dmi-id: Add parameter to relax sysfs permissions
PATCH 1/1 dmi-id: Add parameter to relax sysfs permissions
Every few years I find myself in a discussion that goes like:
user: I hate using dmidecode to read vendor infos, it needs root!
me: Just use /sys/class/dmi/id/
user: wow! Neat!
*later*
user: But, I can't read from product_serial!
me: *grrrr*
For systems where no confidential information is stored in the DMI IDs allow setting the kernel module parameter dmi_id.relaxed_perms to y. It will make sure the every sysfs attribute has at least 0444 permissions.
Signed-off-by Richard Weinberger <[email protected]>
--- drivers/firmware/dmi-id.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/firmware/dmi-id.c +12 -5
@@ -12,6 +12,8 @@#include <linux/device.h> #include <linux/slab.h> +static bool relaxed_perms; +struct dmi_device_attribute {struct device_attribute dev_attr;int field;
@@ -183,10 +185,14 @@ static struct class dmi_class = {static struct device *dmi_dev;/* Initialization */ - -#define ADD_DMI_ATTR (_name, _field) \ - if (dmi_get_system_info(_field)) \ - sys_dmi_attributes[i++] = &sys_dmi_##_name##_attr.dev_attr.attr; +#define ADD_DMI_ATTR (_name, _field) \ + ({ \ + if (dmi_get_system_info(_field)) { \ + if (relaxed_perms) \ + sys_dmi_##_name##_attr.dev_attr.attr.mode |= 0444; \ + sys_dmi_attributes[i++] = &sys_dmi_##_name##_attr.dev_attr.attr;\ + } \ + })/* In a separate function to keep gcc 3.2 happy - do NOT merge this in dmi_id_init! */
@@ -260,5 +266,6 @@ static int __init dmi_id_init(void)return ret; } - +module_param (relaxed_perms, bool,0400 ); +MODULE_PARM_DESC (relaxed_perms,"Allow everyone read access to all IDs" );arch_initcall (dmi_id_init);
Signature · 1 line
2.51.0