Skip to content

Commit d19f05d

Browse files
mcgrofrustyrussell
authored andcommitted
kernel/params.c: generalize bool_enable_only
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 <rusty@rustcorp.com.au> Cc: Jani Nikula <jani.nikula@intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Kees Cook <keescook@chromium.org> Cc: Tejun Heo <tj@kernel.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: linux-kernel@vger.kernel.org Cc: cocci@systeme.lip6.fr Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 05f408d commit d19f05d

3 files changed

Lines changed: 36 additions & 31 deletions

File tree

‎include/linux/moduleparam.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ extern int param_set_bool(const char *val, const struct kernel_param *kp);
427427
extern int param_get_bool(char *buffer, const struct kernel_param *kp);
428428
#define param_check_bool(name, p) __param_check(name, p, bool)
429429

430+
extern const struct kernel_param_ops param_ops_bool_enable_only;
431+
extern int param_set_bool_enable_only(const char *val,
432+
const struct kernel_param *kp);
433+
/* getter is the same as for the regular bool */
434+
#define param_check_bool_enable_only param_check_bool
435+
430436
extern const struct kernel_param_ops param_ops_invbool;
431437
extern int param_set_invbool(const char *val, const struct kernel_param *kp);
432438
extern int param_get_invbool(char *buffer, const struct kernel_param *kp);

‎kernel/module.c‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -298,37 +298,6 @@ static bool sig_enforce = true;
298298
#else
299299
static bool sig_enforce = false;
300300

301-
static int param_set_bool_enable_only(const char *val,
302-
const struct kernel_param *kp)
303-
{
304-
int err = 0;
305-
bool new_value;
306-
bool orig_value = *(bool *)kp->arg;
307-
struct kernel_param dummy_kp = *kp;
308-
309-
dummy_kp.arg = &new_value;
310-
311-
err = param_set_bool(val, &dummy_kp);
312-
if (err)
313-
return err;
314-
315-
/* Don't let them unset it once it's set! */
316-
if (!new_value && orig_value)
317-
return -EROFS;
318-
319-
if (new_value)
320-
err = param_set_bool(val, kp);
321-
322-
return err;
323-
}
324-
325-
static const struct kernel_param_ops param_ops_bool_enable_only = {
326-
.flags = KERNEL_PARAM_OPS_FL_NOARG,
327-
.set = param_set_bool_enable_only,
328-
.get = param_get_bool,
329-
};
330-
#define param_check_bool_enable_only param_check_bool
331-
332301
module_param(sig_enforce, bool_enable_only, 0644);
333302
#endif /* !CONFIG_MODULE_SIG_FORCE */
334303
#endif /* CONFIG_MODULE_SIG */

‎kernel/params.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,36 @@ const struct kernel_param_ops param_ops_bool = {
335335
};
336336
EXPORT_SYMBOL(param_ops_bool);
337337

338+
int param_set_bool_enable_only(const char *val, const struct kernel_param *kp)
339+
{
340+
int err = 0;
341+
bool new_value;
342+
bool orig_value = *(bool *)kp->arg;
343+
struct kernel_param dummy_kp = *kp;
344+
345+
dummy_kp.arg = &new_value;
346+
347+
err = param_set_bool(val, &dummy_kp);
348+
if (err)
349+
return err;
350+
351+
/* Don't let them unset it once it's set! */
352+
if (!new_value && orig_value)
353+
return -EROFS;
354+
355+
if (new_value)
356+
err = param_set_bool(val, kp);
357+
358+
return err;
359+
}
360+
EXPORT_SYMBOL_GPL(param_set_bool_enable_only);
361+
362+
const struct kernel_param_ops param_ops_bool_enable_only = {
363+
.flags = KERNEL_PARAM_OPS_FL_NOARG,
364+
.set = param_set_bool_enable_only,
365+
.get = param_get_bool,
366+
};
367+
338368
/* This one must be bool. */
339369
int param_set_invbool(const char *val, const struct kernel_param *kp)
340370
{

0 commit comments

Comments
 (0)