git: 1ee7e4ba70e1 - releng/13.1 - loader: fix elf lookup_symbol type filtering
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 01 Nov 2022 20:33:46 UTC
The branch releng/13.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1ee7e4ba70e10e0ac0c9c144ad0301ffeca8824d commit 1ee7e4ba70e10e0ac0c9c144ad0301ffeca8824d Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2022-10-14 03:06:13 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-11-01 18:03:25 +0000 loader: fix elf lookup_symbol type filtering The existing logic doesn't seem to make much sense, as we won't filter on the type if st_shndx != SHN_UNDEF. In practice, this breaks booting 12.3 kernels on newer loaders, as they do have a `kernphys` symbol of the wrong type (NOTYPE, rather than OBJECT) -- we end up deriving the wrong value for copy_staging. It's unclear if this version makes any more sense, but it seems to match what rtld's matched_symbol() does. Loader doesn't need to care about STT_FUNC w/ UND shndx, because we won't encounter those; in kmods, undefined (kernel) functions are NOTYPE. Approved by: so Security: FreeBSD-EN-22:27.loader Reported by: Christian McDonald <cmcdonald netgate com> Reviewed by: imp, kib, tsoome (cherry picked from commit 0701dbda94f21de8ddab3113f79262a26cc7b96c) (cherry picked from commit 2b31059ea701957584e68a75857206d80a230211) --- stand/common/load_elf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stand/common/load_elf.c b/stand/common/load_elf.c index c75567b4a560..9e47d3db3828 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -1259,9 +1259,8 @@ __elfN(lookup_symbol)(elf_file_t ef, const char* name, Elf_Sym *symp, strp = strdupout((vm_offset_t)(ef->strtab + sym.st_name)); if (strcmp(name, strp) == 0) { free(strp); - if (sym.st_shndx != SHN_UNDEF || - (sym.st_value != 0 && - ELF_ST_TYPE(sym.st_info) == type)) { + if (sym.st_shndx != SHN_UNDEF && sym.st_value != 0 && + ELF_ST_TYPE(sym.st_info) == type) { *symp = sym; return 0; }