Skip to content

Commit 5419aa2

Browse files
committed
modpost: use more reliable way to get fromsec in section_rel(a)()
The section name of Rel and Rela starts with ".rel" and ".rela" respectively (but, I do not know whether this is specification or convention). For example, ".rela.text" holds relocation entries applied to the ".text" section. So, the code chops the ".rel" or ".rela" prefix to get the name of the section to which the relocation applies. However, I do not like to skip 4 or 5 bytes blindly because it is potential memory overrun. The ELF specification provides a more reliable way to do this. - The sh_info field holds extra information, whose interpretation depends on the section type - If the section type is SHT_REL or SHT_RELA, the sh_info field holds the section header index of the section to which the relocation applies. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 125ed24 commit 5419aa2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

scripts/mod/modpost.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,8 +1723,7 @@ static void section_rela(const char *modname, struct elf_info *elf,
17231723
Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
17241724
Elf_Rela *stop = (void *)start + sechdr->sh_size;
17251725

1726-
fromsec = sech_name(elf, sechdr);
1727-
fromsec += strlen(".rela");
1726+
fromsec = sec_name(elf, sechdr->sh_info);
17281727
/* if from section (name) is know good then skip it */
17291728
if (match(fromsec, section_white_list))
17301729
return;
@@ -1776,8 +1775,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
17761775
Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
17771776
Elf_Rel *stop = (void *)start + sechdr->sh_size;
17781777

1779-
fromsec = sech_name(elf, sechdr);
1780-
fromsec += strlen(".rel");
1778+
fromsec = sec_name(elf, sechdr->sh_info);
17811779
/* if from section (name) is know good then skip it */
17821780
if (match(fromsec, section_white_list))
17831781
return;

0 commit comments

Comments
 (0)