SHA256
1
0
forked from pool/kmod
kmod/0002-depmod-ignore-related-modules-in-depmod_report_cycle.patch

83 lines
2.9 KiB
Diff

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)