!6 update kmod to kmod-27

Merge pull request !6 from wswsamao/mybranch
This commit is contained in:
openeuler-ci-bot 2020-05-12 20:29:38 +08:00 committed by Gitee
commit 121d611300
8 changed files with 243 additions and 211 deletions

View File

@ -0,0 +1,46 @@
From d8d1d54051053d770643b59c3f5cf5608a17a0ce Mon Sep 17 00:00:00 2001
From: Lucas De Marchi <lucas.demarchi@intel.com>
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

View File

@ -0,0 +1,171 @@
From 3bd7187ff549a2ef2441dcddabf382cc53cf6f22 Mon Sep 17 00:00:00 2001
From: Lucas De Marchi <lucas.demarchi@intel.com>
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

View File

@ -4,32 +4,23 @@ Date: Fri, 25 Jan 2019 17:03:05 +0000
Subject: [PATCH] ok
Signed-off-by: guoxiaoqi <guoxiaoqi2@huawei.com>
---
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

View File

@ -1,62 +0,0 @@
From a06bacf500d56b72b5f9b121ebf7f6af9e3df185 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
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 <msuchanek@suse.de>
---
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 <string.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/utsname.h>
#include <shared/array.h>
@@ -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

Binary file not shown.

BIN
kmod-27.tar.xz Normal file

Binary file not shown.

View File

@ -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<wangshuo47@huawei.com> - 27-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: backport patch to deal with lspci -v error report
* Fri Apr 17 2020 Wang Shuo<wangshuo47@huawei.com> - 27-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: update kmod to 27
* Wed Feb 28 2020 Wang Shuo<wangshuo47@huawei.com> - 25-6
- Type:enhancement
- ID:NA

View File

@ -1,126 +0,0 @@
From c8f0623ad18194eedfcca69ccae1cbfe6cf5d2a8 Mon Sep 17 00:00:00 2001
From: Luca Bruno <luca.bruno@coreos.com>
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 <luca.bruno@coreos.com>
---
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