Skip to content

Commit bdf428f

Browse files
committed
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull module update from Rusty Russell: "Nothing major: support for compressing modules, and auto-tainting params. PS. My virtio-next tree is empty: DaveM took the patches I had. There might be a virtio-rng starvation fix, but so far it's a bit voodoo so I will get to that in the next two days or it will wait" * tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: moduleparam: Resolve missing-field-initializer warning kbuild: handle module compression while running 'make modules_install'. modinst: wrap long lines in order to enhance cmd_modules_install modsign: lookup lines ending in .ko in .mod files modpost: simplify file name generation of *.mod.c files modpost: reduce visibility of symbols and constify r/o arrays param: check for tainting before calling set op. drm/i915: taint the kernel if unsafe module parameters are set module: add module_param_unsafe and module_param_named_unsafe module: make it possible to have unsafe, tainting module params module: rename KERNEL_PARAM_FL_NOARG to avoid confusion
2 parents a40a720 + 184c3fc commit bdf428f

11 files changed

Lines changed: 139 additions & 36 deletions

File tree

‎Makefile‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,21 @@ mod_strip_cmd = true
842842
endif # INSTALL_MOD_STRIP
843843
export mod_strip_cmd
844844

845+
# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed
846+
# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP
847+
# or CONFIG_MODULE_COMPRESS_XZ.
848+
849+
mod_compress_cmd = true
850+
ifdef CONFIG_MODULE_COMPRESS
851+
ifdef CONFIG_MODULE_COMPRESS_GZIP
852+
mod_compress_cmd = gzip -n
853+
endif # CONFIG_MODULE_COMPRESS_GZIP
854+
ifdef CONFIG_MODULE_COMPRESS_XZ
855+
mod_compress_cmd = xz
856+
endif # CONFIG_MODULE_COMPRESS_XZ
857+
endif # CONFIG_MODULE_COMPRESS
858+
export mod_compress_cmd
859+
845860
# Select initial ramdisk compression format, default is gzip(1).
846861
# This shall be used by the dracut(8) tool while creating an initramfs image.
847862
#

‎drivers/gpu/drm/i915/i915_params.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ module_param_named(powersave, i915.powersave, int, 0600);
6666
MODULE_PARM_DESC(powersave,
6767
"Enable powersavings, fbc, downclocking, etc. (default: true)");
6868

69-
module_param_named(semaphores, i915.semaphores, int, 0400);
69+
module_param_named_unsafe(semaphores, i915.semaphores, int, 0400);
7070
MODULE_PARM_DESC(semaphores,
7171
"Use semaphores for inter-ring sync "
7272
"(default: -1 (use per-chip defaults))");
7373

74-
module_param_named(enable_rc6, i915.enable_rc6, int, 0400);
74+
module_param_named_unsafe(enable_rc6, i915.enable_rc6, int, 0400);
7575
MODULE_PARM_DESC(enable_rc6,
7676
"Enable power-saving render C-state 6. "
7777
"Different stages can be selected via bitmask values "
7878
"(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
7979
"For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
8080
"default: -1 (use per-chip default)");
8181

82-
module_param_named(enable_fbc, i915.enable_fbc, int, 0600);
82+
module_param_named_unsafe(enable_fbc, i915.enable_fbc, int, 0600);
8383
MODULE_PARM_DESC(enable_fbc,
8484
"Enable frame buffer compression for power savings "
8585
"(default: -1 (use per-chip default))");
@@ -113,7 +113,7 @@ MODULE_PARM_DESC(enable_hangcheck,
113113
"WARNING: Disabling this can cause system wide hangs. "
114114
"(default: true)");
115115

116-
module_param_named(enable_ppgtt, i915.enable_ppgtt, int, 0400);
116+
module_param_named_unsafe(enable_ppgtt, i915.enable_ppgtt, int, 0400);
117117
MODULE_PARM_DESC(enable_ppgtt,
118118
"Override PPGTT usage. "
119119
"(-1=auto [default], 0=disabled, 1=aliasing, 2=full)");

