platform/x86: dell-smbios: Fix call filtering, lifetime and error handling
Subsystems (3)
v2 cover platform/x86: dell-smbios: Fix call filtering, lifetime and error handling
Fixes for the dell-smbios dispatcher and its SMM and WMI backends.
Patch 1 is security relevant: /dev/wmi/dell-smbios is mode 0444, and the WSMT tokens are whitelisted without a capability for both reads and writes, so any local user can write to the WSMT token location and change the BIOS setting. Patch 2 closes the related gap where tokens sharing a location were filtered by whichever came first. Both were found by code review; I have no WSMT-capable machine to reproduce them on.
Patches 3-11 fix a use-after-free when the dell-smbios.1 device is unbound, an empty token sysfs group, use of an unpopulated SMI port, unchecked SMI and registration errors, and a WMI buffer size underflow.
Patches 1-11 carry Fixes: tags and come first so they can be applied on their own. Patches 12-16 are hardening and cleanups for the next merge window: they stop unprivileged users from flooding the log, restrict the token sysfs files by mode, and tidy up the rest.
These patches were developed with the help of an AI coding assistant (Claude Opus 5.5): it reviewed the drivers, found the issues and drafted the fixes and changelogs. I reviewed every change and I am responsible for them.
All patches build cleanly with W=1.
Tested on a Dell Precision M4800 running v7.2.15, using the equivalent backports built as out-of-tree modules:
- token sysfs files are 0400; unprivileged reads fail, root reads work
- unprivileged non-whitelisted token reads through /dev/wmi/dell-smbios are rejected, and 503 rejected calls logged 10 lines; root calls work
- dell-laptop, dell-pc and dell-wmi work on top, and three unload/reload cycles of the whole stack are clean
The WSMT write fix (patch 1) could not be exercised: this machine has no WSMT tokens. Its seven 0xDA structures all report SMI port 0xb2.
Changes in v2:
- Patch 3: don't leak token_entries when kasprintf() or sysfs_create_group() fails; fall through to its kfree() and return
ret from a single exit
- v1: https://lore.kernel.org/platform-driver-x86/[email protected]/
Rosen Penev (16):
platform/x86: dell-smbios: Only allow unprivileged reads of
whitelisted tokens
platform/x86: dell-smbios: Filter every token at the requested
location
platform/x86: dell-smbios: Return the real error from
build_tokens_sysfs()
platform/x86: dell-smbios: Skip 0xDA structures without tokens platform/x86: dell-smbios: Use dev_driver_string() in debug messages platform/x86: dell-smbios-smm: Use the first 0xDA structure with an
SMI port
platform/x86: dell-smbios-smm: Propagate SMI request errors platform/x86: dell-smbios-smm: Clear platform_device when it is
released
platform/x86: dell-smbios-wmi: Don't unregister a driver that failed
to register
platform/x86: dell-smbios-wmi: Reject buffer sizes too small for a
call
platform/x86: dell-smbios: Don't tie dispatcher entries to the device
driver
platform/x86: dell-smbios-smm: Set the WSMT test call after clearing
the buffer
platform/x86: dell-smbios-wmi: Don't let unprivileged users flood the
log
platform/x86: dell-smbios: Suppress bind attributes of the platform
driver
platform/x86: dell-smbios: Restrict token sysfs files with their mode platform/x86: dell-smbios: Drop smbios_mutex from module exit
drivers/platform/x86/dell/dell-smbios-base.c | 162 +++++++++++-------- drivers/platform/x86/dell/dell-smbios-smm.c | 24 ++- drivers/platform/x86/dell/dell-smbios-wmi.c | 23 ++- 3 files changed, 136 insertions(+), 73 deletions(-)
base-commit: 2800868f63227c8237d70c41e70d441c919620d6
Signature · 1 line
2.56.1
PATCH v2 1/16 platform/x86: dell-smbios: Only allow unprivileged reads of whitelisted tokens
The WSMT tokens are whitelisted without a capability so that userspace can find out whether WMI has to be used instead of SMM. The whitelist check does not look at the call class though, so the entry applies to CLASS_TOKEN_WRITE as well as CLASS_TOKEN_READ.
/dev/wmi/dell-smbios is mode 0444 and the ioctl only needs a read-only open, so any local user can write an arbitrary value to the WSMT token location and change the BIOS setting.
Only let capability-free whitelist entries match token reads. Writes fall through to the call whitelist, which requires CAP_SYS_ADMIN.
--- drivers/platform/x86/dell/dell-smbios-base.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/platform/x86/dell/dell-smbios-base.c +4 -0
@@ -255,6 +255,10 @@ int dell_smbios_call_filter(struct device *d,if (t < token_whitelist[i].min || t > token_whitelist[i].max)continue ; +/* tokens needing no capability may only be read */ +if (!token_whitelist[i].need_capability && + buffer->cmd_class !=CLASS_TOKEN_READ ) +continue ;if (!token_whitelist[i].need_capability ||capable (token_whitelist[i].need_capability)) {dev_dbg (d,"whitelisted token: %x\n" , t);
Signature · 1 line
2.56.1
PATCH v2 2/16 platform/x86: dell-smbios: Filter every token at the requested location
In reply to Rosen PenevToken calls identify the token by its location, and the filter maps the location back to a token ID by taking the first token stored there. Several tokens commonly share a location (enable/disable pairs, for example), so which ID gets checked against the blacklist and whitelist depends on the order of the SMBIOS tables. A blacklisted token can be reached through the location of a token that comes before it.
The lookup also stops at the first match even if that entry was zeroed by zero_duplicates(), so an existing location can be reported as missing.
Move the token handling into a helper that walks every token at the location, skipping zeroed duplicates. The call is rejected if any of them is blacklisted, and only accepted by the token whitelist if all of them are whitelisted.
--- drivers/platform/x86/dell/dell-smbios-base.c | 133 ++++++++++++------- 1 file changed, 82 insertions(+), 51 deletions(-)
drivers/platform/x86/dell/dell-smbios-base.c +82 -51
@@ -182,10 +182,86 @@ void dell_smbios_unregister_device(struct device *d) }EXPORT_SYMBOL_GPL (dell_smbios_unregister_device); +static bool token_in_range (const struct token_range *range,u16 t) +{ +if (!range->min || !range->max) +return false; +return t >= range->min && t <= range->max; +} + +static bool token_is_whitelisted (struct device *d, +struct calling_interface_buffer *buffer,u16 t) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (token_whitelist); i++) { +if (!token_in_range (&token_whitelist[i], t)) +continue ; +/* tokens needing no capability may only be read */ +if (!token_whitelist[i].need_capability) { +if (buffer->cmd_class ==CLASS_TOKEN_READ ) +return true; +continue ; + } +if (capable (token_whitelist[i].need_capability)) +return true; + } + +dev_dbg (d,"token %x not whitelisted for %u/%u\n" , t, + buffer->cmd_class, buffer->cmd_select); +return false; +} + +/* +* Several tokens can share a location (e.g. enable/disable pairs), so every +* token at the requested location has to pass the filter. +* +* Returns 0 if the call is whitelisted, 1 if it should be checked against +* the call whitelist, or a negative error code if it is rejected. +*/ +static int dell_smbios_token_filter (struct device *d, +struct calling_interface_buffer *buffer) +{ +bool whitelisted = true; +bool found = false; +u16 t; +int i, j; + +if (!da_tokens) { +dev_dbg (d,"no token support on this system\n" ); +return -EINVAL ; + } + +for (i =0 ; i < da_num_tokens; i++) { + t = da_tokens[i].tokenID; +if (!t || da_tokens[i].location != buffer->input[0 ]) +continue ; + found = true; + +for (j =0 ; j <ARRAY_SIZE (token_blacklist); j++) { +if (token_in_range (&token_blacklist[j], t)) { +dev_dbg (d,"blacklisted token: %x\n" , t); +return -EINVAL ; + } + } + +if (!token_is_whitelisted (d, buffer, t)) + whitelisted = false; + } + +if (!found) { +dev_dbg (d,"token at location %04x doesn't exist\n" , + buffer->input[0 ]); +return -EINVAL ; + } + +return whitelisted ?0 :1 ; +} +int dell_smbios_call_filter (struct device *d,struct calling_interface_buffer *buffer) { -u16 t =0 ; +int ret;int i;/* can't make calls over 30 */
@@ -213,60 +289,15 @@ int dell_smbios_call_filter(struct device *d,return -EINVAL ; } -/* if a token call, find token ID */ - +/* if a token call, check the token(s) at the requested location */ if ((buffer->cmd_class ==CLASS_TOKEN_READ || buffer->cmd_class ==CLASS_TOKEN_WRITE ) && buffer->cmd_select <3 ) { -/* tokens enabled ? */ -if (!da_tokens) { -dev_dbg (d,"no token support on this system\n" ); -return -EINVAL ; - } - -/* find the matching token ID */ -for (i =0 ; i < da_num_tokens; i++) { -if (da_tokens[i].location != buffer->input[0 ]) -continue ; - t = da_tokens[i].tokenID; -break ; - } - -/* token call; but token didn't exist */ -if (!t) { -dev_dbg (d,"token at location %04x doesn't exist\n" , - buffer->input[0 ]); -return -EINVAL ; - } - -/* match against token blacklist */ -for (i =0 ; i <ARRAY_SIZE (token_blacklist); i++) { -if (!token_blacklist[i].min || !token_blacklist[i].max) -continue ; -if (t >= token_blacklist[i].min && - t <= token_blacklist[i].max) -return -EINVAL ; - } - -/* match against token whitelist */ -for (i =0 ; i <ARRAY_SIZE (token_whitelist); i++) { -if (!token_whitelist[i].min || !token_whitelist[i].max) -continue ; -if (t < token_whitelist[i].min || - t > token_whitelist[i].max) -continue ; -/* tokens needing no capability may only be read */ -if (!token_whitelist[i].need_capability && - buffer->cmd_class !=CLASS_TOKEN_READ ) -continue ; -if (!token_whitelist[i].need_capability || -capable (token_whitelist[i].need_capability)) { -dev_dbg (d,"whitelisted token: %x\n" , t); -return 0 ; - } - - } + ret =dell_smbios_token_filter (d, buffer); +if (ret <=0 ) +return ret; } +/* match against call whitelist */ for (i =0 ; i <ARRAY_SIZE (call_whitelist); i++) {if (buffer->cmd_class != call_whitelist[i].cmd_class)
Signature · 1 line
2.56.1
PATCH v2 3/16 platform/x86: dell-smbios: Return the real error from build_tokens_sysfs()
In reply to Rosen Penevbuild_tokens_sysfs() returns -ENOMEM on every failure, including when sysfs_create_group() fails for another reason. Pass that error through.
---
v2:
- Don't leak token_entries on the out_unwind paths (fall through to out_allocate_attrs and return ret)
drivers/platform/x86/dell/dell-smbios-base.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/x86/dell/dell-smbios-base.c +7 -3
@@ -536,8 +536,10 @@ static int build_tokens_sysfs(struct platform_device *dev)/* need to store both location and value + terminator*/ token_attrs =kzalloc_objs (*token_attrs, (2 * da_num_tokens) +1 ); -if (!token_attrs) +if (!token_attrs) { + ret = -ENOMEM ; goto out_allocate_attrs; + }for (i =0 , j =0 ; i < da_num_tokens; i++) {/* skip empty */
@@ -576,10 +578,12 @@ static int build_tokens_sysfs(struct platform_device *dev) ret =sysfs_create_group (&dev->dev.kobj, &smbios_attribute_group);if (ret) - goto out_unwind_strings; + goto out_unwind;return 0 ; out_unwind_strings: + ret = -ENOMEM ; +out_unwind:while (i--) {kfree (token_entries[i].location_attr.attr.name);kfree (token_entries[i].value_attr.attr.name);
@@ -588,7 +592,7 @@ static int build_tokens_sysfs(struct platform_device *dev) out_allocate_attrs:kfree (token_entries); -return -ENOMEM ; +return ret; }static void free_group (struct platform_device *pdev)
Signature · 1 line
2.56.1
PATCH v2 4/16 platform/x86: dell-smbios: Skip 0xDA structures without tokens
In reply to Rosen PenevWhen a 0xDA structure only holds the terminator and no tokens have been collected yet, parse_da_table() calls krealloc(NULL, 0). That returns ZERO_SIZE_PTR, so da_tokens looks valid even though there are no tokens, and an empty "tokens" sysfs group is created.
Return before reallocating when the structure has no tokens.
--- drivers/platform/x86/dell/dell-smbios-base.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/x86/dell/dell-smbios-base.c +3 -0
@@ -443,6 +443,9 @@ static void __init parse_da_table(const struct dmi_header *dm) da_supported_commands = table->supportedCmds; +if (tokens <=0 ) +return ; + new_da_tokens =krealloc (da_tokens, (da_num_tokens + tokens) *sizeof (struct calling_interface_token ),GFP_KERNEL );
Signature · 1 line
2.56.1
PATCH v2 5/16 platform/x86: dell-smbios: Use dev_driver_string() in debug messages
In reply to Rosen Penevdell_smbios_register_device() and dell_smbios_unregister_device() dereference d->driver for their debug messages. The device is not guaranteed to be bound to a driver, so use dev_driver_string(), which handles that case.
--- drivers/platform/x86/dell/dell-smbios-base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-smbios-base.c +2 -2
@@ -160,7 +160,7 @@ int dell_smbios_register_device(struct device *d, int priority, smbios_callback_mutex_lock (&smbios_mutex);list_add_tail (&priv->list, &smbios_device_list);mutex_unlock (&smbios_mutex); -dev_dbg (d,"Added device: %s\n" , d->driver->name); +dev_dbg (d,"Added device: %s\n" ,dev_driver_string (d));return 0 ; }EXPORT_SYMBOL_GPL (dell_smbios_register_device);
@@ -178,7 +178,7 @@ void dell_smbios_unregister_device(struct device *d) } }mutex_unlock (&smbios_mutex); -dev_dbg (d,"Remove device: %s\n" , d->driver->name); +dev_dbg (d,"Remove device: %s\n" ,dev_driver_string (d)); }EXPORT_SYMBOL_GPL (dell_smbios_unregister_device);
Signature · 1 line
2.56.1
PATCH v2 6/16 platform/x86: dell-smbios-smm: Use the first 0xDA structure with an SMI port
In reply to Rosen Penevparse_da_table() runs for every SMBIOS 0xDA structure and overwrites the SMI command port and code each time, so the last structure wins. Systems can expose several 0xDA structures, and they are not all filled in the same way: on a Dell Precision M4800 all seven report port 0xb2, but the last one reports zero for its supported commands.
If the last structure has no SMI port, every SMM call writes the command code to I/O port 0, which on x86 is the legacy DMA controller.
Take the port and code from the first structure that has a non-zero port, and fail to initialize the SMM backend if none has one.
--- drivers/platform/x86/dell/dell-smbios-smm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/platform/x86/dell/dell-smbios-smm.c +12 -0
@@ -36,6 +36,13 @@ static void parse_da_table(const struct dmi_header *dm)if (dm->length <17 )return ; +/* +* Systems may expose several 0xDA structures and not all of them fill +* in the SMI port, so use the first one that does. +*/ +if (da_command_address || !table->cmdIOAddress) +return ; + da_command_address = table->cmdIOAddress; da_command_code = table->cmdIOCode; }
@@ -108,6 +115,11 @@ int init_dell_smbios_smm(void) buffer = (void *)smi_buf.virt;dmi_walk (find_cmd_address,NULL ); +if (!da_command_address) { +pr_debug ("No SMI command address found\n" ); + ret = -ENODEV ; + goto fail_wsmt; + }if (test_wsmt_enabled (&platform_device->dev)) {pr_debug ("Disabling due to WSMT enabled\n" );
Signature · 1 line
2.56.1
PATCH v2 7/16 platform/x86: dell-smbios-smm: Propagate SMI request errors
In reply to Rosen Penevdell_smbios_smm_call() ignores the return value of dcdbas_smi_request() and always returns 0. If the SMI was never raised, the caller gets its own input buffer back and treats output[0] as the firmware's answer.
Return the error, and only copy the buffer back when the SMI ran.
--- drivers/platform/x86/dell/dell-smbios-smm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/platform/x86/dell/dell-smbios-smm.c +5 -3
@@ -60,6 +60,7 @@ static int dell_smbios_smm_call(struct device *dev, struct calling_interface_buf {struct smi_cmd command;size_t size; +int ret; size =sizeof (struct calling_interface_buffer ); command.magic =SMI_CMD_MAGIC ;
@@ -70,10 +71,11 @@ static int dell_smbios_smm_call(struct device *dev, struct calling_interface_bufmutex_lock (&smm_mutex);memcpy (buffer, input, size); -dcdbas_smi_request (&command); -memcpy (input, buffer, size); + ret =dcdbas_smi_request (&command); +if (!ret) +memcpy (input, buffer, size);mutex_unlock (&smm_mutex); -return 0 ; +return ret; }/* When enabled this indicates that SMM won't work */
Signature · 1 line
2.56.1
PATCH v2 8/16 platform/x86: dell-smbios-smm: Clear platform_device when it is released
In reply to Rosen PenevIf platform_device_add() or dell_smbios_register_device() fails, init_dell_smbios_smm() drops the platform device but leaves the static pointer set. dell_smbios_exit() calls exit_dell_smbios_smm() unconditionally, so when the WMI backend loaded and SMM did not, module unload unregisters the freed device and frees smi_buf a second time.
Clear the pointer whenever the device is released.
--- drivers/platform/x86/dell/dell-smbios-smm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/platform/x86/dell/dell-smbios-smm.c +2 -0
@@ -150,6 +150,7 @@ int init_dell_smbios_smm(void) fail_platform_device_add:platform_device_put (platform_device); + platform_device =NULL ; fail_wsmt: fail_platform_device_alloc:
@@ -162,6 +163,7 @@ void exit_dell_smbios_smm(void)if (platform_device) {dell_smbios_unregister_device (&platform_device->dev);platform_device_unregister (platform_device); + platform_device =NULL ;dcdbas_smi_free (&smi_buf); } }
Signature · 1 line
2.56.1
PATCH v2 9/16 platform/x86: dell-smbios-wmi: Don't unregister a driver that failed to register
In reply to Rosen Penevexit_dell_smbios_wmi() only checks wmi_supported, which stays set when wmi_driver_register() fails. dell_smbios_exit() calls it unconditionally, so if the SMM backend loaded and the WMI one did not, module unload unregisters a driver that was never registered.
Clear wmi_supported when registration fails.
--- drivers/platform/x86/dell/dell-smbios-wmi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/platform/x86/dell/dell-smbios-wmi.c +7 -1
@@ -308,12 +308,18 @@ static struct wmi_driver dell_smbios_wmi_driver = {int init_dell_smbios_wmi (void ) { +int ret; +dmi_walk (find_b1,NULL );if (!wmi_supported)return -ENODEV ; -return wmi_driver_register (&dell_smbios_wmi_driver); + ret =wmi_driver_register (&dell_smbios_wmi_driver); +if (ret) + wmi_supported =0 ; + +return ret; }void exit_dell_smbios_wmi (void )
Signature · 1 line
2.56.1
PATCH v2 10/16 platform/x86: dell-smbios-wmi: Reject buffer sizes too small for a call
In reply to Rosen PenevThe WMI buffer size comes from the firmware descriptor and is not checked. dell_smbios_wmi_call() clears the part of the buffer past the standard call structure with
difference = priv->req_buf_size - sizeof(u64) - size;
which wraps around if the firmware reports less than sizeof(struct calling_interface_buffer), and the following memset() runs far past the buffer.
Refuse to probe if the buffer cannot hold a call.
--- drivers/platform/x86/dell/dell-smbios-wmi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/platform/x86/dell/dell-smbios-wmi.c +5 -0
@@ -233,6 +233,11 @@ static int dell_smbios_wmi_probe(struct wmi_device *wdev, const void *context)if (!dell_wmi_get_size (&buffer_size))return -EPROBE_DEFER ; +if (buffer_size <sizeof (struct calling_interface_buffer )) { +dev_err (&wdev->dev,"WMI buffer size %u is too small\n" , buffer_size); +return -EINVAL ; + } + priv->req_buf_size = buffer_size;/* some SMBIOS calls fail unless BIOS contains hotfix */
Signature · 1 line
2.56.1
PATCH v2 11/16 platform/x86: dell-smbios: Don't tie dispatcher entries to the device driver
In reply to Rosen Penevdell_smbios_register_device() allocates the dispatcher entry with devm_kzalloc() on the registered device, so it is freed when that device is unbound from its driver, whether or not it was unregistered.
The SMM backend registers the dell-smbios.1 platform device, which is bound to the base module's platform driver and never unregisters on unbind. Writing dell-smbios.1 to the driver's unbind file frees the entry while it is still on smbios_device_list, and the next dell_smbios_call() from dell-laptop, dell-pc or dell-wmi walks freed memory.
Allocate the entry with kzalloc() and free it in dell_smbios_unregister_device(), so it lives exactly as long as it is on the list.
--- drivers/platform/x86/dell/dell-smbios-base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/dell/dell-smbios-base.c +2 -1
@@ -150,7 +150,7 @@ int dell_smbios_register_device(struct device *d, int priority, smbios_callback_ {struct smbios_device *priv; - priv = devm_kzalloc_obj(d, struct smbios_device); + priv =kzalloc_obj (*priv);if (!priv)return -ENOMEM ;get_device (d);
@@ -174,6 +174,7 @@ void dell_smbios_unregister_device(struct device *d)if (priv->device == d) {list_del (&priv->list);put_device (d); +kfree (priv);break ; } }
Signature · 1 line
2.56.1
PATCH v2 12/16 platform/x86: dell-smbios-smm: Set the WSMT test call after clearing the buffer
In reply to Rosen Penevtest_wsmt_enabled() sets the class and select and then clears the whole buffer. It only works because CLASS_TOKEN_READ and SELECT_TOKEN_STD are both 0. Clear the buffer first.
No functional change.
--- drivers/platform/x86/dell/dell-smbios-smm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-smbios-smm.c +1 -1
@@ -92,9 +92,9 @@ static bool test_wsmt_enabled(struct device *dev)* - If WSMT disabled it will be overwritten by SMM * - If WSMT enabled then dummy value will remain */ +memset (buffer,0 ,sizeof (struct calling_interface_buffer )); buffer->cmd_class =CLASS_TOKEN_READ ; buffer->cmd_select =SELECT_TOKEN_STD ; -memset (buffer,0 ,sizeof (struct calling_interface_buffer )); buffer->input[0 ] = wsmt->location; buffer->output[0 ] =99 ;dell_smbios_smm_call (dev, buffer);
Signature · 1 line
2.56.1
PATCH v2 13/16 platform/x86: dell-smbios-wmi: Don't let unprivileged users flood the log
In reply to Rosen Penev/dev/wmi/dell-smbios can be opened by any user, and the ioctl logs an error for an oversized buffer and for every call rejected by the filter. A local user can flood the kernel log by repeating either.
An oversized buffer is handled fine, so log it at debug level, and ratelimit the rejected call message.
--- drivers/platform/x86/dell/dell-smbios-wmi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/platform/x86/dell/dell-smbios-wmi.c +5 -5
@@ -119,17 +119,17 @@ static long dell_smbios_wmi_do_ioctl(struct wmi_smbios_priv *priv,/* if it's too big, warn, driver will only use what is needed */ if (priv->buf->length > priv->req_buf_size) -dev_err (&priv->wdev->dev,"Buffer %llu is bigger than required %llu\n" , +dev_dbg (&priv->wdev->dev,"Buffer %llu is bigger than required %llu\n" , priv->buf->length, priv->req_buf_size);if (copy_from_user (priv->buf, arg, priv->req_buf_size))return -EFAULT ;if (dell_smbios_call_filter (&priv->wdev->dev, &priv->buf->std)) { -dev_err (&priv->wdev->dev,"Invalid call %d/%d:%8x\n" , - priv->buf->std.cmd_class, - priv->buf->std.cmd_select, - priv->buf->std.input[0 ]); +dev_err_ratelimited (&priv->wdev->dev,"Invalid call %d/%d:%8x\n" , + priv->buf->std.cmd_class, + priv->buf->std.cmd_select, + priv->buf->std.input[0 ]);return -EINVAL ; }
Signature · 1 line
2.56.1
PATCH v2 14/16 platform/x86: dell-smbios: Suppress bind attributes of the platform driver
In reply to Rosen PenevThe dell-smbios platform driver has no probe or remove callbacks. It only exists so the platform devices created by the module have a driver, and binding or unbinding them by hand does nothing useful while the rest of the module keeps using them.
Hide the bind and unbind files.
--- drivers/platform/x86/dell/dell-smbios-base.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/dell/dell-smbios-base.c +1 -0
@@ -524,6 +524,7 @@ static struct attribute_group smbios_attribute_group = {static struct platform_driver platform_driver = { .driver = { .name ="dell-smbios" , + .suppress_bind_attrs = true, }, };
Signature · 1 line
2.56.1
PATCH v2 15/16 platform/x86: dell-smbios: Restrict token sysfs files with their mode
In reply to Rosen PenevThe token location and value files are world-readable and check capable(CAP_SYS_ADMIN) on every read. Checking capabilities in a sysfs show() callback tests the credentials of whoever reads, not whoever opened the file, and the permissions shown by ls do not match what is enforced.
Make the files 0400 and drop the check. Only root can still read them, but an unprivileged open now fails with -EACCES instead of a read failing with -EPERM.
--- drivers/platform/x86/dell/dell-smbios-base.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/platform/x86/dell/dell-smbios-base.c +2 -8
@@ -500,9 +500,6 @@ static ssize_t location_show(struct device *dev, { struct token_sysfs_data *data = container_of(attr, struct token_sysfs_data, location_attr); -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -return sysfs_emit (buf,"%08x" , data->token->location); }
@@ -511,9 +508,6 @@ static ssize_t value_show(struct device *dev, { struct token_sysfs_data *data = container_of(attr, struct token_sysfs_data, value_attr); -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -return sysfs_emit (buf,"%08x" , data->token->value); }
@@ -561,7 +555,7 @@ static int build_tokens_sysfs(struct platform_device *dev)sysfs_attr_init (&token_entries[i].location_attr.attr); token_entries[i].location_attr.attr.name = location_name; - token_entries[i].location_attr.attr.mode =0444 ; + token_entries[i].location_attr.attr.mode =0400 ; token_entries[i].location_attr.show = location_show; token_attrs[j++] = &token_entries[i].location_attr.attr;
@@ -575,7 +569,7 @@ static int build_tokens_sysfs(struct platform_device *dev)sysfs_attr_init (&token_entries[i].value_attr.attr); token_entries[i].value_attr.attr.name = value_name; - token_entries[i].value_attr.attr.mode =0444 ; + token_entries[i].value_attr.attr.mode =0400 ; token_entries[i].value_attr.show = value_show; token_attrs[j++] = &token_entries[i].value_attr.attr; }
Signature · 1 line
2.56.1
PATCH v2 16/16 platform/x86: dell-smbios: Drop smbios_mutex from module exit
In reply to Rosen Penevsmbios_mutex protects the list of dispatcher backends. By the time dell_smbios_exit() tears down the token sysfs group and frees the tokens, both backends are unregistered and no module that uses dell-smbios is loaded, so there is nothing to protect.
No functional change.
--- drivers/platform/x86/dell/dell-smbios-base.c | 2 -- 1 file changed, 2 deletions(-)
drivers/platform/x86/dell/dell-smbios-base.c +0 -2
@@ -683,7 +683,6 @@ static void __exit dell_smbios_exit(void) {exit_dell_smbios_wmi ();exit_dell_smbios_smm (); -mutex_lock (&smbios_mutex);if (platform_device) {if (da_tokens)free_group (platform_device);
@@ -691,7 +690,6 @@ static void __exit dell_smbios_exit(void)platform_driver_unregister (&platform_driver); }kfree (da_tokens); -mutex_unlock (&smbios_mutex); }module_init (dell_smbios_init);
Signature · 1 line
2.56.1