-
Notifications
You must be signed in to change notification settings - Fork 52
Add mask command and modprobe test with blacklist #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -734,12 +734,30 @@ static bool module_is_blacklisted(const struct kmod_module *mod) | |
return false; | ||
} | ||
|
||
static bool module_is_masked(const struct kmod_module *mod) | ||
{ | ||
const struct kmod_ctx *ctx = mod->ctx; | ||
const struct kmod_config *config = kmod_get_config(ctx); | ||
const struct kmod_list *bl = config->masks; | ||
const struct kmod_list *l; | ||
|
||
kmod_list_foreach(l, bl) { | ||
const char *modname = kmod_mask_get_modname(l); | ||
|
||
if (streq(modname, mod->name)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, | ||
enum kmod_filter filter_type, | ||
const struct kmod_list *input, | ||
struct kmod_list **output) | ||
{ | ||
const struct kmod_list *li; | ||
int err = 0; | ||
|
||
if (ctx == NULL || output == NULL) | ||
return -ENOENT; | ||
|
@@ -758,9 +776,20 @@ KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, | |
if ((filter_type & KMOD_FILTER_BUILTIN) && kmod_module_is_builtin(mod)) | ||
continue; | ||
|
||
if ((filter_type & KMOD_FILTER_MASK) && module_is_masked(mod)) { | ||
if (!mod->required) | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
ERR(mod->ctx, "module is masked: %s\n", | ||
kmod_module_get_name(mod)); | ||
err = -EINVAL; | ||
goto fail; | ||
} | ||
|
||
node = kmod_list_append(*output, mod); | ||
if (node == NULL) | ||
if (node == NULL) { | ||
err = -ENOMEM; | ||
goto fail; | ||
} | ||
|
||
*output = node; | ||
kmod_module_ref(mod); | ||
|
@@ -771,7 +800,7 @@ KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx, | |
fail: | ||
kmod_module_unref_list(*output); | ||
*output = NULL; | ||
return -ENOMEM; | ||
return err; | ||
} | ||
|
||
static int command_do(struct kmod_module *mod, const char *type, const char *cmd) | ||
|
@@ -1005,7 +1034,7 @@ KMOD_EXPORT int kmod_module_probe_insert_module( | |
const void *data, | ||
void (*print_action)(struct kmod_module *m, bool install, const char *options)) | ||
{ | ||
struct kmod_list *list = NULL, *l; | ||
struct kmod_list *list = NULL, *l, *filtered = NULL; | ||
struct probe_insert_cb cb; | ||
int err; | ||
|
||
|
@@ -1019,6 +1048,11 @@ KMOD_EXPORT int kmod_module_probe_insert_module( | |
return 0; | ||
} | ||
|
||
if (module_is_masked(mod)) { | ||
ERR(mod->ctx, "module is masked: %s\n", kmod_module_get_name(mod)); | ||
return -EINVAL; | ||
} | ||
|
||
if (module_is_blacklisted(mod)) { | ||
if (mod->alias != NULL && (flags & KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY)) | ||
return KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY; | ||
|
@@ -1035,15 +1069,23 @@ KMOD_EXPORT int kmod_module_probe_insert_module( | |
if (err < 0) | ||
return err; | ||
|
||
if (flags & KMOD_PROBE_APPLY_BLACKLIST_ALL) { | ||
struct kmod_list *filtered = NULL; | ||
err = kmod_module_apply_filter(mod->ctx, KMOD_FILTER_MASK, list, &filtered); | ||
kmod_module_unref_list(list); | ||
if (err < 0) | ||
return err; | ||
|
||
if (filtered == NULL) | ||
return -EINVAL; | ||
|
||
list = filtered; | ||
|
||
if (flags & KMOD_PROBE_APPLY_BLACKLIST_ALL) { | ||
err = kmod_module_apply_filter(mod->ctx, KMOD_FILTER_BLACKLIST, list, | ||
&filtered); | ||
kmod_module_unref_list(list); | ||
if (err < 0) | ||
return err; | ||
|
||
kmod_module_unref_list(list); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely spotted. Let's split this one-line corner-case memory leak fix in its* own commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity (aka non-blocking question): What is the command which produces the Sanitizer leak report? Does one need to modify code or it happens out of the box? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had ASAN complaining primarily at 1072 when we had a similar sequence of statements: filter -> return -> unref. You'd need to hit any of the failing conditions of the filter: |
||
if (filtered == NULL) | ||
return KMOD_PROBE_APPLY_BLACKLIST_ALL; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
blacklist mod-foo-b |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases extracted from modules themselves. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kernel/mod-foo-b.ko: | ||
kernel/mod-foo-c.ko: | ||
kernel/mod-foo-a.ko: | ||
kernel/mod-foo.ko: kernel/mod-foo-b.ko kernel/mod-foo-a.ko kernel/mod-foo-c.ko |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Device nodes to trigger on-demand module loading. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Soft dependencies extracted from modules themselves. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Aliases for symbols, used by symbol_request(). | ||
alias symbol:print_fooA mod_foo_a | ||
alias symbol:print_fooC mod_foo_c | ||
alias symbol:print_fooB mod_foo_b |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alias simple.* mod-simple | ||
blacklist mod-simple |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases extracted from modules themselves. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kernel/mod-simple.ko: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Device nodes to trigger on-demand module loading. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Soft dependencies extracted from modules themselves. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases for symbols, used by symbol_request(). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
softdep mod-simple pre: mod-foo-a | ||
blacklist mod-foo-a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases extracted from modules themselves. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
kernel/mod-foo-a.ko: | ||
kernel/mod-simple.ko: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Device nodes to trigger on-demand module loading. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Soft dependencies extracted from modules themselves. |
Uh oh!
There was an error while loading. Please reload this page.