aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mod/modpost.c
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2018-10-23 18:15:35 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-11-21 09:57:32 -0500
commit5818c683a619c534c113e1f66d24f636defc29bc (patch)
tree578923fbf0c0cda1be816c465aa46547c7e44bad /scripts/mod/modpost.c
parent813af51f5d30a2da6a2523c08465f9726e51772e (diff)
modpost: validate symbol names also in find_elf_symbol
If an ARM mapping symbol shares an address with a valid symbol, find_elf_symbol can currently return the mapping symbol instead, as the symbol is not validated. This can result in confusing warnings: WARNING: vmlinux.o(.text+0x18f4028): Section mismatch in reference from the function set_reset_devices() to the variable .init.text:$x.0 This change adds a call to is_valid_name to find_elf_symbol, similarly to how it's already used in find_elf_symbol2. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r--scripts/mod/modpost.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 0d998c54564d..b709b2e623d6 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1204,6 +1204,30 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
1204 return 1; 1204 return 1;
1205} 1205}
1206 1206
1207static inline int is_arm_mapping_symbol(const char *str)
1208{
1209 return str[0] == '$' && strchr("axtd", str[1])
1210 && (str[2] == '\0' || str[2] == '.');
1211}
1212
1213/*
1214 * If there's no name there, ignore it; likewise, ignore it if it's
1215 * one of the magic symbols emitted used by current ARM tools.
1216 *
1217 * Otherwise if find_symbols_between() returns those symbols, they'll
1218 * fail the whitelist tests and cause lots of false alarms ... fixable
1219 * only by merging __exit and __init sections into __text, bloating
1220 * the kernel (which is especially evil on embedded platforms).
1221 */
1222static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1223{
1224 const char *name = elf->strtab + sym->st_name;
1225
1226 if (!name || !strlen(name))
1227 return 0;
1228 return !is_arm_mapping_symbol(name);
1229}
1230
1207/** 1231/**
1208 * Find symbol based on relocation record info. 1232 * Find symbol based on relocation record info.
1209 * In some cases the symbol supplied is a valid symbol so 1233 * In some cases the symbol supplied is a valid symbol so
@@ -1229,6 +1253,8 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1229 continue; 1253 continue;
1230 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) 1254 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1231 continue; 1255 continue;
1256 if (!is_valid_name(elf, sym))
1257 continue;
1232 if (sym->st_value == addr) 1258 if (sym->st_value == addr)
1233 return sym; 1259 return sym;
1234 /* Find a symbol nearby - addr are maybe negative */ 1260 /* Find a symbol nearby - addr are maybe negative */
@@ -1247,30 +1273,6 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1247 return NULL; 1273 return NULL;
1248} 1274}
1249 1275
1250static inline int is_arm_mapping_symbol(const char *str)
1251{
1252 return str[0] == '$' && strchr("axtd", str[1])
1253 && (str[2] == '\0' || str[2] == '.');
1254}
1255
1256/*
1257 * If there's no name there, ignore it; likewise, ignore it if it's
1258 * one of the magic symbols emitted used by current ARM tools.
1259 *
1260 * Otherwise if find_symbols_between() returns those symbols, they'll
1261 * fail the whitelist tests and cause lots of false alarms ... fixable
1262 * only by merging __exit and __init sections into __text, bloating
1263 * the kernel (which is especially evil on embedded platforms).
1264 */
1265static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1266{
1267 const char *name = elf->strtab + sym->st_name;
1268
1269 if (!name || !strlen(name))
1270 return 0;
1271 return !is_arm_mapping_symbol(name);
1272}
1273
1274/* 1276/*
1275 * Find symbols before or equal addr and after addr - in the section sec. 1277 * Find symbols before or equal addr and after addr - in the section sec.
1276 * If we find two symbols with equal offset prefer one with a valid name. 1278 * If we find two symbols with equal offset prefer one with a valid name.