Accepting request 403054 from home:michal-m:branches:Base:System

- libkmod: Handle long lines in /proc/modules (bsc#983754)
  0001-libkmod-Handle-long-lines-in-proc-modules.patch

OBS-URL: https://build.opensuse.org/request/show/403054
OBS-URL: https://build.opensuse.org/package/show/Base:System/kmod?expand=0&rev=107
This commit is contained in:
Jan Engelhardt 2016-06-17 15:29:31 +00:00 committed by Git OBS Bridge
parent 6935bee3df
commit 1b55364c8c
4 changed files with 104 additions and 2 deletions

View File

@ -0,0 +1,93 @@
From d1a89109faebc3db7e01d10fb8ac6f9dd2332a8f Mon Sep 17 00:00:00 2001
From: Michal Marek <mmarek@suse.cz>
Date: Thu, 16 Jun 2016 09:18:52 +0200
Subject: [PATCH] libkmod: Handle long lines in /proc/modules
Patch-mainline: Submitted to linux-modules@vger.kernel.org on 2016-06-17
References: bsc#983754
kmod_module_new_from_loaded() calls fgets with a 4k buffer. When a
module such as usbcore is used by too many modules, the rest of the line
is considered a beginning of another lines and we eventually get errors
like these from lsmod:
libkmod: kmod_module_get_holders: could not open '/sys/module/100,/holders': No such file or directory
together with bogus entries in the output. In kmod_module_get_size, the
problem does not affect functionality, but the line numbers in error
messages will be wrong.
Signed-off-by: Michal Marek <mmarek@suse.com>
---
I wrote a test case for this as well, but it is failing because the
testsuite itself has problems with output larger than 4k. I'll send
something later.
Also, the buffer could be shrinked now, so that we do not use that much
space on stack. Not sure if this is of interest or not. I left it as is.
Michal
---
libkmod/libkmod-module.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 1460c6746cc4..25dcda7667b7 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -1660,13 +1660,14 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
struct kmod_module *m;
struct kmod_list *node;
int err;
+ size_t len = strlen(line);
char *saveptr, *name = strtok_r(line, " \t", &saveptr);
err = kmod_module_new_from_name(ctx, name, &m);
if (err < 0) {
ERR(ctx, "could not get module from name '%s': %s\n",
name, strerror(-err));
- continue;
+ goto eat_line;
}
node = kmod_list_append(l, m);
@@ -1676,6 +1677,9 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
ERR(ctx, "out of memory\n");
kmod_module_unref(m);
}
+eat_line:
+ while (line[len - 1] != '\n' && fgets(line, sizeof(line), fp))
+ len = strlen(line);
}
fclose(fp);
@@ -1825,12 +1829,13 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
}
while (fgets(line, sizeof(line), fp)) {
+ size_t len = strlen(line);
char *saveptr, *endptr, *tok = strtok_r(line, " \t", &saveptr);
long value;
lineno++;
if (tok == NULL || !streq(tok, mod->name))
- continue;
+ goto eat_line;
tok = strtok_r(NULL, " \t", &saveptr);
if (tok == NULL) {
@@ -1848,6 +1853,9 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
size = value;
break;
+eat_line:
+ while (line[len - 1] != '\n' && fgets(line, sizeof(line), fp))
+ len = strlen(line);
}
fclose(fp);
--
2.6.2

View File

@ -36,6 +36,8 @@ Patch3: 0009-libkmod-Implement-filtering-of-unsupported-modules-o.patch
Patch4: 0010-modprobe-Implement-allow-unsupported-modules.patch
Patch5: 0011-Do-not-filter-unsupported-modules-when-running-a-van.patch
Patch7: 0001-use-correct-sort-method-in-test-array.patch
Patch8: depmod-Ignore_PowerPC64_ABIv2_.TOC.symbol.patch
Patch9: 0001-libkmod-Handle-long-lines-in-proc-modules.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: autoconf
BuildRequires: automake
@ -61,7 +63,7 @@ buildloop with the kernel.
%prep
%setup -q -n kmod-%version
%patch -P 1 -P 2 -P 3 -P 4 -P 5 -P 7 -p1
%patch -P 1 -P 2 -P 3 -P 4 -P 5 -P 7 -P 8 -P 9 -p1
%build
autoreconf -fi

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jun 17 15:18:29 UTC 2016 - mmarek@suse.cz
- libkmod: Handle long lines in /proc/modules (bsc#983754)
0001-libkmod-Handle-long-lines-in-proc-modules.patch
-------------------------------------------------------------------
Tue Feb 9 15:15:56 UTC 2016 - dvaleev@suse.com

View File

@ -37,6 +37,7 @@ Patch4: 0010-modprobe-Implement-allow-unsupported-modules.patch
Patch5: 0011-Do-not-filter-unsupported-modules-when-running-a-van.patch
Patch7: 0001-use-correct-sort-method-in-test-array.patch
Patch8: depmod-Ignore_PowerPC64_ABIv2_.TOC.symbol.patch
Patch9: 0001-libkmod-Handle-long-lines-in-proc-modules.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: autoconf
BuildRequires: automake
@ -102,7 +103,7 @@ in %lname.
%prep
%setup -q -n kmod-%version
%patch -P 1 -P 2 -P 3 -P 4 -P 5 -P 7 -p1 -P 8 -p1
%patch -P 1 -P 2 -P 3 -P 4 -P 5 -P 7 -P 8 -P 9 -p1
%build
autoreconf -fi