Commit 49019426 authored by Kees Cook's avatar Kees Cook Committed by Jessica Yu
Browse files

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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJessica Yu <jeyu@redhat.com>
parent 08332893
Loading
Loading
Loading
Loading
+10 −12
Original line number Original line Diff line number Diff line
@@ -1278,12 +1278,13 @@ static u32 resolve_rel_crc(const s32 *crc)
	return *(u32 *)((void *)crc + *crc);
	return *(u32 *)((void *)crc + *crc);
}
}


static int check_version(Elf_Shdr *sechdrs,
static int check_version(const struct load_info *info,
			 unsigned int versindex,
			 const char *symname,
			 const char *symname,
			 struct module *mod,
			 struct module *mod,
			 const s32 *crc)
			 const s32 *crc)
{
{
	Elf_Shdr *sechdrs = info->sechdrs;
	unsigned int versindex = info->index.vers;
	unsigned int i, num_versions;
	unsigned int i, num_versions;
	struct modversion_info *versions;
	struct modversion_info *versions;


@@ -1326,8 +1327,7 @@ bad_version:
	return 0;
	return 0;
}
}


static inline int check_modstruct_version(Elf_Shdr *sechdrs,
static inline int check_modstruct_version(const struct load_info *info,
					  unsigned int versindex,
					  struct module *mod)
					  struct module *mod)
{
{
	const s32 *crc;
	const s32 *crc;
@@ -1343,8 +1343,8 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
		BUG();
		BUG();
	}
	}
	preempt_enable();
	preempt_enable();
	return check_version(sechdrs, versindex,
	return check_version(info, VMLINUX_SYMBOL_STR(module_layout),
			     VMLINUX_SYMBOL_STR(module_layout), mod, crc);
			     mod, crc);
}
}


/* First part is kernel version, which we ignore if module has crcs. */
/* 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,
	return strcmp(amagic, bmagic) == 0;
	return strcmp(amagic, bmagic) == 0;
}
}
#else
#else
static inline int check_version(Elf_Shdr *sechdrs,
static inline int check_version(const struct load_info *info,
				unsigned int versindex,
				const char *symname,
				const char *symname,
				struct module *mod,
				struct module *mod,
				const s32 *crc)
				const s32 *crc)
@@ -1367,8 +1366,7 @@ static inline int check_version(Elf_Shdr *sechdrs,
	return 1;
	return 1;
}
}


static inline int check_modstruct_version(Elf_Shdr *sechdrs,
static inline int check_modstruct_version(const struct load_info *info,
					  unsigned int versindex,
					  struct module *mod)
					  struct module *mod)
{
{
	return 1;
	return 1;
@@ -1404,7 +1402,7 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
	if (!sym)
	if (!sym)
		goto unlock;
		goto unlock;


	if (!check_version(info->sechdrs, info->index.vers, name, mod, crc)) {
	if (!check_version(info, name, mod, crc)) {
		sym = ERR_PTR(-EINVAL);
		sym = ERR_PTR(-EINVAL);
		goto getname;
		goto getname;
	}
	}
@@ -2971,7 +2969,7 @@ static struct module *setup_load_info(struct load_info *info, int flags)
	info->index.pcpu = find_pcpusec(info);
	info->index.pcpu = find_pcpusec(info);


	/* Check module struct version now, before we try to use module. */
	/* Check module struct version now, before we try to use module. */
	if (!check_modstruct_version(info->sechdrs, info->index.vers, mod))
	if (!check_modstruct_version(info, mod))
		return ERR_PTR(-ENOEXEC);
		return ERR_PTR(-ENOEXEC);


	return mod;
	return mod;