Skip to content

Commit

Permalink
kernel/params.c: generalize bool_enable_only
Browse files Browse the repository at this point in the history
This takes out the bool_enable_only implementation from
the module loading code and generalizes it so that others
can make use of it.

Cc: Rusty Russell <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
mcgrof authored and rustyrussell committed May 28, 2015
1 parent 05f408d commit d19f05d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
6 changes: 6 additions & 0 deletions include/linux/moduleparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ extern int param_set_bool(const char *val, const struct kernel_param *kp);
extern int param_get_bool(char *buffer, const struct kernel_param *kp);
#define param_check_bool(name, p) __param_check(name, p, bool)

extern const struct kernel_param_ops param_ops_bool_enable_only;
extern int param_set_bool_enable_only(const char *val,
const struct kernel_param *kp);
/* getter is the same as for the regular bool */
#define param_check_bool_enable_only param_check_bool

extern const struct kernel_param_ops param_ops_invbool;
extern int param_set_invbool(const char *val, const struct kernel_param *kp);
extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
Expand Down
31 changes: 0 additions & 31 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,37 +298,6 @@ static bool sig_enforce = true;
#else
static bool sig_enforce = false;

static int param_set_bool_enable_only(const char *val,
const struct kernel_param *kp)
{
int err = 0;
bool new_value;
bool orig_value = *(bool *)kp->arg;
struct kernel_param dummy_kp = *kp;

dummy_kp.arg = &new_value;

err = param_set_bool(val, &dummy_kp);
if (err)
return err;

/* Don't let them unset it once it's set! */
if (!new_value && orig_value)
return -EROFS;

if (new_value)
err = param_set_bool(val, kp);

return err;
}

static const struct kernel_param_ops param_ops_bool_enable_only = {
.flags = KERNEL_PARAM_OPS_FL_NOARG,
.set = param_set_bool_enable_only,
.get = param_get_bool,
};
#define param_check_bool_enable_only param_check_bool

module_param(sig_enforce, bool_enable_only, 0644);
#endif /* !CONFIG_MODULE_SIG_FORCE */
#endif /* CONFIG_MODULE_SIG */
Expand Down
30 changes: 30 additions & 0 deletions kernel/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,36 @@ const struct kernel_param_ops param_ops_bool = {
};
EXPORT_SYMBOL(param_ops_bool);

int param_set_bool_enable_only(const char *val, const struct kernel_param *kp)
{
int err = 0;
bool new_value;
bool orig_value = *(bool *)kp->arg;
struct kernel_param dummy_kp = *kp;

dummy_kp.arg = &new_value;

err = param_set_bool(val, &dummy_kp);
if (err)
return err;

/* Don't let them unset it once it's set! */
if (!new_value && orig_value)
return -EROFS;

if (new_value)
err = param_set_bool(val, kp);

return err;
}
EXPORT_SYMBOL_GPL(param_set_bool_enable_only);

const struct kernel_param_ops param_ops_bool_enable_only = {
.flags = KERNEL_PARAM_OPS_FL_NOARG,
.set = param_set_bool_enable_only,
.get = param_get_bool,
};

/* This one must be bool. */
int param_set_invbool(const char *val, const struct kernel_param *kp)
{
Expand Down

0 comments on commit d19f05d

Please sign in to comment.