kabi: check modver major version and features

if module name contains "hotfix" or "patch", must match entirely,
otherwise, only match major verion(5.4.32-19-0001) and features(
SMP mod_unload modversions aarch64).

vermagic:       5.4.32-19-0001.1 SMP mod_unload modversions aarch64

Signed-off-by: Denise Cheng <denisecheng@tencent.com>
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
This commit is contained in:
Fuhai Wang 2021-06-08 15:33:13 +08:00 committed by kaixuxiakx
parent 78356abba2
commit ee465ed14b
1 changed files with 40 additions and 9 deletions

View File

@ -1366,17 +1366,39 @@ static inline int check_modstruct_version(const struct load_info *info,
static inline int same_magic(const char *amagic, const char *bmagic,
bool has_crcs)
{
int l1, l2;
int l1, l2, l3, l4, l5, l6;
if (has_crcs) {
l1 = strcspn(amagic, " ");
l2 = strcspn(bmagic, " ");
if (l1 != l2)
l3 = strcspn(amagic, "-");
l4 = strcspn(bmagic, "-");
if (l3 > l1 || l4 > l2)
goto check_all;
if (l3 != l4 || memcmp(amagic, bmagic, l3))
return false;
if (memcmp(amagic, bmagic, l1))
amagic += l3;
bmagic += l3;
l5 = strcspn(amagic, ". ");
l6 = strcspn(bmagic, ". ");
if (l5 != l6)
goto check_all;
if (memcmp(amagic, bmagic, l5))
return false;
amagic += l1;
bmagic += l2;
l5 = strcspn(amagic, " ");
l6 = strcspn(bmagic, " ");
amagic += l5;
bmagic += l6;
}
check_all:
return strcmp(amagic, bmagic) == 0;
}
#else
@ -3261,10 +3283,19 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
err = try_to_force_load(mod, "bad vermagic");
if (err)
return err;
} else if (!same_magic(modmagic, vermagic, info->index.vers)) {
pr_err("%s: version magic '%s' should be '%s'\n",
info->name, modmagic, vermagic);
return -ENOEXEC;
} else {
if ((strstr(mod->name, "patch") || strstr(mod->name, "hotfix")) &&
strcmp(modmagic, vermagic) != 0) {
printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
mod->name, modmagic, vermagic);
return -ENOEXEC;
}
if (!same_magic(modmagic, vermagic, info->index.vers)) {
printk(KERN_ERR "%s: version magic '%s' should be compatible with '%s'\n",
mod->name, modmagic, vermagic);
return -ENOEXEC;
}
}
if (!get_modinfo(info, "intree")) {