backport patches to fix NULL-termination of new_argv and set builtin to no

This commit is contained in:
fangchuang 2023-04-17 23:12:33 +08:00
parent 7de5564272
commit 2c199c50d7
3 changed files with 105 additions and 3 deletions

View File

@ -0,0 +1,61 @@
From 4e391ac92d1b9a2c8c0e9d8735d2913ee86c0ad8 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Wed, 18 Aug 2021 22:52:00 +0200
Subject: [PATCH] libkmod: Set builtin to no when module is created from path.
Conflict:NA
Reference:https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/commit?id=4e391ac92d1b9a2c8c0e9d8735d2913ee86c0ad8
A recent bug report showed that modinfo doesn't give the signature
information for certain modules, and it turned out to happen only on
the modules that are built-in on the running kernel; then modinfo
skips the signature check, as if the target module file never exists.
The behavior is, however, inconsistent when modinfo is performed for
external modules (no matter which kernel version is) and the module
file path is explicitly given by a command-line argument, which
guarantees the presence of the module file itself.
Fixes: e7e2cb61fa9f ("modinfo: Show information about built-in modules")
Link: https://lore.kernel.org/linux-modules/CAKi4VAJVvY3=JdSZm-GD1hJqyCPYaYz-jBJ_REeY5BakVb6_ww@mail.gmail.com/
BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1189537
Suggested-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
libkmod/libkmod-module.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 6e0ff1a..6f7747c 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -431,17 +431,18 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
return -EEXIST;
}
- *mod = kmod_module_ref(m);
- return 0;
- }
+ kmod_module_ref(m);
+ } else {
+ err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
+ if (err < 0) {
+ free(abspath);
+ return err;
+ }
- err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
- if (err < 0) {
- free(abspath);
- return err;
+ m->path = abspath;
}
- m->path = abspath;
+ m->builtin = KMOD_MODULE_BUILTIN_NO;
*mod = m;
return 0;
--
2.33.0

View File

@ -0,0 +1,35 @@
From 757b3599236c0fee9e2bb0770eb6b7c84a271276 Mon Sep 17 00:00:00 2001
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Thu, 10 Feb 2022 11:14:22 +0900
Subject: [PATCH] modprobe: fix the NULL-termination of new_argv
Conflict:NA
Reference:https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/commit?id=757b3599236c0fee9e2bb0770eb6b7c84a271276
The number of new arguments is (i + argc - 1) as it is set to *p_argc
one line below.
The correct location of NULL termination is new_argv[i + argc - 1].
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
tools/modprobe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/modprobe.c b/tools/modprobe.c
index eed951f..48b1c8c 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -744,7 +744,7 @@ static char **prepend_options_from_env(int *p_argc, char **orig_argv)
}
memcpy(new_argv + i, orig_argv + 1, sizeof(char *) * (argc - 1));
- new_argv[i + argc] = NULL;
+ new_argv[i + argc - 1] = NULL;
*p_argc = i + argc - 1;
return new_argv;
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: kmod
Version: 29
Release: 6
Release: 7
Summary: Kernel module management
# GPLv2+ is used by programs, LGPLv2+ is used for libraries.
License: GPLv2+ and LGPLv2+
@ -14,8 +14,10 @@ Patch2: 0002-Module-replace-the-module-with-new-module.patch
Patch3: 0003-Module-suspend-the-module-by-rmmod-r-option.patch
Patch4: 0004-don-t-check-module-s-refcnt-when-rmmod-with-r.patch
Patch5: backport-libkmod-Support-SM3-hash-algorithm.patch
Patch6: backport-libkmod-do-not-crash-on-unknown-signature-algorithm.patch
Patch7: backport-libkmod-error-out-on-unknown-hash-algorithm.patch
Patch6: backport-libkmod-do-not-crash-on-unknown-signature-algorithm.patch
Patch7: backport-libkmod-error-out-on-unknown-hash-algorithm.patch
Patch8: backport-libkmod-Set-builtin-to-no-when-module-is-created-fro.patch
Patch9: backport-modprobe-fix-the-NULL-termination-of-new_argv.patch
BuildRequires: gcc chrpath zlib-devel xz-devel libxslt openssl-devel
@ -123,6 +125,10 @@ install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/depmod.d/dist.conf
%doc TODO NEWS README
%changelog
* Mon Apr 17 2023 Fang Chuangchuang <fangchuangchuang@huawei.com> - 29-7
- libkmod: Set builtin to no when module is created from path.
modprobe: fix the NULL-termination of new_argv
* Sun Mar 26 2023 Hangliang Lai <laihangliang1@huawei.com> - 29-6
- fix crash and OOB on unknown hash signature algorithm.