Patch "objtool: Preserve special st_shndx indexes in elf_update_symbol" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    objtool: Preserve special st_shndx indexes in elf_update_symbol

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     objtool-preserve-special-st_shndx-indexes-in-elf_upd.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 82fc065417fb3b595c2d975a438cc9410c969ea1
Author: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
Date:   Thu Sep 8 14:54:58 2022 -0700

    objtool: Preserve special st_shndx indexes in elf_update_symbol
    
    [ Upstream commit 5141d3a06b2da1731ac82091298b766a1f95d3d8 ]
    
    elf_update_symbol fails to preserve the special st_shndx values
    between [SHN_LORESERVE, SHN_HIRESERVE], which results in it
    converting SHN_ABS entries into SHN_UNDEF, for example. Explicitly
    check for the special indexes and ensure these symbols are not
    marked undefined.
    
    Fixes: ead165fa1042 ("objtool: Fix symbol creation")
    Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
    Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Tested-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220908215504.3686827-17-samitolvanen@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index bc3005ef5af8..4b78df22d42e 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -555,6 +555,11 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab,
 	Elf64_Xword entsize = symtab->sh.sh_entsize;
 	int max_idx, idx = sym->idx;
 	Elf_Scn *s, *t = NULL;
+	bool is_special_shndx = sym->sym.st_shndx >= SHN_LORESERVE &&
+				sym->sym.st_shndx != SHN_XINDEX;
+
+	if (is_special_shndx)
+		shndx = sym->sym.st_shndx;
 
 	s = elf_getscn(elf->elf, symtab->idx);
 	if (!s) {
@@ -640,7 +645,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab,
 	}
 
 	/* setup extended section index magic and write the symbol */
-	if (shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) {
+	if ((shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) {
 		sym->sym.st_shndx = shndx;
 		if (!shndx_data)
 			shndx = 0;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux