aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod/modpost.c
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2022-07-31 02:36:34 +0900
committerMasahiro Yamada <masahiroy@kernel.org>2022-08-03 22:58:10 +0900
commit125ed24a4ab0d704bab5dee5ccb2c3b05f627c78 (patch)
tree82a7e0f4e2880d7219ad494c7abc71a2c7e241b8 /scripts/mod/modpost.c
parentmodpost: refactor get_secindex() (diff)
downloadlinux-dev-125ed24a4ab0d704bab5dee5ccb2c3b05f627c78.tar.xz
linux-dev-125ed24a4ab0d704bab5dee5ccb2c3b05f627c78.zip
modpost: add array range check to sec_name()
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 <masahiroy@kernel.org>
Diffstat (limited to '')
-rw-r--r--scripts/mod/modpost.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 08411fff3e17..148b38699889 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -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]);
}