Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1617220
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 01/38] Annotate module params that specify hardware parameters (eg. ioport) |
| Date | 2017-04-05 19:30 +0200 |
| Message-ID | <tsWUP-5zn-39@gated-at.bofh.it> (permalink) |
| References | <tsWBr-5sA-3@gated-at.bofh.it> |
| Organization | Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 |
Provided an annotation for module parameters that specify hardware
parameters (such as io ports, iomem addresses, irqs, dma channels, fixed
dma buffers and other types).
This will enable such parameters to be locked down in the core parameter
parser for secure boot support.
I've also included annotations as to what sort of hardware configuration
each module is dealing with for future use. Some of these are
straightforward (ioport, iomem, irq, dma), but there are also:
(1) drivers that switch the semantics of a parameter between ioport and
iomem depending on a second parameter,
(2) drivers that appear to reserve a CPU memory buffer at a fixed address,
(3) other parameters, such as bus types and irq selection bitmasks.
For the moment, the hardware configuration type isn't actually stored,
though its validity is checked.
Signed-off-by: David Howells <dhowells@redhat.com>
---
include/linux/moduleparam.h | 65 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 52666d90ca94..6be1949ebcdf 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -60,9 +60,11 @@ struct kernel_param_ops {
* Flags available for kernel_param
*
* UNSAFE - the parameter is dangerous and setting it will taint the kernel
+ * HWPARAM - Hardware param not permitted in lockdown mode
*/
enum {
- KERNEL_PARAM_FL_UNSAFE = (1 << 0)
+ KERNEL_PARAM_FL_UNSAFE = (1 << 0),
+ KERNEL_PARAM_FL_HWPARAM = (1 << 1),
};
struct kernel_param {
@@ -451,6 +453,67 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
perm, -1, 0); \
__MODULE_PARM_TYPE(name, "array of " #type)
+enum hwparam_type {
+ hwparam_ioport, /* Module parameter configures an I/O port */
+ hwparam_iomem, /* Module parameter configures an I/O mem address */
+ hwparam_ioport_or_iomem, /* Module parameter could be either, depending on other option */
+ hwparam_irq, /* Module parameter configures an I/O port */
+ hwparam_dma, /* Module parameter configures a DMA channel */
+ hwparam_dma_addr, /* Module parameter configures a DMA buffer address */
+ hwparam_other, /* Module parameter configures some other value */
+};
+
+/**
+ * module_param_hw_named - A parameter representing a hw parameters
+ * @name: a valid C identifier which is the parameter name.
+ * @value: the actual lvalue to alter.
+ * @type: the type of the parameter
+ * @hwtype: what the value represents (enum hwparam_type)
+ * @perm: visibility in sysfs.
+ *
+ * Usually it's a good idea to have variable names and user-exposed names the
+ * same, but that's harder if the variable must be non-static or is inside a
+ * structure. This allows exposure under a different name.
+ */
+#define module_param_hw_named(name, value, type, hwtype, perm) \
+ param_check_##type(name, &(value)); \
+ __module_param_call(MODULE_PARAM_PREFIX, name, \
+ ¶m_ops_##type, &value, \
+ perm, -1, \
+ KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
+ __MODULE_PARM_TYPE(name, #type)
+
+#define module_param_hw(name, type, hwtype, perm) \
+ module_param_hw_named(name, name, type, hwtype, perm)
+
+/**
+ * module_param_hw_array - A parameter representing an array of hw parameters
+ * @name: the name of the array variable
+ * @type: the type, as per module_param()
+ * @hwtype: what the value represents (enum hwparam_type)
+ * @nump: optional pointer filled in with the number written
+ * @perm: visibility in sysfs
+ *
+ * Input and output are as comma-separated values. Commas inside values
+ * don't work properly (eg. an array of charp).
+ *
+ * ARRAY_SIZE(@name) is used to determine the number of elements in the
+ * array, so the definition must be visible.
+ */
+#define module_param_hw_array(name, type, hwtype, nump, perm) \
+ param_check_##type(name, &(name)[0]); \
+ static const struct kparam_array __param_arr_##name \
+ = { .max = ARRAY_SIZE(name), .num = nump, \
+ .ops = ¶m_ops_##type, \
+ .elemsize = sizeof(name[0]), .elem = name }; \
+ __module_param_call(MODULE_PARAM_PREFIX, name, \
+ ¶m_array_ops, \
+ .arr = &__param_arr_##name, \
+ perm, -1, \
+ KERNEL_PARAM_FL_HWPARAM | (hwparam_##hwtype & 0)); \
+ __MODULE_PARM_TYPE(name, "array of " #type)
+
+
extern const struct kernel_param_ops param_array_ops;
extern const struct kernel_param_ops param_ops_string;
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 00/38] Annotate hw config module params for future lockdown David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
[PATCH 13/38] Annotate hardware config module parameters in drivers/media/ David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
[PATCH 08/38] Annotate hardware config module parameters in drivers/gpio/ David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
Re: [PATCH 08/38] Annotate hardware config module parameters in drivers/gpio/ Linus Walleij <linus.walleij@linaro.org> - 2017-04-07 12:50 +0200
Re: [PATCH 08/38] Annotate hardware config module parameters in drivers/gpio/ David Howells <dhowells@redhat.com> - 2017-04-07 15:00 +0200
[PATCH 07/38] Annotate hardware config module parameters in drivers/cpufreq/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
Re: [PATCH 07/38] Annotate hardware config module parameters in drivers/cpufreq/ Viresh Kumar <viresh.kumar@linaro.org> - 2017-04-10 12:40 +0200
[PATCH 06/38] Annotate hardware config module parameters in drivers/clocksource/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
[PATCH 02/38] Annotate hardware config module parameters in arch/x86/mm/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
Re: [PATCH 02/38] Annotate hardware config module parameters in arch/x86/mm/ Steven Rostedt <rostedt@goodmis.org> - 2017-04-05 19:40 +0200
[PATCH 03/38] Annotate hardware config module parameters in drivers/char/ipmi/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
[PATCH 05/38] Annotate hardware config module parameters in drivers/char/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
Re: [PATCH 05/38] Annotate hardware config module parameters in drivers/char/ Greg KH <gregkh@linuxfoundation.org> - 2017-04-08 17:30 +0200
[PATCH 04/38] Annotate hardware config module parameters in drivers/char/mwave/ David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
[PATCH 01/38] Annotate module params that specify hardware parameters (eg. ioport) David Howells <dhowells@redhat.com> - 2017-04-05 19:30 +0200
csiph-web