From 0341d5998ad8b904dae901badfcaa2484a268509 Mon Sep 17 00:00:00 2001 From: zhangjian Date: Tue, 26 Aug 2025 01:10:37 +0000 Subject: [PATCH] backport two patches from upstream --- ...heck-strtol-strtoul-strtoull-results.patch | 161 ++++++++++++++++++ ...robe-Fix-odd-remove-holders-behavior.patch | 46 +++++ kmod.spec | 7 +- 3 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 backport-check-strtol-strtoul-strtoull-results.patch create mode 100644 backport-tools-modprobe-Fix-odd-remove-holders-behavior.patch diff --git a/backport-check-strtol-strtoul-strtoull-results.patch b/backport-check-strtol-strtoul-strtoull-results.patch new file mode 100644 index 0000000..7881509 --- /dev/null +++ b/backport-check-strtol-strtoul-strtoull-results.patch @@ -0,0 +1,161 @@ +From dcd652b57c6e60b15cfe8e5791f94e152e08063a Mon Sep 17 00:00:00 2001 +From: Tobias Stoeckmann +Date: Sun, 25 May 2025 10:22:09 +0200 +Subject: [PATCH] check strtol/strtoul/strtoull results + +The strto* family of functions may fail if the input string contains +a number which is too large for the designated data type. In such +cases, errno is set to ERANGE. Check for this error condition and if +subsequent casts would truncate the value. + +Signed-off-by: Tobias Stoeckmann +Reviewed-by: Emil Velikov +Link: https://github.com/kmod-project/kmod/pull/357 +Signed-off-by: Lucas De Marchi + +Conflict: NA +Reference: https://github.com/kmod-project/kmod/commit/dcd652b57c6e60b15cfe8e5791f94e152e08063a +--- + libkmod/libkmod-module.c | 3 ++- + libkmod/libkmod.c | 5 ++++- + shared/util.c | 4 ++-- + testsuite/delete_module.c | 7 ++++++- + testsuite/init_module.c | 6 +++++- + tools/depmod.c | 3 ++- + tools/modprobe.c | 3 ++- + 7 files changed, 23 insertions(+), 8 deletions(-) + +diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c +index 3ca90c0..fca6a10 100644 +--- a/libkmod/libkmod-module.c ++++ b/libkmod/libkmod-module.c +@@ -1515,8 +1515,9 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod) + break; + } + ++ errno = 0; + value = strtol(tok, &endptr, 10); +- if (endptr == tok || *endptr != '\0') { ++ if (endptr == tok || *endptr != '\0' || errno == ERANGE || value < 0) { + ERR(mod->ctx, + "invalid line format at /proc/modules:%d\n", lineno); + break; +diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c +index fceed93..a62946d 100644 +--- a/libkmod/libkmod.c ++++ b/libkmod/libkmod.c +@@ -148,9 +148,12 @@ KMOD_EXPORT void kmod_set_userdata(struct kmod_ctx *ctx, const void *userdata) + static int log_priority(const char *priority) + { + char *endptr; +- int prio; ++ long prio; + ++ errno = 0; + prio = strtol(priority, &endptr, 10); ++ if (errno == ERANGE || prio < INT_MIN || prio > INT_MAX) ++ return 0; + if (endptr[0] == '\0' || isspace(endptr[0])) + return prio; + if (strncmp(priority, "err", 3) == 0) +diff --git a/shared/util.c b/shared/util.c +index ba91815..4541cab 100644 +--- a/shared/util.c ++++ b/shared/util.c +@@ -274,7 +274,7 @@ int read_str_long(int fd, long *value, int base) + return err; + errno = 0; + v = strtol(buf, &end, base); +- if (end == buf || !isspace(*end)) ++ if (end == buf || !isspace(*end) || errno == ERANGE) + return -EINVAL; + + *value = v; +@@ -292,7 +293,7 @@ int read_str_ulong(int fd, unsigned long *value, int base) + return err; + errno = 0; + v = strtoul(buf, &end, base); +- if (end == buf || !isspace(*end)) ++ if (end == buf || !isspace(*end) || errno == ERANGE) + return -EINVAL; + *value = v; + return 0; +diff --git a/testsuite/delete_module.c b/testsuite/delete_module.c +index 088496a..84bf0ff 100644 +--- a/testsuite/delete_module.c ++++ b/testsuite/delete_module.c +@@ -60,14 +60,19 @@ static void parse_retcodes(struct mod **_modules, const char *s) + if (p == NULL) + break; + ++ errno = 0; + l = strtol(p, &end, 0); +- if (end == p || *end != ':') ++ if (end == p || *end != ':' || errno == ERANGE || l < INT_MIN || ++ l > INT_MAX) + break; + + ret = (int) l; + p = end + 1; + ++ errno = 0; + l = strtol(p, &end, 0); ++ if (errno == ERANGE || l < INT_MIN || l > INT_MAX) ++ break; + if (*end == ':') + p = end + 1; + else if (*end != '\0') +diff --git a/testsuite/init_module.c b/testsuite/init_module.c +index 891df6b..7b34499 100644 +--- a/testsuite/init_module.c ++++ b/testsuite/init_module.c +@@ -76,12 +76,16 @@ static void parse_retcodes(struct mod **_modules, const char *s) + break; + + l = strtol(p, &end, 0); +- if (end == p || *end != ':') ++ if (end == p || *end != ':' || errno == ERANGE || l < INT_MIN || ++ l > INT_MAX) + break; + ret = (int) l; + p = end + 1; + ++ errno = 0; + l = strtol(p, &end, 0); ++ if (errno == ERANGE || l < INT_MIN || l > INT_MAX) ++ break; + if (*end == ':') + p = end + 1; + else if (*end != '\0') +diff --git a/tools/depmod.c b/tools/depmod.c +index 60271dc..3390222 100644 +--- a/tools/depmod.c ++++ b/tools/depmod.c +@@ -2693,8 +2693,9 @@ static int depmod_load_symvers(struct depmod *depmod, const char *filename) + if (!streq(where, "vmlinux")) + continue; + ++ errno = 0; + crc = strtoull(ver, &verend, 16); +- if (verend[0] != '\0') { ++ if (verend[0] != '\0' || errno == ERANGE) { + ERR("%s:%u Invalid symbol version %s: %m\n", + filename, linenum, ver); + continue; +diff --git a/tools/modprobe.c b/tools/modprobe.c +index a939a3b..c501fb5 100644 +--- a/tools/modprobe.c ++++ b/tools/modprobe.c +@@ -790,8 +790,9 @@ static int do_modprobe(int argc, char **orig_argv) + break; + case 'w': { + char *endptr = NULL; ++ errno = 0; + wait_msec = strtoul(optarg, &endptr, 0); +- if (!*optarg || *endptr) { ++ if (!*optarg || *endptr || errno == ERANGE) { + ERR("unexpected wait value '%s'.\n", optarg); + err = -1; + goto done; +-- +2.33.0 \ No newline at end of file diff --git a/backport-tools-modprobe-Fix-odd-remove-holders-behavior.patch b/backport-tools-modprobe-Fix-odd-remove-holders-behavior.patch new file mode 100644 index 0000000..5de8a03 --- /dev/null +++ b/backport-tools-modprobe-Fix-odd-remove-holders-behavior.patch @@ -0,0 +1,46 @@ +From 15edeed38680c7ab5cfa2717b1721e3e51e41e33 Mon Sep 17 00:00:00 2001 +From: Lucas De Marchi +Date: Fri, 13 Jun 2025 13:57:08 -0500 +Subject: [PATCH] tools/modprobe: Fix odd --remove-holders behavior + +--remove-holders was not implying --remove, which means that if the user +called `modprobe --remove-holders xe` it would actually try to insert +the xe module. Fix it and spell it out in the man page about one option +implying the other. + +Considering i915 is not currently loaded: + +Before: + kmod $ ./build/modprobe -v --dry-run --remove-holders i915 + insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/char/agp/intel-gtt.ko.zst + insmod /lib/modules/6.14.11-1-MANJARO/kernel/drivers/gpu/drm/i915/i915.ko.zst + kmod $ + +After: + kmod $ ./build/modprobe -v --dry-run --remove-holders i915 + kmod $ + +Signed-off-by: Lucas De Marchi +Link: https://github.com/kmod-project/kmod/pull/372 + +Conflict: NA +Reference: https://github.com/kmod-project/kmod/commit/15edeed38680c7ab5cfa2717b1721e3e51e41e33 +--- + tools/modprobe.c | 1 + + 1 files changed, 1 insertions(+) + +diff --git a/tools/modprobe.c b/tools/modprobe.c +index 81b1960..fa9757e 100644 +--- a/tools/modprobe.c ++++ b/tools/modprobe.c +@@ -827,6 +827,7 @@ static int do_modprobe(int argc, char **orig_argv) + break; + case 5: + remove_holders = 1; ++ do_remove = 1; + break; + case 'w': { + char *endptr = NULL; +-- +2.33.0 + \ No newline at end of file diff --git a/kmod.spec b/kmod.spec index e60f28b..c07fa0e 100644 --- a/kmod.spec +++ b/kmod.spec @@ -1,6 +1,6 @@ Name: kmod Version: 30 -Release: 8 +Release: 9 Summary: Kernel module management # GPLv2+ is used by programs, LGPLv2+ is used for libraries. License: GPLv2+ and LGPLv2+ @@ -21,6 +21,8 @@ Patch0003: backport-libkmod-error-out-on-unknown-hash-algorithm.patch Patch0004: backport-shared-avoid-passing-NULL-0-array-to-bsearch.patch Patch0005: backport-libkmod-fix-possible-out-of-bounds-memory-access.patch Patch0006: backport-libkmod-clear-file-memory-if-map-fails.patch +Patch0007: backport-check-strtol-strtoul-strtoull-results.patch +Patch0008: backport-tools-modprobe-Fix-odd-remove-holders-behavior.patch %description The kmod package provides several commands to manage the kernel modules, @@ -128,6 +130,9 @@ make check %doc TODO NEWS README.md %changelog +* Tue Aug 26 2025 zhangjian - 30-9 +- backport two patches from upstream + * Fri Jul 04 2025 Liu Chao - 30-8 - enable make check and move changelog to spec to fix ci failure -- Gitee