‎drivers/tty/serial/8250/8250_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,7 @@ static void __used s8250_options(void)
35873587
#ifdef CONFIG_SERIAL_8250_RSA
35883588
__module_param_call(MODULE_PARAM_PREFIX, probe_rsa,
35893589
&param_array_ops, .arr = &__param_arr_probe_rsa,
3590-
0444, -1);
3590+
0444, -1, 0);
35913591
#endif
35923592
}
35933593
#else

‎include/linux/moduleparam.h‎

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct kernel_param;
4242
* NOARG - the parameter allows for no argument (foo instead of foo=1)
4343
*/
4444
enum {
45-
KERNEL_PARAM_FL_NOARG = (1 << 0)
45+
KERNEL_PARAM_OPS_FL_NOARG = (1 << 0)
4646
};
4747

4848
struct kernel_param_ops {
@@ -56,11 +56,21 @@ struct kernel_param_ops {
5656
void (*free)(void *arg);
5757
};
5858

59+
/*
60+
* Flags available for kernel_param
61+
*
62+
* UNSAFE - the parameter is dangerous and setting it will taint the kernel
63+
*/
64+
enum {
65+
KERNEL_PARAM_FL_UNSAFE = (1 << 0)
66+
};
67+
5968
struct kernel_param {
6069
const char *name;
6170
const struct kernel_param_ops *ops;
6271
u16 perm;
63-
s16 level;
72+
s8 level;
73+
u8 flags;
6474
union {
6575
void *arg;
6676
const struct kparam_string *str;
@@ -112,6 +122,12 @@ struct kparam_array
112122
#define module_param(name, type, perm) \
113123
module_param_named(name, name, type, perm)
114124

125+
/**
126+
* module_param_unsafe - same as module_param but taints kernel
127+
*/
128+
#define module_param_unsafe(name, type, perm) \
129+
module_param_named_unsafe(name, name, type, perm)
130+
115131
/**
116132
* module_param_named - typesafe helper for a renamed module/cmdline parameter
117133
* @name: a valid C identifier which is the parameter name.
@@ -128,6 +144,14 @@ struct kparam_array
128144
module_param_cb(name, &param_ops_##type, &value, perm); \
129145
__MODULE_PARM_TYPE(name, #type)
130146

147+
/**
148+
* module_param_named_unsafe - same as module_param_named but taints kernel
149+
*/
150+
#define module_param_named_unsafe(name, value, type, perm) \
151+
param_check_##type(name, &(value)); \
152+
module_param_cb_unsafe(name, &param_ops_##type, &value, perm); \
153+
__MODULE_PARM_TYPE(name, #type)
154+
131155
/**
132156
* module_param_cb - general callback for a module/cmdline parameter
133157
* @name: a valid C identifier which is the parameter name.
@@ -137,7 +161,11 @@ struct kparam_array
137161
* The ops can have NULL set or get functions.
138162
*/
139163
#define module_param_cb(name, ops, arg, perm) \
140-
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1)
164+
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, 0)
165+
166+
#define module_param_cb_unsafe(name, ops, arg, perm) \
167+
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, -1, \
168+
KERNEL_PARAM_FL_UNSAFE)
141169

142170
/**
143171
* <level>_param_cb - general callback for a module/cmdline parameter
@@ -149,7 +177,7 @@ struct kparam_array
149177
* The ops can have NULL set or get functions.
150178
*/
151179
#define __level_param_cb(name, ops, arg, perm, level) \
152-
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level)
180+
__module_param_call(MODULE_PARAM_PREFIX, name, ops, arg, perm, level, 0)
153181

154182
#define core_param_cb(name, ops, arg, perm) \
155183
__level_param_cb(name, ops, arg, perm, 1)
@@ -184,22 +212,22 @@ struct kparam_array
184212

185213
/* This is the fundamental function for registering boot/module
186214
parameters. */
187-
#define __module_param_call(prefix, name, ops, arg, perm, level) \
215+
#define __module_param_call(prefix, name, ops, arg, perm, level, flags) \
188216
/* Default value instead of permissions? */ \
189217
static const char __param_str_##name[] = prefix #name; \
190218
static struct kernel_param __moduleparam_const __param_##name \
191219
__used \
192220
__attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
193221
= { __param_str_##name, ops, VERIFY_OCTAL_PERMISSIONS(perm), \
194-
level, { arg } }
222+
level, flags, { arg } }
195223

