Skip to content

Commit

Permalink
modpost: add array range check to sec_name()
Browse files Browse the repository at this point in the history
The section index is always positive, so the argument, secindex, should
be unsigned.

Also, inserted the array range check.

If sym->st_shndx is a special section index (between SHN_LORESERVE and
SHN_HIRESERVE), there is no corresponding section header.

For example, if a symbol specifies an absolute value, sym->st_shndx is
SHN_ABS (=0xfff1).

The current users do not cause the out-of-range access of
info->sechddrs[], but it is better to avoid such a pitfall.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y committed Aug 3, 2022
1 parent 36b0f0d commit 125ed24
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,16 @@ static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr)
sechdr->sh_name);
}

static const char *sec_name(const struct elf_info *info, int secindex)
static const char *sec_name(const struct elf_info *info, unsigned int secindex)
{
/*
* If sym->st_shndx is a special section index, there is no
* corresponding section header.
* Return "" if the index is out of range of info->sechdrs[] array.
*/
if (secindex >= info->num_sections)
return "";

return sech_name(info, &info->sechdrs[secindex]);
}

Expand Down

0 comments on commit 125ed24

Please sign in to comment.