diff --git a/backport-libkmod-allow-modules.alias.builtin-to-be-optional.patch b/backport-libkmod-allow-modules.alias.builtin-to-be-optional.patch new file mode 100644 index 0000000000000000000000000000000000000000..6a3a310847e089f6c13588c5f5ce66a00a4b5c0e --- /dev/null +++ b/backport-libkmod-allow-modules.alias.builtin-to-be-optional.patch @@ -0,0 +1,46 @@ +From d8d1d54051053d770643b59c3f5cf5608a17a0ce Mon Sep 17 00:00:00 2001 +From: Lucas De Marchi +Date: Mon, 9 Mar 2020 22:00:28 -0700 +Subject: [PATCH] libkmod: allow modules.alias.builtin to be optional + +--- + libkmod/libkmod.c | 15 ++++++++++++--- + 1 file changed, 12 insertions(+), 3 deletions(-) + +diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c +index ab5c1e8..43423d6 100644 +--- a/libkmod/libkmod.c ++++ b/libkmod/libkmod.c +@@ -855,8 +855,8 @@ KMOD_EXPORT int kmod_validate_resources(struct kmod_ctx *ctx) + */ + KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) + { ++ int ret = 0; + size_t i; +- int ret; + + if (ctx == NULL) + return -ENOENT; +@@ -874,8 +874,17 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) + index_files[i].fn); + ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i], + &ctx->indexes[i]); +- if (ret) +- break; ++ ++ /* ++ * modules.builtin.alias are considered optional since it's ++ * recently added and older installations may not have it; ++ * we allow failing for any reason ++ */ ++ if (ret) { ++ if (i != KMOD_INDEX_MODULES_BUILTIN_ALIAS) ++ break; ++ ret = 0; ++ } + } + + if (ret) +-- +2.19.1 + diff --git a/backport-libkmod-fix-return-error-when-opening-index.patch b/backport-libkmod-fix-return-error-when-opening-index.patch new file mode 100644 index 0000000000000000000000000000000000000000..c380f74a437816d67698458d09772c170c4b30f5 --- /dev/null +++ b/backport-libkmod-fix-return-error-when-opening-index.patch @@ -0,0 +1,171 @@ +From 3bd7187ff549a2ef2441dcddabf382cc53cf6f22 Mon Sep 17 00:00:00 2001 +From: Lucas De Marchi +Date: Mon, 9 Mar 2020 22:00:27 -0700 +Subject: [PATCH] libkmod: fix return error when opening index + +When calling kmod_load_resources() we could end up getting a bogus +return value -ENOMEM due to several other reasons, like the index not +existing. Change index_mm_open() to propagate the failure reason so we +can take actions on it or return to the caller. +--- + libkmod/libkmod-index.c | 31 +++++++++++++++++++------------ + libkmod/libkmod-index.h | 4 ++-- + libkmod/libkmod.c | 16 ++++++++-------- + 3 files changed, 29 insertions(+), 22 deletions(-) + +diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c +index 1f3351a..6a34c8d 100644 +--- a/libkmod/libkmod-index.c ++++ b/libkmod/libkmod-index.c +@@ -611,7 +611,7 @@ struct index_value *index_searchwild(struct index_file *in, const char *key) + static const char _idx_empty_str[] = ""; + + struct index_mm { +- struct kmod_ctx *ctx; ++ const struct kmod_ctx *ctx; + void *mm; + uint32_t root_offset; + size_t size; +@@ -739,10 +739,10 @@ static void index_mm_free_node(struct index_mm_node *node) + free(node); + } + +-struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, +- unsigned long long *stamp) ++int index_mm_open(const struct kmod_ctx *ctx, const char *filename, ++ unsigned long long *stamp, struct index_mm **pidx) + { +- int fd; ++ int fd, err; + struct stat st; + struct index_mm *idx; + struct { +@@ -752,28 +752,32 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, + } hdr; + void *p; + ++ assert(pidx != NULL); ++ + DBG(ctx, "file=%s\n", filename); + + idx = malloc(sizeof(*idx)); + if (idx == NULL) { + ERR(ctx, "malloc: %m\n"); +- return NULL; ++ return -ENOMEM; + } + + if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) { + DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename); ++ err = -errno; + goto fail_open; + } + +- if (fstat(fd, &st) < 0) +- goto fail_nommap; +- if ((size_t) st.st_size < sizeof(hdr)) ++ if (fstat(fd, &st) < 0 || (size_t) st.st_size < sizeof(hdr)) { ++ err = -EINVAL; + goto fail_nommap; ++ } + +- if ((idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) +- == MAP_FAILED) { ++ idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); ++ if (idx->mm == MAP_FAILED) { + ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, %d, MAP_PRIVATE, 0): %m\n", + st.st_size, fd); ++ err = -errno; + goto fail_nommap; + } + +@@ -785,12 +789,14 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, + if (hdr.magic != INDEX_MAGIC) { + ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic, + INDEX_MAGIC); ++ err = -EINVAL; + goto fail; + } + + if (hdr.version >> 16 != INDEX_VERSION_MAJOR) { + ERR(ctx, "major version check fail: %u instead of %u\n", + hdr.version >> 16, INDEX_VERSION_MAJOR); ++ err = -EINVAL; + goto fail; + } + +@@ -800,8 +806,9 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, + close(fd); + + *stamp = stat_mstamp(&st); ++ *pidx = idx; + +- return idx; ++ return 0; + + fail: + munmap(idx->mm, st.st_size); +@@ -809,7 +816,7 @@ fail_nommap: + close(fd); + fail_open: + free(idx); +- return NULL; ++ return err; + } + + void index_mm_close(struct index_mm *idx) +diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h +index 52aebac..db671b0 100644 +--- a/libkmod/libkmod-index.h ++++ b/libkmod/libkmod-index.h +@@ -40,8 +40,8 @@ void index_values_free(struct index_value *values); + + /* Implementation using mmap */ + struct index_mm; +-struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, +- unsigned long long *stamp); ++int index_mm_open(const struct kmod_ctx *ctx, const char *filename, ++ unsigned long long *stamp, struct index_mm **pidx); + void index_mm_close(struct index_mm *index); + char *index_mm_search(struct index_mm *idx, const char *key); + struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); +diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c +index 39f58d9..ab5c1e8 100644 +--- a/libkmod/libkmod.c ++++ b/libkmod/libkmod.c +@@ -856,6 +856,7 @@ KMOD_EXPORT int kmod_validate_resources(struct kmod_ctx *ctx) + KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) + { + size_t i; ++ int ret; + + if (ctx == NULL) + return -ENOENT; +@@ -871,17 +872,16 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx) + + snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, + index_files[i].fn); +- ctx->indexes[i] = index_mm_open(ctx, path, +- &ctx->indexes_stamp[i]); +- if (ctx->indexes[i] == NULL) +- goto fail; ++ ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i], ++ &ctx->indexes[i]); ++ if (ret) ++ break; + } + +- return 0; ++ if (ret) ++ kmod_unload_resources(ctx); + +-fail: +- kmod_unload_resources(ctx); +- return -ENOMEM; ++ return ret; + } + + /** +-- +2.19.1 + diff --git a/bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch b/bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch index d23541be9b679f20eb3ae6d0cfce7602515af2dc..93fb44d0880bb882e38c9a7f7bcef44c47b7b38a 100644 --- a/bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch +++ b/bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch @@ -4,32 +4,23 @@ Date: Fri, 25 Jan 2019 17:03:05 +0000 Subject: [PATCH] ok Signed-off-by: guoxiaoqi ---- - tools/depmod.c | 7 ++++--- - 1 file changed, 4 insertions(+), 3 deletions(-) +--- +tools/depmod.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/depmod.c b/tools/depmod.c -index 989d907..f519679 100644 +index fbbce10..01db7ad 100644 --- a/tools/depmod.c +++ b/tools/depmod.c -@@ -2438,7 +2438,7 @@ static int depmod_output(struct depmod *depmod, FILE *out) - r = itr->cb(depmod, fp); +@@ -2529,6 +2529,7 @@ static int depmod_output(struct depmod *depmod, FILE *out) if (fp == out) continue; -- + + fsync(fileno(fp)); ferr = ferror(fp) | fclose(fp); if (r < 0) { -@@ -2451,7 +2451,6 @@ static int depmod_output(struct depmod *depmod, FILE *out) - break; - } - -- unlinkat(dfd, itr->name, 0); - if (renameat(dfd, tmp, dfd, itr->name) != 0) { - err = -errno; - CRIT("renameat(%s, %s, %s, %s): %m\n", -@@ -2467,8 +2466,10 @@ static int depmod_output(struct depmod *depmod, FILE *out) +@@ -2556,8 +2557,10 @@ static int depmod_output(struct depmod *depmod, FILE *out) } } @@ -42,5 +33,5 @@ index 989d907..f519679 100644 return err; } -- -1.8.3.1 +2.19.1 diff --git a/depmod-prevent-module-dependency-files-corruption-du.patch b/depmod-prevent-module-dependency-files-corruption-du.patch deleted file mode 100644 index c3b932c06e5a8dd8f0962a84b5187f4f2e2ef4a3..0000000000000000000000000000000000000000 --- a/depmod-prevent-module-dependency-files-corruption-du.patch +++ /dev/null @@ -1,62 +0,0 @@ -From a06bacf500d56b72b5f9b121ebf7f6af9e3df185 Mon Sep 17 00:00:00 2001 -From: Michal Suchanek -Date: Mon, 17 Dec 2018 23:46:28 +0100 -Subject: [PATCH 16/36] depmod: prevent module dependency files corruption due - to parallel invocation. - -Depmod does not use unique filename for temporary files. There is no -guarantee the user does not attempt to run mutiple depmod processes in -parallel. If that happens a temporary file might be created by -depmod(1st), truncated by depmod(2nd), and renamed to final name by -depmod(1st) resulting in corrupted file seen by user. - -Due to missing mkstempat() this is more complex than it should be. -Adding PID and timestamp to the filename should be reasonably reliable. -Adding O_EXCL as mkstemp does fails creating the file rather than -corrupting existing file. - -Signed-off-by: Michal Suchanek ---- - tools/depmod.c | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/tools/depmod.c b/tools/depmod.c -index 18c0d61..0f7e33c 100644 ---- a/tools/depmod.c -+++ b/tools/depmod.c -@@ -29,6 +29,7 @@ - #include - #include - #include -+#include - #include - - #include -@@ -2398,6 +2399,9 @@ static int depmod_output(struct depmod *depmod, FILE *out) - }; - const char *dname = depmod->cfg->dirname; - int dfd, err = 0; -+ struct timeval tv; -+ -+ gettimeofday(&tv, NULL); - - if (out != NULL) - dfd = -1; -@@ -2416,11 +2420,12 @@ static int depmod_output(struct depmod *depmod, FILE *out) - int r, ferr; - - if (fp == NULL) { -- int flags = O_CREAT | O_TRUNC | O_WRONLY; -+ int flags = O_CREAT | O_EXCL | O_WRONLY; - int mode = 0644; - int fd; - -- snprintf(tmp, sizeof(tmp), "%s.tmp", itr->name); -+ snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(), -+ tv.tv_usec, tv.tv_sec); - fd = openat(dfd, tmp, flags, mode); - if (fd < 0) { - ERR("openat(%s, %s, %o, %o): %m\n", --- -1.8.3.1 - diff --git a/kmod-25.tar.xz b/kmod-25.tar.xz deleted file mode 100644 index 8131248537b21420c4182c03ebbb28f593303a56..0000000000000000000000000000000000000000 Binary files a/kmod-25.tar.xz and /dev/null differ diff --git a/kmod-27.tar.xz b/kmod-27.tar.xz new file mode 100644 index 0000000000000000000000000000000000000000..a3e46aeaad49aceb5610a9cc8fa3bac4a9e790ca Binary files /dev/null and b/kmod-27.tar.xz differ diff --git a/kmod.spec b/kmod.spec index 2fc438be460ce45b9ebd032af6dbe61c81035e87..9bdb756020cb544dc2f3d995f6a22a16be4fd798 100644 --- a/kmod.spec +++ b/kmod.spec @@ -1,6 +1,6 @@ Name: kmod -Version: 25 -Release: 6 +Version: 27 +Release: 2 Summary: Kernel module management # GPLv2+ is used by programs, LGPLv2+ is used for libraries. License: GPLv2+ and LGPLv2+ @@ -9,11 +9,11 @@ Source0: https://www.kernel.org/pub/linux/utils/kernel/kmod/%{name}-%{ver Source1: weak-modules Source2: depmod.conf.dist +Patch6000: backport-libkmod-fix-return-error-when-opening-index.patch +Patch6001: backport-libkmod-allow-modules.alias.builtin-to-be-optional.patch Patch9000: bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch -Patch9001: libkmod-module-check-for-NULL-before-accessing-point.patch -Patch9002: depmod-prevent-module-dependency-files-corruption-du.patch -BuildRequires: gcc chrpath zlib-devel xz-devel libxslt +BuildRequires: gcc chrpath zlib-devel xz-devel libxslt openssl-devel Provides: module-init-tools = 4.0-1 Provides: /sbin/modprobe @@ -50,7 +50,7 @@ developers to understand the kmod. %autosetup -n %{name}-%{version} -p1 %build -%configure --with-zlib --with-xz +%configure --with-openssl --with-zlib --with-xz %make_build %install @@ -106,6 +106,18 @@ install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/depmod.d/dist.conf %doc TODO NEWS README %changelog +* Tue May 5 2020 Wang Shuo - 27-2 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC: backport patch to deal with lspci -v error report + +* Fri Apr 17 2020 Wang Shuo - 27-1 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC: update kmod to 27 + * Wed Feb 28 2020 Wang Shuo - 25-6 - Type:enhancement - ID:NA diff --git a/libkmod-module-check-for-NULL-before-accessing-point.patch b/libkmod-module-check-for-NULL-before-accessing-point.patch deleted file mode 100644 index d3914ca3b7553f1b4d76415b14963fda9f140797..0000000000000000000000000000000000000000 --- a/libkmod-module-check-for-NULL-before-accessing-point.patch +++ /dev/null @@ -1,126 +0,0 @@ -From c8f0623ad18194eedfcca69ccae1cbfe6cf5d2a8 Mon Sep 17 00:00:00 2001 -From: Luca Bruno -Date: Wed, 7 Mar 2018 10:51:21 +0000 -Subject: [PATCH 04/36] libkmod-module: check for NULL before accessing - pointers - -This introduces a few missing NULL-checks in public functions, and -align their docstrings with real behavior by getting rid of copy-paste -mistakes. - -Signed-off-by: Luca Bruno ---- - TODO | 5 +++++ - libkmod/libkmod-module.c | 23 ++++++++++------------- - 2 files changed, 15 insertions(+), 13 deletions(-) - -diff --git a/TODO b/TODO -index 537e7e1..3fe06eb 100644 ---- a/TODO -+++ b/TODO -@@ -35,6 +35,11 @@ and libkmod - - kmod_module_symbols_free_list() - - kmod_module_dependency_symbols_free_list() - -+* libkmod API breaking changes: -+ - dedicated error value for all kmod_*_get_crc() functions. Currently there -+ is no way for callers to distinguish between a valid CRC=0 and the error -+ code 0. -+ - * index: drop the "open(), seek(), read()" implementation and use another one - with mmap(). When lookup() is called and the file is not mmaped, mmap it. - Another possibility is to drop the mmap implementation relying on VFS to have -diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c -index 0a3ef11..ee420f4 100644 ---- a/libkmod/libkmod-module.c -+++ b/libkmod/libkmod-module.c -@@ -2519,7 +2519,7 @@ KMOD_EXPORT const char *kmod_module_version_get_symbol(const struct kmod_list *e - { - struct kmod_module_version *version; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return NULL; - - version = entry->data; -@@ -2532,14 +2532,13 @@ KMOD_EXPORT const char *kmod_module_version_get_symbol(const struct kmod_list *e - * - * Get the crc of a kmod module version. - * -- * Returns: the crc of this kmod module version on success or NULL on -- * failure. The string is owned by the version, do not free it. -+ * Returns: the crc of this kmod module version if available, otherwise default to 0. - */ - KMOD_EXPORT uint64_t kmod_module_version_get_crc(const struct kmod_list *entry) - { - struct kmod_module_version *version; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return 0; - - version = entry->data; -@@ -2660,7 +2659,7 @@ KMOD_EXPORT const char *kmod_module_symbol_get_symbol(const struct kmod_list *en - { - struct kmod_module_symbol *symbol; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return NULL; - - symbol = entry->data; -@@ -2673,14 +2672,13 @@ KMOD_EXPORT const char *kmod_module_symbol_get_symbol(const struct kmod_list *en - * - * Get the crc of a kmod module symbol. - * -- * Returns: the crc of this kmod module symbol on success or NULL on -- * failure. The string is owned by the symbol, do not free it. -+ * Returns: the crc of this kmod module symbol if available, otherwise default to 0. - */ - KMOD_EXPORT uint64_t kmod_module_symbol_get_crc(const struct kmod_list *entry) - { - struct kmod_module_symbol *symbol; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return 0; - - symbol = entry->data; -@@ -2806,7 +2804,7 @@ KMOD_EXPORT const char *kmod_module_dependency_symbol_get_symbol(const struct km - { - struct kmod_module_dependency_symbol *dependency_symbol; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return NULL; - - dependency_symbol = entry->data; -@@ -2819,14 +2817,13 @@ KMOD_EXPORT const char *kmod_module_dependency_symbol_get_symbol(const struct km - * - * Get the crc of a kmod module dependency_symbol. - * -- * Returns: the crc of this kmod module dependency_symbol on success or NULL on -- * failure. The string is owned by the dependency_symbol, do not free it. -+ * Returns: the crc of this kmod module dependency_symbol if available, otherwise default to 0. - */ - KMOD_EXPORT uint64_t kmod_module_dependency_symbol_get_crc(const struct kmod_list *entry) - { - struct kmod_module_dependency_symbol *dependency_symbol; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return 0; - - dependency_symbol = entry->data; -@@ -2846,7 +2843,7 @@ KMOD_EXPORT int kmod_module_dependency_symbol_get_bind(const struct kmod_list *e - { - struct kmod_module_dependency_symbol *dependency_symbol; - -- if (entry == NULL) -+ if (entry == NULL || entry->data == NULL) - return 0; - - dependency_symbol = entry->data; --- -1.8.3.1 -