196224
/* Obsolete - use module_param_cb() */
197225
#define module_param_call(name, set, get, arg, perm) \
198226
static struct kernel_param_ops __param_ops_##name = \
199-
{ 0, (void *)set, (void *)get }; \
227+
{ .flags = 0, (void *)set, (void *)get }; \
200228
__module_param_call(MODULE_PARAM_PREFIX, \
201229
name, &__param_ops_##name, arg, \
202-
(perm) + sizeof(__check_old_set_param(set))*0, -1)
230+
(perm) + sizeof(__check_old_set_param(set))*0, -1, 0)
203231

204232
/* We don't get oldget: it's often a new-style param_get_uint, etc. */
205233
static inline int
@@ -279,7 +307,7 @@ static inline void __kernel_param_unlock(void)
279307
*/
280308
#define core_param(name, var, type, perm) \
281309
param_check_##type(name, &(var)); \
282-
__module_param_call("", name, &param_ops_##type, &var, perm, -1)
310+
__module_param_call("", name, &param_ops_##type, &var, perm, -1, 0)
283311
#endif /* !MODULE */
284312

285313
/**
@@ -297,7 +325,7 @@ static inline void __kernel_param_unlock(void)
297325
= { len, string }; \
298326
__module_param_call(MODULE_PARAM_PREFIX, name, \
299327
&param_ops_string, \
300-
.str = &__param_string_##name, perm, -1); \
328+
.str = &__param_string_##name, perm, -1, 0);\
301329
__MODULE_PARM_TYPE(name, "string")
302330

303331
/**
@@ -444,7 +472,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
444472
__module_param_call(MODULE_PARAM_PREFIX, name, \
445473
&param_array_ops, \
446474
.arr = &__param_arr_##name, \
447-
perm, -1); \
475+
perm, -1, 0); \
448476
__MODULE_PARM_TYPE(name, "array of " #type)
449477

450478
extern struct kernel_param_ops param_array_ops;

‎init/Kconfig‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,49 @@ config MODULE_SIG_HASH
19191919
default "sha384" if MODULE_SIG_SHA384
19201920
default "sha512" if MODULE_SIG_SHA512
19211921

1922+
config MODULE_COMPRESS
1923+
bool "Compress modules on installation"
1924+
depends on MODULES
1925+
help
1926+
This option compresses the kernel modules when 'make
1927+
modules_install' is run.
1928+
1929+
The modules will be compressed either using gzip or xz depend on the
1930+
choice made in "Compression algorithm".
1931+
1932+
module-init-tools has support for gzip format while kmod handle gzip
1933+
and xz compressed modules.
1934+
1935+
When a kernel module is installed from outside of the main kernel
1936+
source and uses the Kbuild system for installing modules then that
1937+
kernel module will also be compressed when it is installed.
1938+
1939+
This option provides little benefit when the modules are to be used inside
1940+
an initrd or initramfs, it generally is more efficient to compress the whole
1941+
initrd or initramfs instead.
1942+
1943+
This is fully compatible with signed modules while the signed module is
1944+
compressed. module-init-tools or kmod handles decompression and provide to
1945+
other layer the uncompressed but signed payload.
1946+
1947+
choice
1948+
prompt "Compression algorithm"
1949+
depends on MODULE_COMPRESS
1950+
default MODULE_COMPRESS_GZIP
1951+
help
1952+
This determines which sort of compression will be used during
1953+
'make modules_install'.
1954+
1955+
GZIP (default) and XZ are supported.
1956+
1957+
config MODULE_COMPRESS_GZIP
1958+
bool "GZIP"
1959+
1960+
config MODULE_COMPRESS_XZ
1961+
bool "XZ"
1962+
1963+
endchoice
1964+
19221965
endif # MODULES
19231966

19241967
config INIT_ALL_POSSIBLE

‎kernel/module.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int param_set_bool_enable_only(const char *val,
135135
}
136136

137137
static const struct kernel_param_ops param_ops_bool_enable_only = {
138-
.flags = KERNEL_PARAM_FL_NOARG,
138+
.flags = KERNEL_PARAM_OPS_FL_NOARG,
139139
.set = param_set_bool_enable_only,
140140
.get = param_get_bool,
141141
};

‎kernel/params.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ bool parameq(const char *a, const char *b)
8383
return parameqn(a, b, strlen(a)+1);
8484
}
8585

86+
static void param_check_unsafe(const struct kernel_param *kp)
87+
{
88+
if (kp->flags & KERNEL_PARAM_FL_UNSAFE) {
89+
pr_warn("Setting dangerous option %s - tainting kernel\n",
90+
kp->name);
91+
add_taint(TAINT_USER, LOCKDEP_STILL_OK);
92+
}
93+
}
94+
8695
static int parse_one(char *param,
8796
char *val,
8897
const char *doing,
@@ -104,11 +113,12 @@ static int parse_one(char *param,
104113
return 0;
105114
/* No one handled NULL, so do it here. */
106115
if (!val &&
107-
!(params[i].ops->flags & KERNEL_PARAM_FL_NOARG))
116+
!(params[i].ops->flags & KERNEL_PARAM_OPS_FL_NOARG))
108117
return -EINVAL;
109118
pr_debug("handling %s with %p\n", param,
110119
params[i].ops->set);
111120
mutex_lock(&param_lock);
121+
param_check_unsafe(&params[i]);
112122
err = params[i].ops->set(val, &params[i]);
113123
mutex_unlock(&param_lock);
114124
return err;
@@ -318,7 +328,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp)
318328
EXPORT_SYMBOL(param_get_bool);
319329

