diff options
author | Andreas Robinson <andr345@gmail.com> | 2009-10-04 17:18:38 +0200 |
---|---|---|
committer | Andreas Robinson <andr345@gmail.com> | 2009-10-04 17:18:38 +0200 |
commit | f2150e81dbeb547f9fc70b8c622c38cc6f987a50 (patch) | |
tree | f490ff8a8b6fc389719e1489dfec22ba96cf6d9d | |
parent | d7a8758609dc13d048a249295c2dcc4345cbf40f (diff) | |
download | module-init-tools-f2150e81dbeb547f9fc70b8c622c38cc6f987a50.tar.gz |
modprobe: add simple softdep loop detector
Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r-- | modprobe.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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); |