Skip to content

Commit bca014c

Browse files
bwhacksrustyrussell
authored andcommitted
module: Invalidate signatures on force-loaded modules
Signing a module should only make it trusted by the specific kernel it was built for, not anything else. Loading a signed module meant for a kernel with a different ABI could have interesting effects. Therefore, treat all signatures as invalid when a module is force-loaded. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Cc: stable@vger.kernel.org Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 3205c36 commit bca014c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎kernel/module.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,13 +2686,18 @@ static inline void kmemleak_load_module(const struct module *mod,
26862686
#endif
26872687

26882688
#ifdef CONFIG_MODULE_SIG
2689-
static int module_sig_check(struct load_info *info)
2689+
static int module_sig_check(struct load_info *info, int flags)
26902690
{
26912691
int err = -ENOKEY;
26922692
const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
26932693
const void *mod = info->hdr;
26942694

2695-
if (info->len > markerlen &&
2695+
/*
2696+
* Require flags == 0, as a module with version information
2697+
* removed is no longer the module that was signed
2698+
*/
2699+
if (flags == 0 &&
2700+
info->len > markerlen &&
26962701
memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
26972702
/* We truncate the module to discard the signature */
26982703
info->len -= markerlen;
@@ -2711,7 +2716,7 @@ static int module_sig_check(struct load_info *info)
27112716
return err;
27122717
}
27132718
#else /* !CONFIG_MODULE_SIG */
2714-
static int module_sig_check(struct load_info *info)
2719+
static int module_sig_check(struct load_info *info, int flags)
27152720
{
27162721
return 0;
27172722
}
@@ -3506,7 +3511,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
35063511
long err;
35073512
char *after_dashes;
35083513

3509-
err = module_sig_check(info);
3514+
err = module_sig_check(info, flags);
35103515
if (err)
35113516
goto free_copy;
35123517

0 commit comments

Comments
 (0)