aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2017-04-21 18:35:26 -0400
committerJessica Yu <jeyu@redhat.com>2017-05-23 17:08:18 -0400
commit490194269665d6d4915a4a5774f002885c5a2d8f (patch)
tree02f07a7542e5875a64102de0e99d4689df61f0d8 /kernel
parent08332893e37af6ae779367e78e444f8f9571511d (diff)
module: Pass struct load_info into symbol checks
Since we're already using values from struct load_info, just pass this pointer in directly and use what's needed as we need it. This allows us to access future fields in struct load_info too. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jessica Yu <jeyu@redhat.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/module.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 4a3665f8f837..ca4509b13400 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1278,12 +1278,13 @@ static u32 resolve_rel_crc(const s32 *crc)
1278 return *(u32 *)((void *)crc + *crc); 1278 return *(u32 *)((void *)crc + *crc);
1279} 1279}
1280 1280
1281static int check_version(Elf_Shdr *sechdrs, 1281static int check_version(const struct load_info *info,
1282 unsigned int versindex,
1283 const char *symname, 1282 const char *symname,
1284 struct module *mod, 1283 struct module *mod,
1285 const s32 *crc) 1284 const s32 *crc)
1286{ 1285{
1286 Elf_Shdr *sechdrs = info->sechdrs;
1287 unsigned int versindex = info->index.vers;
1287 unsigned int i, num_versions; 1288 unsigned int i, num_versions;
1288 struct modversion_info *versions; 1289 struct modversion_info *versions;
1289 1290
@@ -1326,8 +1327,7 @@ bad_version:
1326 return 0; 1327 return 0;
1327} 1328}
1328 1329
1329static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1330static inline int check_modstruct_version(const struct load_info *info,
1330 unsigned int versindex,
1331 struct module *mod) 1331 struct module *mod)
1332{ 1332{
1333 const s32 *crc; 1333 const s32 *crc;
@@ -1343,8 +1343,8 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1343 BUG(); 1343 BUG();
1344 } 1344 }
1345 preempt_enable(); 1345 preempt_enable();
1346 return check_version(sechdrs, versindex, 1346 return check_version(info, VMLINUX_SYMBOL_STR(module_layout),
1347 VMLINUX_SYMBOL_STR(module_layout), mod, crc); 1347 mod, crc);
1348} 1348}
1349 1349
1350/* First part is kernel version, which we ignore if module has crcs. */ 1350/* First part is kernel version, which we ignore if module has crcs. */
@@ -1358,8 +1358,7 @@ static inline int same_magic(const char *amagic, const char *bmagic,
1358 return strcmp(amagic, bmagic) == 0; 1358 return strcmp(amagic, bmagic) == 0;
1359} 1359}
1360#else 1360#else
1361static inline int check_version(Elf_Shdr *sechdrs, 1361static inline int check_version(const struct load_info *info,
1362 unsigned int versindex,
1363 const char *symname, 1362 const char *symname,
1364 struct module *mod, 1363 struct module *mod,
1365 const s32 *crc) 1364 const s32 *crc)
@@ -1367,8 +1366,7 @@ static inline int check_version(Elf_Shdr *sechdrs,
1367 return 1; 1366 return 1;
1368} 1367}
1369 1368
1370static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1369static inline int check_modstruct_version(const struct load_info *info,
1371 unsigned int versindex,
1372 struct module *mod) 1370 struct module *mod)
1373{ 1371{
1374 return 1; 1372 return 1;
@@ -1404,7 +1402,7 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
1404 if (!sym) 1402 if (!sym)
1405 goto unlock; 1403 goto unlock;
1406 1404
1407 if (!check_version(info->sechdrs, info->index.vers, name, mod, crc)) { 1405 if (!check_version(info, name, mod, crc)) {
1408 sym = ERR_PTR(-EINVAL); 1406 sym = ERR_PTR(-EINVAL);
1409 goto getname; 1407 goto getname;
1410 } 1408 }
@@ -2971,7 +2969,7 @@ static struct module *setup_load_info(struct load_info *info, int flags)
2971 info->index.pcpu = find_pcpusec(info); 2969 info->index.pcpu = find_pcpusec(info);
2972 2970
2973 /* Check module struct version now, before we try to use module. */ 2971 /* Check module struct version now, before we try to use module. */
2974 if (!check_modstruct_version(info->sechdrs, info->index.vers, mod)) 2972 if (!check_modstruct_version(info, mod))
2975 return ERR_PTR(-ENOEXEC); 2973 return ERR_PTR(-ENOEXEC);
2976 2974
2977 return mod; 2975 return mod;