320330
struct kernel_param_ops param_ops_bool = {
321-
.flags = KERNEL_PARAM_FL_NOARG,
331+
.flags = KERNEL_PARAM_OPS_FL_NOARG,
322332
.set = param_set_bool,
323333
.get = param_get_bool,
324334
};
@@ -369,7 +379,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp)
369379
EXPORT_SYMBOL(param_set_bint);
370380

371381
struct kernel_param_ops param_ops_bint = {
372-
.flags = KERNEL_PARAM_FL_NOARG,
382+
.flags = KERNEL_PARAM_OPS_FL_NOARG,
373383
.set = param_set_bint,
374384
.get = param_get_int,
375385
};
@@ -552,6 +562,7 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
552562
return -EPERM;
553563

554564
mutex_lock(&param_lock);
565+
param_check_unsafe(attribute->param);
555566
err = attribute->param->ops->set(buf, attribute->param);
556567
mutex_unlock(&param_lock);
557568
if (!err)

‎scripts/Makefile.modinst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ __modinst: $(modules)
1818

1919
# Don't stop modules_install if we can't sign external modules.
2020
quiet_cmd_modules_install = INSTALL $@
21-
cmd_modules_install = mkdir -p $(2); cp $@ $(2) ; $(mod_strip_cmd) $(2)/$(notdir $@) ; $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD))
21+
cmd_modules_install = \
22+
mkdir -p $(2) ; \
23+
cp $@ $(2) ; \
24+
$(mod_strip_cmd) $(2)/$(notdir $@) ; \
25+
$(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \
26+
$(mod_compress_cmd) $(2)/$(notdir $@)
2227

2328
# Modules built outside the kernel source tree go into extra by default
2429
INSTALL_MOD_DIR ?= extra

‎scripts/Makefile.modsign‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __modsign:
77

88
include scripts/Kbuild.include
99

10-
__modules := $(sort $(shell grep -h '\.ko' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
10+
__modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
1111
modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))
1212

1313
PHONY += $(modules)

0 commit comments

Comments
 (0)