aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Robinson <andr345@gmail.com>2009-10-04 17:18:38 +0200
committerAndreas Robinson <andr345@gmail.com>2009-10-04 17:18:38 +0200
commitf2150e81dbeb547f9fc70b8c622c38cc6f987a50 (patch)
treef490ff8a8b6fc389719e1489dfec22ba96cf6d9d
parentd7a8758609dc13d048a249295c2dcc4345cbf40f (diff)
downloadmodule-init-tools-f2150e81dbeb547f9fc70b8c622c38cc6f987a50.tar.gz
modprobe: add simple softdep loop detector
Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r--modprobe.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/modprobe.c b/modprobe.c
index 6ce3ad0..317a109 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -51,6 +51,13 @@
int use_binary_indexes = 1; /* default to enabled. */
+/* Limit do_softdep/do_modprobe recursion.
+ * This is a simple way to handle dependency loops
+ * caused by poorly written softdep commands.
+ */
+static int recursion_depth = 0;
+const int MAX_RECURSION = 50; /* Arbitrary choice */
+
extern long init_module(void *, unsigned long, const char *);
extern long delete_module(const char *, unsigned int);
@@ -1170,6 +1177,11 @@ static void do_softdep(const struct module_softdep *softdep,
struct string_table *pre_modnames, *post_modnames;
int i, j;
+ if (++recursion_depth >= MAX_RECURSION)
+ fatal("modprobe: softdep dependency loop encountered %s %s\n",
+ (flags & mit_remove) ? "removing" : "inserting",
+ softdep->modname);
+
if (flags & mit_remove) {
/* Reverse module order if removing. */
pre_modnames = softdep->post;
@@ -1615,6 +1627,8 @@ int main(int argc, char *argv[])
int failed = 0;
modprobe_flags_t flags = 0;
+ recursion_depth = 0;
+
/* Prepend options from environment. */
argv = merge_args(getenv("MODPROBE_OPTIONS"), argv, &argc);