Accepting request 441318 from home:ykaukab:branches:Base:System

Fix bug boo#1008186

OBS-URL: https://build.opensuse.org/request/show/441318
OBS-URL: https://build.opensuse.org/package/show/Base:System/kmod?expand=0&rev=115
This commit is contained in:
Jan Engelhardt 2016-11-22 09:36:22 +00:00 committed by Git OBS Bridge
parent 0ed1d615fe
commit 17237728d7
6 changed files with 271 additions and 4 deletions

View File

@ -0,0 +1,167 @@
From 965886b55ab2f80fc242c1bc7e92423c87424718 Mon Sep 17 00:00:00 2001
From: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
Date: Tue, 8 Nov 2016 17:45:49 +0100
Subject: [PATCH 1/2] testsuite: depmod: add module dependency outside cyclic
chain
Check that depmod do not report modules outside cyclic chain
Two modules f and g are added which do not have any dependency.
modules a and b are made dependent on f and g.
Here is the output of loop dependency check test after adding this
patch:
TESTSUITE: ERR: wrong:
depmod: ERROR: Found 7 modules in dependency cycles!
depmod: ERROR: Cycle detected: mod_loop_d -> mod_loop_e -> mod_loop_d
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_b
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_g
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_f
Buffer overflow occurs in the loop when last two lines are printed.
43 bytes buffer is allocated and 53 bytes are used.
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
---
testsuite/module-playground/Makefile | 6 +++++-
testsuite/module-playground/mod-loop-a.c | 2 ++
testsuite/module-playground/mod-loop-b.c | 2 ++
testsuite/module-playground/mod-loop-f.c | 24 ++++++++++++++++++++++++
testsuite/module-playground/mod-loop-g.c | 24 ++++++++++++++++++++++++
testsuite/module-playground/mod-loop.h | 2 ++
testsuite/populate-modules.sh | 2 ++
7 files changed, 61 insertions(+), 1 deletion(-)
create mode 100644 testsuite/module-playground/mod-loop-f.c
create mode 100644 testsuite/module-playground/mod-loop-g.c
Index: kmod-23/testsuite/module-playground/Makefile
===================================================================
--- kmod-23.orig/testsuite/module-playground/Makefile
+++ kmod-23/testsuite/module-playground/Makefile
@@ -12,13 +12,17 @@ obj-m += mod-foo-c.o
obj-m += mod-foo.o
# mod-loop: create loops in dependencies:
-# 1) mod-loop-a -> mod-loop-b -> mod-loop-c -> mod-loop-a
+# 1) mod-loop-a -> mod-loop-b -> mod-loop-c -> mod-loop-a
+# |-> mod-loop-f |-> mod-loop-f
+# \-> mod-loop-g \-> mod-loop-g
# 2) mod-loop-d -> mod-loop-e -> mod-loop-d
obj-m += mod-loop-a.o
obj-m += mod-loop-b.o
obj-m += mod-loop-c.o
obj-m += mod-loop-d.o
obj-m += mod-loop-e.o
+obj-m += mod-loop-f.o
+obj-m += mod-loop-g.o
# mod-fake-*: fake the respective modules in kernel with these aliases. Aliases
# list was taken from 3.5.4
Index: kmod-23/testsuite/module-playground/mod-loop-a.c
===================================================================
--- kmod-23.orig/testsuite/module-playground/mod-loop-a.c
+++ kmod-23/testsuite/module-playground/mod-loop-a.c
@@ -10,6 +10,8 @@ static int __init test_module_init(void)
{
printA();
printB();
+ printF();
+ printG();
return 0;
}
Index: kmod-23/testsuite/module-playground/mod-loop-b.c
===================================================================
--- kmod-23.orig/testsuite/module-playground/mod-loop-b.c
+++ kmod-23/testsuite/module-playground/mod-loop-b.c
@@ -10,6 +10,8 @@ static int __init test_module_init(void)
{
printB();
printC();
+ printF();
+ printG();
return 0;
}
Index: kmod-23/testsuite/module-playground/mod-loop-f.c
===================================================================
--- /dev/null
+++ kmod-23/testsuite/module-playground/mod-loop-f.c
@@ -0,0 +1,24 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+#include "mod-loop.h"
+
+static int __init test_module_init(void)
+{
+ printF();
+
+ return 0;
+}
+module_init(test_module_init);
+
+void printF(void)
+{
+ pr_warn("Hello, world F\n");
+}
+EXPORT_SYMBOL(printF);
+
+MODULE_AUTHOR("Lucas De Marchi <lucas.demarchi@intel.com>");
+MODULE_LICENSE("LGPL");
Index: kmod-23/testsuite/module-playground/mod-loop-g.c
===================================================================
--- /dev/null
+++ kmod-23/testsuite/module-playground/mod-loop-g.c
@@ -0,0 +1,24 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+#include "mod-loop.h"
+
+static int __init test_module_init(void)
+{
+ printG();
+
+ return 0;
+}
+module_init(test_module_init);
+
+void printG(void)
+{
+ pr_warn("Hello, world G\n");
+}
+EXPORT_SYMBOL(printG);
+
+MODULE_AUTHOR("Lucas De Marchi <lucas.demarchi@intel.com>");
+MODULE_LICENSE("LGPL");
Index: kmod-23/testsuite/module-playground/mod-loop.h
===================================================================
--- kmod-23.orig/testsuite/module-playground/mod-loop.h
+++ kmod-23/testsuite/module-playground/mod-loop.h
@@ -5,3 +5,5 @@ void printB(void);
void printC(void);
void printD(void);
void printE(void);
+void printF(void);
+void printG(void);
Index: kmod-23/testsuite/populate-modules.sh
===================================================================
--- kmod-23.orig/testsuite/populate-modules.sh
+++ kmod-23/testsuite/populate-modules.sh
@@ -16,6 +16,8 @@ map=(
["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-c.ko"]="mod-loop-c.ko"
["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-d.ko"]="mod-loop-d.ko"
["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-e.ko"]="mod-loop-e.ko"
+ ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-f.ko"]="mod-loop-f.ko"
+ ["test-depmod/detect-loop/lib/modules/4.4.4/kernel/mod-loop-g.ko"]="mod-loop-g.ko"
["test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/foo/"]="mod-foo-b.ko"
["test-dependencies/lib/modules/4.0.20-kmod/kernel/"]="mod-foo-c.ko"
["test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/"]="mod-foo-a.ko"

View File

@ -0,0 +1,82 @@
From 6b77f188969d72254f6bda291f4f2d9fd42f5ecc Mon Sep 17 00:00:00 2001
From: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
Date: Tue, 8 Nov 2016 17:45:50 +0100
Subject: [PATCH 2/2] depmod: ignore related modules in depmod_report_cycles
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Only print actual cyclic dependencies. Print count of all the modules
in cyclic dependency at the end of the function so that dependent
modules which are not in cyclic chain can be ignored.
Printing dependent modules which are not in cyclic chain causes buffer
overflow as m->modnamesz is not included in buffer size calculations
(loop == m is never true). This buffer overflow causes kmod to crash.
Update depmod test to reflect the change as well.
Reported-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
---
.../rootfs-pristine/test-depmod/detect-loop/correct.txt | 2 +-
tools/depmod.c | 13 ++++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
Index: kmod-23/testsuite/rootfs-pristine/test-depmod/detect-loop/correct.txt
===================================================================
--- kmod-23.orig/testsuite/rootfs-pristine/test-depmod/detect-loop/correct.txt
+++ kmod-23/testsuite/rootfs-pristine/test-depmod/detect-loop/correct.txt
@@ -1,3 +1,3 @@
-depmod: ERROR: Found 5 modules in dependency cycles!
depmod: ERROR: Cycle detected: mod_loop_d -> mod_loop_e -> mod_loop_d
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_b
+depmod: ERROR: Found 5 modules in dependency cycles!
Index: kmod-23/tools/depmod.c
===================================================================
--- kmod-23.orig/tools/depmod.c
+++ kmod-23/tools/depmod.c
@@ -1455,7 +1455,7 @@ static void depmod_report_cycles(struct
{
const char sep[] = " -> ";
int ir = 0;
- ERR("Found %u modules in dependency cycles!\n", n_roots);
+ int num_cyclic = 0;
while (n_roots > 0) {
int is, ie;
@@ -1490,6 +1490,7 @@ static void depmod_report_cycles(struct
if (m->visited) {
int i, n = 0, sz = 0;
char *buf;
+ bool is_cyclic = false;
for (i = ie - 1; i >= 0; i--) {
struct mod *loop = depmod->modules.array[edges[i]];
@@ -1497,9 +1498,17 @@ static void depmod_report_cycles(struct
n++;
if (loop == m) {
sz += loop->modnamesz - 1;
+ is_cyclic = true;
break;
}
}
+ /* Current module not found in dependency list.
+ * Must be a related module. Ignore it.
+ */
+ if (!is_cyclic)
+ continue;
+
+ num_cyclic += n;
buf = malloc(sz + n * strlen(sep) + 1);
sz = 0;
@@ -1537,6 +1546,8 @@ static void depmod_report_cycles(struct
}
}
}
+
+ ERR("Found %d modules in dependency cycles!\n", num_cyclic);
}
static int depmod_calculate_dependencies(struct depmod *depmod)

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Nov 22 09:13:47 UTC 2016 - yousaf.kaukab@suse.com
- 0001-testsuite-depmod-add-module-dependency-outside-cycli.patch:
Add test case where cyclic and non-cyclic dependencies are present
at the same time. (boo#1008186)
-------------------------------------------------------------------
Thu Mar 31 16:53:28 UTC 2016 - normand@linux.vnet.ibm.com

View File

@ -1,7 +1,7 @@
#
# spec file for package kmod-testsuite
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -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: 0001-testsuite-depmod-add-module-dependency-outside-cycli.patch
Patch9: 0002-depmod-ignore-related-modules-in-depmod_report_cycle.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,10 @@
-------------------------------------------------------------------
Tue Nov 22 09:10:54 UTC 2016 - yousaf.kaukab@suse.com
- 0002-depmod-ignore-related-modules-in-depmod_report_cycle.patch:
Fix buffer overflow when printing modules in cyclic dependency
chain (boo#1008186)
-------------------------------------------------------------------
Thu Jul 21 09:56:02 UTC 2016 - jengelh@inai.de

View File

@ -1,7 +1,7 @@
#
# spec file for package kmod
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -35,6 +35,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: 0001-testsuite-depmod-add-module-dependency-outside-cycli.patch
Patch9: 0002-depmod-ignore-related-modules-in-depmod_report_cycle.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: autoconf
BuildRequires: automake
@ -100,7 +102,7 @@ in %lname.
%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