Introduce support for Systems Management Driver over WMI for Dell Systems
PATCH v3 1/1 Introduce support for Systems Management Driver over WMI for Dell Systems
The Dell WMI Systems Management Driver provides a sysfs interface for systems management to enable BIOS configuration capability on certain Dell Systems.
This driver allows user to configure Dell systems with a uniform common interface. To facilitate this, the patch introduces a generic way for driver to be able to create configurable BIOS Attributes available in Setup (F2) screen.
---
Changes from v2 to v3:
- Fix a possible NULL pointer error in init
- Add missing newlines to all dev_err/dev_dbg/pr_err/pr_debug statements
- Correct updating passwords when both Admin and System password are set
- Correct the WMI driver name
- Correct some namespace clashing when compiled into the kernel (Reported by Mark Gross)
- Correct some comment typos
- Adopt suggestions made by Hans:
+ Use single global mutex
+ Clarify reason for uevents with a comment
+ Remove functions for set and get current password
+ Rename lower_bound to min_value and upper_bound to max_value
+ Rename possible_value to possible_values
+ Remove references to float
+ Build a separate passwords directory again since it behaves differently from the other attributes
+ Move more calls from pr_err -> dev_err
- Documentation cleanups (see v2 patch feedback)
+ Grouping types
+ Syntax of modifier output
Changes from v1 to v2:
- use pr_fmt instead of pr_err(DRIVER_NAME
- re-order variables reverse xmas tree order
- correct returns of -1 to error codes
- correct usage of {} on some split line statements
- Refine all documentation deficiencies suggested by Hans
- Merge all attributes to a single directory
- Overhaul WMI interface interaction as suggested by Hans
* Move WMI driver registration to start of module
* Remove usage of lists that only use first entry for WMI interfaces
* Create a global structure shared across interface source files
* Make get_current_password function static
* Remove get_pending changes function, shared across global structure now.
- Overhaul use of mutexes
* Make kset list mutex shared across source files
* Remove unneeded dell-wmi-sysman call_mutex
* Keep remaining call_mutexes in WMI functions
- Move security area calculation into a function
- Use NLS helper for utf8->utf16 conversion
.../testing/sysfs-platform-dell-wmi-sysman | 175 ++++++ MAINTAINERS | 9 + drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 8 + .../x86/dell-wmi-biosattr-interface.c | 197 ++++++ .../platform/x86/dell-wmi-enum-attributes.c | 208 +++++++ .../platform/x86/dell-wmi-int-attributes.c | 189 ++++++ .../x86/dell-wmi-passobj-attributes.c | 165 +++++ .../x86/dell-wmi-passwordattr-interface.c | 167 +++++ .../platform/x86/dell-wmi-string-attributes.c | 171 +++++ .../platform/x86/dell-wmi-sysman-attributes.c | 589 ++++++++++++++++++ .../platform/x86/dell-wmi-sysman-attributes.h | 137 ++++ 12 files changed, 2027 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman create mode 100644 drivers/platform/x86/dell-wmi-biosattr-interface.c create mode 100644 drivers/platform/x86/dell-wmi-enum-attributes.c create mode 100644 drivers/platform/x86/dell-wmi-int-attributes.c create mode 100644 drivers/platform/x86/dell-wmi-passobj-attributes.c create mode 100644 drivers/platform/x86/dell-wmi-passwordattr-interface.c create mode 100644 drivers/platform/x86/dell-wmi-string-attributes.c create mode 100644 drivers/platform/x86/dell-wmi-sysman-attributes.c create mode 100644 drivers/platform/x86/dell-wmi-sysman-attributes.h
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +175 -0
@@ -0,0 +1,175 @@ +What: /sys/devices/platform/dell-wmi-sysman/attributes/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + The Dell WMI Systems Management Driver provides a sysfs interface + for systems management software to enable BIOS configuration + capability on certain Dell systems. This directory exposes + interfaces for interacting with BIOS attributes. + + Attributes can accept a set of pre-defined valid values (enumeration) + or a range of numerical values (integer) or a string. + + current_value: A file that can be read to obtain the current + value of the <attr> + + This file can also be written to in order to update + the value of a <attr> + + default_value: A file that can be read to obtain the default + value of the <attr> + + display_name: A file that can be read to obtain a user friendly + description of the at <attr> + + display_name_language_code: A file that can be read to obtain + the IETF language tag corresponding to the "display_name" of the <attr> + + modifier: A file that can be read to obtain attribute-level + dependency rule. It says an attribute X will become read-only or + suppressed, if/if-not attribute Y is configured. + + modifier rules can be in following format, + [ReadOnlyIf:<attribute>=<value>] + [ReadOnlyIfNot:<attribute>=<value>] + [SuppressIf:<attribute>=<value>] + [SuppressIfNot:<attribute>=<value>] + + For example, + AutoOnFri/modifier has value, + [SuppressIfNot:AutoOn=SelectDays] + This means AutoOnFri will be supressed in BIOS setup if AutoOn + attribute is not "SelectDays" and its value will not be effective + through sysfs until this rule is met. + + "enumeration"-type specific properties: + + possible_values: A file that can be read to obtain the possible + values of the <attr>. Values are separated using semi-colon. + + value_modifier: A file that can be read to obtain value-level + dependency. This file is similar to modifier but here, an attribute's + current value will be forcefully changed based dependent attributes + value. + + value_modifier rules can be in following format, + <value>[ForceIf:<attribute>=<value>] + <value>[ForceIfNot:<attribute>=<value>] + + For example, + LegacyOrom/value_modifier has value, + Disabled[ForceIf:SecureBoot=Enabled] + This means LegacyOrom's current value will be forced to "Disabled" + in BIOS setup if SecureBoot is Enabled and its value will not be + effective through sysfs until this rule is met. + + "integer"-type specific properties: + + min_value: A file that can be read to obtain the lower + bound value of the <attr> + + max_value: A file that can be read to obtain the upper + bound value of the <attr> + + scalar_increment: A file that can be read to obtain the + resolution of the incremental value this attribute accepts. + + "string"-type specific properties: + + max_length: A file that can be read to obtain the maximum + length value of the <attr> + + min_length: A file that can be read to obtain the minimum + length value of the <attr> + +What: /sys/devices/platform/dell-wmi-sysman/passwords/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> + + A BIOS Admin password and System Password can be set, reset or + cleared using these attributes. An "Admin" password is used for + preventing modification to the BIOS settings. A "System" password is + required to boot a machine. + + is_password_set: A file that can be read + to obtain flag to see if a password is set on <attr> + + max_password_length: A file that can be read to obtain the + maximum length of the Password + + min_password_length: A file that can be read to obtain the + minimum length of the Password + + current_password: A write only value used for privileged access + such as setting attributes when a system or admin password is set + or resetting to a new password + + new_password: A write only value that when used in tandem with + current_password will reset a system or admin password. + + Note, password management is session specific. If Admin/System + password is set, same password must be writen into current_password + file (requied for pasword-validation) and must be cleared once the + session is over. For example, + echo "password" > current_password + echo "disabled" > TouchScreen/current_value + echo "" > current_password + + +What: /sys/devices/platform/dell-wmi-sysman/attributes/reset_bios +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + This attribute can be used to reset the BIOS Configuration. + Specifically, it tells which type of reset BIOS configuration is being + requested on the host. + + Reading from it returns a list of supported options encoded as: + + 'builtinsafe' (Built in safe configuration profile) + 'lastknowngood' (Last known good saved configuration profile) + 'factory' (Default factory settings configuration profile) + 'custom' (Custom saved configuration profile) + + The currently selected option is printed in square brackets as + shown below: + + # echo "factory" > sys/devices/platform/dell-wmi-sysman/attributes/reset_bios + + # cat sys/devices/platform/dell-wmi-sysman/attributes/reset_bios + # builtinsafe lastknowngood [factory] custom + + Note that any changes to this attribute requires a reboot + for changes to take effect. + +What: /sys/devices/platform/dell-wmi-sysman/attributes/pending_reboot +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + A read-only attribute reads 1 if a reboot is necessary to apply + pending BIOS attribute changes. + + 0: All BIOS attributes setting are current + 1: A reboot is necessary to get pending BIOS attribute changes + applied + + + Note, userspace applications need to follow below steps for efficient + BIOS management, + 1. Check if admin password is set. If yes, follow session method for + password management as briefed under password section above. + 2. Before setting any attribute, check if it has any modifiers + or value_modifiers. If yes, incorporate them and then modify + attribute.
MAINTAINERS +9 -0
@@ -4957,6 +4957,15 @@ M: Mario Limonciello <[email protected]> S: Maintained F: drivers/platform/x86/dell-wmi-descriptor.c +DELL WMI SYSMAN DRIVER +M: Divya Bharathi <[email protected]> +M: Mario Limonciello <[email protected]> +M: Prasanth Ksr <[email protected]> +L: [email protected] +S: Maintained +F: drivers/platform/x86/dell-wmi-*-attributes.* +F: drivers/platform/x86/dell-wmi-*-interface.c + DELL WMI NOTIFICATIONS DRIVER M: Matthew Garrett <[email protected]> M: Pali Rohár <[email protected]>
drivers/platform/x86/Kconfig +12 -0
@@ -430,6 +430,18 @@ config DELL_WMI To compile this driver as a module, choose M here: the module will be called dell-wmi. +config DELL_WMI_SYSMAN + tristate "Dell WMI Systems management WMI driver" + depends on ACPI_WMI + depends on DMI + select NLS + help + This driver allows changing BIOS settings on many Dell machines from + 2018 and newer without the use of any additional software. + + To compile this driver as a module, choose M here: the module will + be called dell-wmi-sysman. + config DELL_WMI_DESCRIPTOR tristate depends on ACPI_WMI
drivers/platform/x86/Makefile +8 -0
@@ -47,6 +47,14 @@ obj-$(CONFIG_DELL_WMI) += dell-wmi.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o +obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman.o +dell-wmi-sysman-objs := dell-wmi-sysman-attributes.o \ + dell-wmi-enum-attributes.o \ + dell-wmi-int-attributes.o \ + dell-wmi-string-attributes.o \ + dell-wmi-passobj-attributes.o \ + dell-wmi-passwordattr-interface.o \ + dell-wmi-biosattr-interface.o # Fujitsu obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o
drivers/platform/x86/dell-wmi-biosattr-interface.c new file +197 -0
197 lines not on this page · raw message
drivers/platform/x86/dell-wmi-enum-attributes.c new file +208 -0
208 lines not on this page · raw message
drivers/platform/x86/dell-wmi-int-attributes.c new file +189 -0
189 lines not on this page · raw message
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +165 -0
165 lines not on this page · raw message
drivers/platform/x86/dell-wmi-passwordattr-interface.c new file +167 -0
167 lines not on this page · raw message
drivers/platform/x86/dell-wmi-string-attributes.c new file +171 -0
171 lines not on this page · raw message
drivers/platform/x86/dell-wmi-sysman-attributes.c new file +589 -0
589 lines not on this page · raw message
drivers/platform/x86/dell-wmi-sysman-attributes.h new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Divya,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linux/master]
[also build test WARNING on linus/master v5.9-rc5 next-20200916] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Divya-Bharathi/Introduce-support-for-Systems-Management-Driver-over-WMI-for-Dell-Systems/20200917-145838 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git bcf876870b95592b52519ed4aafcf9d95999bc9c config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from drivers/platform/x86/dell-wmi-enum-attributes.c:9:
>> drivers/platform/x86/dell-wmi-sysman-attributes.h:53:5: warning: no previous prototype for 'get_enumeration_instance_id' [-Wmissing-prototypes]
53 | int get_##type##_instance_id(struct kobject *kobj) \
| ^~~~
drivers/platform/x86/dell-wmi-enum-attributes.c:28:1: note: in expansion of macro 'get_instance_id'
28 | get_instance_id(enumeration);
| ^~~~~~~~~~~~~~~
>> drivers/platform/x86/dell-wmi-enum-attributes.c:57:5: warning: no previous prototype for 'validate_enumeration_input' [-Wmissing-prototypes] 57 | int validate_enumeration_input(int instance_id, const char *buf)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from drivers/platform/x86/dell-wmi-int-attributes.c:9:
>> drivers/platform/x86/dell-wmi-sysman-attributes.h:53:5: warning: no previous prototype for 'get_integer_instance_id' [-Wmissing-prototypes]
53 | int get_##type##_instance_id(struct kobject *kobj) \
| ^~~~
drivers/platform/x86/dell-wmi-int-attributes.c:29:1: note: in expansion of macro 'get_instance_id'
29 | get_instance_id(integer);
| ^~~~~~~~~~~~~~~
>> drivers/platform/x86/dell-wmi-int-attributes.c:58:5: warning: no previous prototype for 'validate_integer_input' [-Wmissing-prototypes] 58 | int validate_integer_input(int instance_id, const char *buf)
| ^~~~~~~~~~~~~~~~~~~~~~
--
In file included from drivers/platform/x86/dell-wmi-string-attributes.c:9:
>> drivers/platform/x86/dell-wmi-sysman-attributes.h:53:5: warning: no previous prototype for 'get_str_instance_id' [-Wmissing-prototypes]
53 | int get_##type##_instance_id(struct kobject *kobj) \
| ^~~~
drivers/platform/x86/dell-wmi-string-attributes.c:28:1: note: in expansion of macro 'get_instance_id'
28 | get_instance_id(str);
| ^~~~~~~~~~~~~~~
>> drivers/platform/x86/dell-wmi-string-attributes.c:57:5: warning: no previous prototype for 'validate_str_input' [-Wmissing-prototypes] 57 | int validate_str_input(int instance_id, const char *buf)
| ^~~~~~~~~~~~~~~~~~
--
In file included from drivers/platform/x86/dell-wmi-passobj-attributes.c:9:
>> drivers/platform/x86/dell-wmi-sysman-attributes.h:53:5: warning: no previous prototype for 'get_po_instance_id' [-Wmissing-prototypes]
53 | int get_##type##_instance_id(struct kobject *kobj) \
| ^~~~
drivers/platform/x86/dell-wmi-passobj-attributes.c:24:1: note: in expansion of macro 'get_instance_id'
24 | get_instance_id(po);
| ^~~~~~~~~~~~~~~# https://github.com/0day-ci/linux/commit/4809f4528720c1aa027b717b66960848bdae7b58
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Divya-Bharathi/Introduce-support-for-Systems-Management-Driver-over-WMI-for-Dell-Systems/20200917-145838 git checkout 4809f4528720c1aa027b717b66960848bdae7b58
vim +/get_enumeration_instance_id +53 drivers/platform/x86/dell-wmi-sysman-attributes.h
51
52 #define get_instance_id(type) \
> 53 int get_##type##_instance_id(struct kobject *kobj) \
54 { \
55 int i; \
56 for (i = 0; i <= type##_instances_count; i++) { \
57 if (!(strcmp(kobj->name, type##_data[i].attribute_name))) \
58 return i; \
59 } \
60 return -EIO; \
61 }
62 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Hi,
As usual, first a review of the userspace API.
Note the biggest pending issue with the userspace API is if we are going to keep this under /sys/devices/platform/dell-wmi-sysman/ or if we are going to have it under:
/sys/class/firmware-attributes/dell-wmi-sysman/
That is still being discussed in the v1 thread.
Quoted 126 lines · Divya Bharathi
The Dell WMI Systems Management Driver provides a sysfs interface for systems management to enable BIOS configuration capability on certain Dell Systems.
This driver allows user to configure Dell systems with a uniform common interface. To facilitate this, the patch introduces a generic way for driver to be able to create configurable BIOS Attributes available in Setup (F2) screen.
Cc Hans de Goede <[email protected]>Cc Andy Shevchenko <[email protected]>Cc mark gross <[email protected]>Co-developed-by Mario Limonciello <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Co-developed-by Prasanth KSR <[email protected]>Signed-off-by Prasanth KSR <[email protected]>Signed-off-by Divya Bharathi <[email protected]>---
Changes from v2 to v3:
- Fix a possible NULL pointer error in init
- Add missing newlines to all dev_err/dev_dbg/pr_err/pr_debug statements
- Correct updating passwords when both Admin and System password are set
- Correct the WMI driver name
- Correct some namespace clashing when compiled into the kernel (Reported by Mark Gross)
- Correct some comment typos
- Adopt suggestions made by Hans:
+ Use single global mutex
+ Clarify reason for uevents with a comment
+ Remove functions for set and get current password
+ Renamelower_boundtomin_valueandupper_boundtomax_value
+ Renamepossible_valuetopossible_values
+ Remove references to float
+ Build a separate passwords directory again since it behaves differently from the other attributes
+ Move more calls frompr_err->dev_err
- Documentation cleanups (see v2 patch feedback)
+ Grouping types
+ Syntax ofmodifieroutputChanges from v1 to v2:
- usepr_fmtinstead of pr_err(DRIVER_NAME
- re-order variables reverse xmas tree order
- correct returns of -1 to error codes
- correct usage of {} on some split line statements
- Refine all documentation deficiencies suggested by Hans
- Merge all attributes to a single directory
- Overhaul WMI interface interaction as suggested by Hans
* Move WMI driver registration to start of module
* Remove usage of lists that only use first entry for WMI interfaces
* Create a global structure shared across interface source files
* Makeget_current_passwordfunction static
* Removeget_pendingchanges function, shared across global structure now.
- Overhaul use of mutexes
* Make kset list mutex shared across source files
* Remove unneeded dell-wmi-sysmancall_mutex
* Keep remainingcall_mutexesin WMI functions
- Move security area calculation into a function
- Use NLS helper forutf8->utf16conversion.../testing/sysfs-platform-dell-wmi-sysman | 175 ++++++ MAINTAINERS | 9 + drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 8 + .../x86/dell-wmi-biosattr-interface.c | 197 ++++++ .../platform/x86/dell-wmi-enum-attributes.c | 208 +++++++ .../platform/x86/dell-wmi-int-attributes.c | 189 ++++++ .../x86/dell-wmi-passobj-attributes.c | 165 +++++ .../x86/dell-wmi-passwordattr-interface.c | 167 +++++ .../platform/x86/dell-wmi-string-attributes.c | 171 +++++ .../platform/x86/dell-wmi-sysman-attributes.c | 589 ++++++++++++++++++ .../platform/x86/dell-wmi-sysman-attributes.h | 137 ++++ 12 files changed, 2027 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysmancreate mode 100644drivers/platform/x86/dell-wmi-biosattr-interface.ccreate mode 100644drivers/platform/x86/dell-wmi-enum-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-int-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-passobj-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-passwordattr-interface.ccreate mode 100644drivers/platform/x86/dell-wmi-string-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-sysman-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-sysman-attributes.hDocumentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +36
-0@@ -0,0 +1,175 @@ +What: /sys/devices/platform/dell-wmi-sysman/attributes/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + The Dell WMI Systems Management Driver provides a sysfs interface + for systems management software to enable BIOS configuration + capability on certain Dell systems. This directory exposes + interfaces for interacting with BIOS attributes. + + Attributes can accept a set of pre-defined valid values (enumeration) + or a range of numerical values (integer) or a string. + + current_value: A file that can be read to obtain the current + value of the <attr> + + This file can also be written to in order to update + the value of a <attr> + + default_value: A file that can be read to obtain the default + value of the <attr> + + display_name: A file that can be read to obtain a user friendly + description of the at <attr> + + display_name_language_code: A file that can be read to obtain + the IETF language tag corresponding to the "display_name" of the <attr> + + modifier: A file that can be read to obtain attribute-level + dependency rule. It says an attribute X will become read-only or + suppressed, if/if-not attribute Y is configured. + + modifier rules can be in following format, + [ReadOnlyIf:<attribute>=<value>]
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 46
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+ [ReadOnlyIfNot:<attribute>=<value>] + [SuppressIf:<attribute>=<value>] + [SuppressIfNot:<attribute>=<value>] + + For example, + AutoOnFri/modifier has value, + [SuppressIfNot:AutoOn=SelectDays] + This means AutoOnFri will be supressed in BIOS setup if AutoOn + attribute is not "SelectDays" and its value will not be effective + through sysfs until this rule is met.
As discussed in the v1 thread, this is somewhat Dell specific and we make the sysfs interface generic and move this to /sys/class/firmware-attributes/dell-wmi-sysman/ then this should probably be prefixed with dell- (and moved to a separate section of this file for vendor extensions to the generic part)
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +11
-0+ + "enumeration"-type specific properties: + + possible_values: A file that can be read to obtain the possible + values of the <attr>. Values are separated using semi-colon. + + value_modifier: A file that can be read to obtain value-level + dependency. This file is similar to modifier but here, an attribute's + current value will be forcefully changed based dependent attributes + value. +
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 67
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+ value_modifier rules can be in following format, + <value>[ForceIf:<attribute>=<value>] + <value>[ForceIfNot:<attribute>=<value>] + + For example, + LegacyOrom/value_modifier has value, + Disabled[ForceIf:SecureBoot=Enabled] + This means LegacyOrom's current value will be forced to "Disabled" + in BIOS setup if SecureBoot is Enabled and its value will not be + effective through sysfs until this rule is met.
Are value_modifiers only valid for enums? If not this should be moved to the generic properties (or to the vendor extensions part)
Quoted 45 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +45
-0+ + "integer"-type specific properties: + + min_value: A file that can be read to obtain the lower + bound value of the <attr> + + max_value: A file that can be read to obtain the upper + bound value of the <attr> + + scalar_increment: A file that can be read to obtain the + resolution of the incremental value this attribute accepts. + + "string"-type specific properties: + + max_length: A file that can be read to obtain the maximum + length value of the <attr> + + min_length: A file that can be read to obtain the minimum + length value of the <attr> + +What: /sys/devices/platform/dell-wmi-sysman/passwords/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> + + A BIOS Admin password and System Password can be set, reset or + cleared using these attributes. An "Admin" password is used for + preventing modification to the BIOS settings. A "System" password is + required to boot a machine. + + is_password_set: A file that can be read + to obtain flag to see if a password is set on <attr> + + max_password_length: A file that can be read to obtain the + maximum length of the Password + + min_password_length: A file that can be read to obtain the + minimum length of the Password + + current_password: A write only value used for privileged access + such as setting attributes when a system or admin password is set + or resetting to a new password +
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 122
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+ new_password: A write only value that when used in tandem with + current_password will reset a system or admin password. + + Note, password management is session specific. If Admin/System + password is set, same password must be writen into current_password + file (requied for pasword-validation) and must be cleared once the + session is over. For example, + echo "password" > current_password + echo "disabled" > TouchScreen/current_value + echo "" > current_password
So I know this was mentioned before already but one concern I have here
is that there is a race where other users with write access to say TouchScreen/current_value may change it between the setting and the clearing of the current_password even if they don't have the password.
This is esp. relevant with containers. I'm not aware about all the intrinsics of sysfs and containers, at a minimum we need to check if it is possible to disallow all writes to the attributes when sysfs is mounted inside a container (so outside of the main filesystem namespace).
If someone is reading along who happen to knows this, please enlighten me :)
Quoted 43 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +43
-0+ + +What: /sys/devices/platform/dell-wmi-sysman/attributes/reset_bios +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + This attribute can be used to reset the BIOS Configuration. + Specifically, it tells which type of reset BIOS configuration is being + requested on the host. + + Reading from it returns a list of supported options encoded as: + + 'builtinsafe' (Built in safe configuration profile) + 'lastknowngood' (Last known good saved configuration profile) + 'factory' (Default factory settings configuration profile) + 'custom' (Custom saved configuration profile) + + The currently selected option is printed in square brackets as + shown below: + + # echo "factory" > sys/devices/platform/dell-wmi-sysman/attributes/reset_bios + + # cat sys/devices/platform/dell-wmi-sysman/attributes/reset_bios + # builtinsafe lastknowngood [factory] custom + + Note that any changes to this attribute requires a reboot + for changes to take effect. + +What: /sys/devices/platform/dell-wmi-sysman/attributes/pending_reboot +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + A read-only attribute reads 1 if a reboot is necessary to apply + pending BIOS attribute changes. + + 0: All BIOS attributes setting are current + 1: A reboot is necessary to get pending BIOS attribute changes
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 175
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+ applied + + + Note, userspace applications need to follow below steps for efficient + BIOS management, + 1. Check if admin password is set. If yes, follow session method for + password management as briefed under password section above. + 2. Before setting any attribute, check if it has any modifiers + or value_modifiers. If yes, incorporate them and then modify + attribute.
OK, so as also mentioned in the v1 thread, I would like to see the uevent disappear since it is somewhat of a heavy mechanism and not necessary when userspace specifically cares about a single sysfs attribute changing.
Instead we can allow userspace to use poll() for POLL_PRI on this file to be notified when it goes from 0 -> 1. See the v1 thread for some example code how to wake the poll() in this case.
Regards,
Hans
Quoted 56 lines
Quoted 21 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +20
-0+ + "integer"-type specific properties: + + min_value: A file that can be read to obtain the lower + bound value of the <attr> + + max_value: A file that can be read to obtain the upper + bound value of the <attr> + + scalar_increment: A file that can be read to obtain the + resolution of the incremental value this attribute accepts. + + "string"-type specific properties: + + max_length: A file that can be read to obtain the maximum + length value of the <attr> + + min_length: A file that can be read to obtain the minimum + length value of the <attr> +Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+What: /sys/devices/platform/dell-wmi-sysman/passwords/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> + + A BIOS Admin password and System Password can be set, reset or + cleared using these attributes. An "Admin" password is used for + preventing modification to the BIOS settings. A "System" passwordis
Quoted 24 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +24
-0+ required to boot a machine. + + is_password_set: A file that can be read + to obtain flag to see if a password is set on <attr> + + max_password_length: A file that can be read to obtain the + maximum length of the Password + + min_password_length: A file that can be read to obtain the + minimum length of the Password + + current_password: A write only value used for privileged access + such as setting attributes when a system or admin password is set + or resetting to a new password + + new_password: A write only value that when used in tandem with + current_password will reset a system or admin password. + + Note, password management is session specific. If Admin/System + password is set, same password must be writen into current_password + file (requied for pasword-validation) and must be cleared once the + session is over. For example, + echo "password" > current_password + echo "disabled" > TouchScreen/current_value
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 122
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +1
-0+ echo "" > current_passwordSo I know this was mentioned before already but one concern I have here is that there is a race where other users with write access to say TouchScreen/current_value
may change it between the setting and the clearing of thecurrent_passwordeven if
they don't have the password.
I don't think there is much that can be done here other than move to something atomic like sending the password as part of the request.
echo "foobar123|enabled" | sudo tee /sys/devices/platform/dell-wmi-sysman/
That isn't really pretty - and worse you can no longer have a process fetching authentication from escrow that is different from your "setter" process.
Quoted 8 lines
This is esp. relevant with containers. I'm not aware about all the intrinsics of
sysfs and containers, at a minimum we need to check if it is possible to disallow
all writes to the attributes when sysfs is mounted inside a container (so outside of the
main filesystem namespace).
Containers by default mount sysfs as read only unless you use the '--privileged' flag.
https://www.redhat.com/sysadmin/privileged-flag-container-engines
Quoted 78 lines
If someone is reading along who happen to knows this, please enlighten me :)
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +11
-0+ + +What: /sys/devices/platform/dell-wmi-sysman/attributes/reset_bios +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + This attribute can be used to reset the BIOS Configuration. + Specifically, it tells which type of reset BIOS configuration isbeing
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 13 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +13
-0+ requested on the host. + + Reading from it returns a list of supported options encoded as: + + 'builtinsafe' (Built in safe configuration profile) + 'lastknowngood' (Last known good saved configuration profile) + 'factory' (Default factory settings configuration profile) + 'custom' (Custom saved configuration profile) + + The currently selected option is printed in square brackets as + shown below: + + # echo "factory" > sys/devices/platform/dell-wmi-sysman/attributes/reset_bios
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +8
-0+ + # cat sys/devices/platform/dell-wmi-sysman/attributes/reset_bios + # builtinsafe lastknowngood [factory] custom + + Note that any changes to this attribute requires a reboot + for changes to take effect. + +What: /sys/devices/platform/dell-wmi-sysman/attributes/pending_reboot
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +11
-0+Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> +Description: + A read-only attribute reads 1 if a reboot is necessary to apply + pending BIOS attribute changes. + + 0: All BIOS attributes setting are current + 1: A reboot is necessary to get pending BIOS attributechanges
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +4
-0+ applied + + + Note, userspace applications need to follow below steps forefficient
Review
Quoted 2 lines
(quoted diff) +2
-0+ BIOS management, + 1. Check if admin password is set. If yes, follow session methodfor
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 175
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +4
-0+ password management as briefed under password section above. + 2. Before setting any attribute, check if it has any modifiers + or value_modifiers. If yes, incorporate them and then modify + attribute.OK, so as also mentioned in the v1 thread, I would like to see the uevent disappear
since it is somewhat of a heavy mechanism and not necessary when userspace specifically
cares about a single sysfs attribute changing.Instead we can allow userspace to use
poll()forPOLL_PRIon this file to be notified
when it goes from 0 -> 1. See the v1 thread for some example code how to wake thepoll()in this case.Regards,
Hans
Hi,
Quoted 65 lines · Mario
Quoted 56 lines
Quoted 21 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +20
-0+ + "integer"-type specific properties: + + min_value: A file that can be read to obtain the lower + bound value of the <attr> + + max_value: A file that can be read to obtain the upper + bound value of the <attr> + + scalar_increment: A file that can be read to obtain the + resolution of the incremental value this attribute accepts. + + "string"-type specific properties: + + max_length: A file that can be read to obtain the maximum + length value of the <attr> + + min_length: A file that can be read to obtain the minimum + length value of the <attr> +Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +10
-0+What: /sys/devices/platform/dell-wmi-sysman/passwords/ +Date: December 2020 +KernelVersion: 5.10 +Contact: Divya Bharathi <[email protected]>, + Mario Limonciello <[email protected]>, + Prasanth KSR <[email protected]> + + A BIOS Admin password and System Password can be set, reset or + cleared using these attributes. An "Admin" password is used for + preventing modification to the BIOS settings. A "System" passwordis
Quoted 24 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +24
-0+ required to boot a machine. + + is_password_set: A file that can be read + to obtain flag to see if a password is set on <attr> + + max_password_length: A file that can be read to obtain the + maximum length of the Password + + min_password_length: A file that can be read to obtain the + minimum length of the Password + + current_password: A write only value used for privileged access + such as setting attributes when a system or admin password is set + or resetting to a new password + + new_password: A write only value that when used in tandem with + current_password will reset a system or admin password. + + Note, password management is session specific. If Admin/System + password is set, same password must be writen into current_password + file (requied for pasword-validation) and must be cleared once the + session is over. For example, + echo "password" > current_password + echo "disabled" > TouchScreen/current_valueQuoted 8 lines
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman line 122
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysman new file +1
-0+ echo "" > current_passwordSo I know this was mentioned before already but one concern I have here is that there is a race where other users with write access to say TouchScreen/current_value
may change it between the setting and the clearing of thecurrent_passwordeven if
they don't have the password.
Quoted 2 lines
I don't think there is much that can be done here other than move to something atomic like sending the password as part of the request.
Right, I'm not saying this scheme is bad per se I just wanted to make sure that this was brought up and discussed.
Quoted 4 lines
echo "foobar123|enabled" | sudo tee
/sys/devices/platform/dell-wmi-sysman/That isn't really pretty - and worse you can no longer have a process fetching authentication from escrow that is different from your "setter" process.
Note you will likely need some form of IPC, say dbus to your escrow process anyways to ask it to unlock. So you could just change the "unlock" request to a "set Camera=Enabled" request and have the process which has access to the authentication token make the changes itself.
Quoted 8 lines
Quoted 7 lines
This is esp. relevant with containers. I'm not aware about all the intrinsics of
sysfs and containers, at a minimum we need to check if it is possible to disallow
all writes to the attributes when sysfs is mounted inside a container (so outside of the
main filesystem namespace).
Quoted 4 lines
Containers by default mount sysfs as read only unless you use the '--privileged' flag.
https://www.redhat.com/sysadmin/privileged-flag-container-engines
Thanks that is good to know and does address most of my concerns. What I was wondering about is if we can enforce this in the kernel even for --privileged containers. I guess another question would be if we can do that, should we?
Regards,
Hans
Hi,
Ok code review this time. Still mainly focussing on the overal structure and not so much individual functions.
Note the code is starting to look good to me.
One general remark, now that we are keeping the 1 file per type (int/enum/string) layout, there are quite a few files in this driver. I think it would be good to create a drivers/platform/x86/dell-wmi-sysman dir and put all the files there, so that it is easier to e.g. grep for something in all the files belonging to this driver.
Quoted 83 lines · Divya Bharathi
The Dell WMI Systems Management Driver provides a sysfs interface for systems management to enable BIOS configuration capability on certain Dell Systems.
This driver allows user to configure Dell systems with a uniform common interface. To facilitate this, the patch introduces a generic way for driver to be able to create configurable BIOS Attributes available in Setup (F2) screen.
Cc Hans de Goede <[email protected]>Cc Andy Shevchenko <[email protected]>Cc mark gross <[email protected]>Co-developed-by Mario Limonciello <[email protected]>Signed-off-by Mario Limonciello <[email protected]>Co-developed-by Prasanth KSR <[email protected]>Signed-off-by Prasanth KSR <[email protected]>Signed-off-by Divya Bharathi <[email protected]>---
Changes from v2 to v3:
- Fix a possible NULL pointer error in init
- Add missing newlines to all dev_err/dev_dbg/pr_err/pr_debug statements
- Correct updating passwords when both Admin and System password are set
- Correct the WMI driver name
- Correct some namespace clashing when compiled into the kernel (Reported by Mark Gross)
- Correct some comment typos
- Adopt suggestions made by Hans:
+ Use single global mutex
+ Clarify reason for uevents with a comment
+ Remove functions for set and get current password
+ Renamelower_boundtomin_valueandupper_boundtomax_value
+ Renamepossible_valuetopossible_values
+ Remove references to float
+ Build a separate passwords directory again since it behaves differently from the other attributes
+ Move more calls frompr_err->dev_err
- Documentation cleanups (see v2 patch feedback)
+ Grouping types
+ Syntax ofmodifieroutputChanges from v1 to v2:
- usepr_fmtinstead of pr_err(DRIVER_NAME
- re-order variables reverse xmas tree order
- correct returns of -1 to error codes
- correct usage of {} on some split line statements
- Refine all documentation deficiencies suggested by Hans
- Merge all attributes to a single directory
- Overhaul WMI interface interaction as suggested by Hans
* Move WMI driver registration to start of module
* Remove usage of lists that only use first entry for WMI interfaces
* Create a global structure shared across interface source files
* Makeget_current_passwordfunction static
* Removeget_pendingchanges function, shared across global structure now.
- Overhaul use of mutexes
* Make kset list mutex shared across source files
* Remove unneeded dell-wmi-sysmancall_mutex
* Keep remainingcall_mutexesin WMI functions
- Move security area calculation into a function
- Use NLS helper forutf8->utf16conversion.../testing/sysfs-platform-dell-wmi-sysman | 175 ++++++ MAINTAINERS | 9 + drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 8 + .../x86/dell-wmi-biosattr-interface.c | 197 ++++++ .../platform/x86/dell-wmi-enum-attributes.c | 208 +++++++ .../platform/x86/dell-wmi-int-attributes.c | 189 ++++++ .../x86/dell-wmi-passobj-attributes.c | 165 +++++ .../x86/dell-wmi-passwordattr-interface.c | 167 +++++ .../platform/x86/dell-wmi-string-attributes.c | 171 +++++ .../platform/x86/dell-wmi-sysman-attributes.c | 589 ++++++++++++++++++ .../platform/x86/dell-wmi-sysman-attributes.h | 137 ++++ 12 files changed, 2027 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-platform-dell-wmi-sysmancreate mode 100644drivers/platform/x86/dell-wmi-biosattr-interface.ccreate mode 100644drivers/platform/x86/dell-wmi-enum-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-int-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-passobj-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-passwordattr-interface.ccreate mode 100644drivers/platform/x86/dell-wmi-string-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-sysman-attributes.ccreate mode 100644drivers/platform/x86/dell-wmi-sysman-attributes.h
<snip>
Quoted 23 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +17
-0@@ -0,0 +1,208 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Functions corresponding to enumeration type attributes under BIOS Enumeration GUID for use +* with dell-wmi-sysman +* +* Copyright (c) 2020 Dell Inc. +*/ + +#include "dell-wmi-sysman-attributes.h" + +/* kept variable names same as in sysfs file name for sysfs_show macro definition */ +struct enumeration_data { +char display_name_language_code[MAX_BUFF ]; +char attribute_name[MAX_BUFF ]; +char display_name[MAX_BUFF ]; +char default_value[MAX_BUFF ]; +char current_value[MAX_BUFF ];
drivers/platform/x86/dell-wmi-enum-attributes.c line 27
Quoted 10 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +10
-0+char modifier[MAX_BUFF ]; +int value_modifier_count; +char value_modifier[MAX_BUFF ]; +int possible_values_count; +char possible_values[MAX_BUFF ]; +char type[MAX_BUFF ]; +}; + +static struct enumeration_data *enumeration_data; +static int enumeration_instances_count;
Can we put these 2 static globals inside the wmi_priv data structure? It does not matter much but I find it a bit cleaner to have all global state together in a single place.
drivers/platform/x86/dell-wmi-enum-attributes.c line 28
Quoted 1 line
drivers/platform/x86/dell-wmi-enum-attributes.c new file +1
-0+get_instance_id (enumeration);
This macro will need to be adjusted a bit then, but I don't see any problem there, just put wmi_priv. in front of the type##_instances_count and type##_data[i].attribute_name.
Quoted 95 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +95
-0+ +static ssize_t current_value_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) +{ +int instance_id; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + instance_id =get_enumeration_instance_id (kobj); +if (instance_id >=0 ) { +union acpi_object *obj; + +/* need to use specific instance_id and guid combination to get right data */ + obj =get_wmiobj_pointer (instance_id,DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID ); +if (!obj) +return -AE_ERROR ; +strncpy_attr (enumeration_data[instance_id].current_value, + obj->package.elements[CURRENT_VAL ].string.pointer); +kfree (obj); +return sprintf (buf,"%s\n" , enumeration_data[instance_id].current_value); + } +return -EIO ; +} + +/** +* validate_enumeration_input() - Validate input of current_value against possible values +* @instance_id: The instance on which input is validated +* @buf: Input value +**/ +int validate_enumeration_input (int instance_id,const char *buf) +{ +char *options, *tmp, *p; +int ret = -EINVAL ; + + options = tmp =kstrdup ((enumeration_data[instance_id].possible_values),GFP_KERNEL ); +if (!options) +return -ENOMEM ; + +while ((p =strsep (&options,";" )) !=NULL ) { +if (!*p) +continue ; +if (!strncasecmp (p, buf,strlen (p))) { + ret =0 ; +break ; + } + } + +kfree (tmp); +return ret; +} + +attribute_s_property_show (display_name_language_code, enumeration); +static struct kobj_attribute displ_langcode = +__ATTR_RO (display_name_language_code); + +attribute_s_property_show (display_name, enumeration); +struct kobj_attribute displ_name = +__ATTR_RO (display_name); + +attribute_s_property_show (default_value, enumeration); +struct kobj_attribute default_val = +__ATTR_RO (default_value); + +attribute_property_store (current_value, enumeration); +struct kobj_attribute current_val = +__ATTR_RW (current_value); + +attribute_s_property_show (modifier, enumeration); +struct kobj_attribute modifier = +__ATTR_RO (modifier); + +attribute_s_property_show (value_modifier, enumeration); +struct kobj_attribute value_modfr = +__ATTR_RO (value_modifier); + +attribute_s_property_show (possible_values, enumeration); +struct kobj_attribute poss_val = +__ATTR_RO (possible_values); + +attribute_s_property_show (type, enumeration); +struct kobj_attribute type = +__ATTR_RO (type); + +static struct attribute *enumeration_attrs[] = { + &displ_langcode.attr, + &displ_name.attr, + &default_val.attr, + ¤t_val.attr, + &modifier.attr, + &value_modfr.attr, + &poss_val.attr, + &type.attr, +NULL , +}; + +static const struct attribute_group enumeration_attr_group = {
drivers/platform/x86/dell-wmi-enum-attributes.c line 133
Quoted 10 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +10
-0+ .attrs = enumeration_attrs, +}; + +int alloc_enum_data (void ) +{ +int ret =0 ; + + enumeration_instances_count =get_instance_count (DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID ); + enumeration_data =kzalloc ((sizeof (struct enumeration_data ) * enumeration_instances_count), +GFP_KERNEL );
Please use kcalloc here, that will check that the
(sizeof(struct enumeration_data) * enumeration_instances_count multiplication does not overflow. The same for all the other alloc_foo_data functions.
Quoted 5 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +5
-0+if (!enumeration_data) + ret = -ENOMEM ; +return ret; +} +
drivers/platform/x86/dell-wmi-enum-attributes.c line 148
Quoted 10 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +10
-0+/** +* populate_enum_data() - Populate all properties of an instance under enumeration attribute +* @enumeration_obj: ACPI object with enumeration data +* @instance_id: The instance to enumerate +* @attr_name_kobj: The parent kernel object +**/ +int populate_enum_data (union acpi_object *enumeration_obj,int instance_id, +struct kobject *attr_name_kobj) +{ +int retval =sysfs_create_group (attr_name_kobj, &enumeration_attr_group);
This needs to be moved to the end of this function, as soon as you call this, e.g. current_value_show() could be called, before the enumeration_data[instance_id].current_value buffer has been filled.
The same goes for the other populate_foo() functions.
drivers/platform/x86/dell-wmi-enum-attributes.c line 154
Quoted 6 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +6
-0+int i, next_obj; + +if (retval) + goto out; + +mutex_lock (&wmi_priv.mutex);
It would be better to push this lock (and the unlock) up into init_dell_bios_attrib_wmi() this way we can ensure that none of the functions which take the lock can run before we are completely done with initializing and registering all
the various sysfs attributes.
This lock/unlock can then also be removed from the other populate_foo() functions.
Quoted 44 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +44
-0+strncpy_attr (enumeration_data[instance_id].attribute_name, + enumeration_obj[ATTR_NAME ].string.pointer); +strncpy_attr (enumeration_data[instance_id].display_name_language_code, + enumeration_obj[DISPL_NAME_LANG_CODE ].string.pointer); +strncpy_attr (enumeration_data[instance_id].display_name, + enumeration_obj[DISPLAY_NAME ].string.pointer); +strncpy_attr (enumeration_data[instance_id].default_value, + enumeration_obj[DEFAULT_VAL ].string.pointer); +strncpy_attr (enumeration_data[instance_id].current_value, + enumeration_obj[CURRENT_VAL ].string.pointer); +strncpy_attr (enumeration_data[instance_id].modifier, + enumeration_obj[MODIFIER ].string.pointer); + + next_obj =MODIFIER +1 ; + + enumeration_data[instance_id].value_modifier_count = + (uintptr_t )enumeration_obj[next_obj].string.pointer; + +for (i =0 ; i < enumeration_data[instance_id].value_modifier_count; i++) { +strcat (enumeration_data[instance_id].value_modifier, + enumeration_obj[++next_obj].string.pointer); +strcat (enumeration_data[instance_id].value_modifier,";" ); + } + + enumeration_data[instance_id].possible_values_count = + (uintptr_t ) enumeration_obj[++next_obj].string.pointer; + +for (i =0 ; i < enumeration_data[instance_id].possible_values_count; i++) { +strcat (enumeration_data[instance_id].possible_values, + enumeration_obj[++next_obj].string.pointer); +strcat (enumeration_data[instance_id].possible_values,";" ); + } +strncpy_attr (enumeration_data[instance_id].type,"enumeration" ); +mutex_unlock (&wmi_priv.mutex); + +out: +return retval; +} + +/** +* exit_enum_attributes() - Clear all attribute data +* +* Clears all data allocated for this group of attributes +**/
drivers/platform/x86/dell-wmi-enum-attributes.c line 208
Quoted 10 lines
drivers/platform/x86/dell-wmi-enum-attributes.c new file +10
-0+void exit_enum_attributes (void ) +{ +struct kobject *pos, *next; + +list_for_each_entry_safe (pos, next, &wmi_priv.main_dir_kset->list, entry) { +/* this removes only enumeration atribute group under main_dir_kset */ +sysfs_remove_group (pos, &enumeration_attr_group); + } +kfree (enumeration_data); +}
As mentioned in the v2 thread I would prefer for this to be done differently (for all exit_foo_attributes functions).
<snip>
Quoted 54 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +48
-0@@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Functions corresponding to password object type attributes under BIOS Password Object GUID for +* use with dell-wmi-sysman +* +* Copyright (c) 2020 Dell Inc. +*/ + +#include "dell-wmi-sysman-attributes.h" + +enum po_properties {IS_PASS_SET =1 ,MIN_PASS_LEN ,MAX_PASS_LEN }; + +/* kept variable names same as in sysfs file name for sysfs_show macro definition */ +struct po_data { +char attribute_name[MAX_BUFF ]; +int is_password_set; +int min_password_length; +int max_password_length; +char type[MAX_BUFF ]; +}; + +static struct po_data *po_data; +static int po_instances_count; +get_instance_id (po); + +static ssize_t is_password_set_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) +{ +int instance_id =get_po_instance_id (kobj); + +if (instance_id >=0 ) { +union acpi_object *obj; + +/* need to use specific instance_id and guid combination to get right data */ + obj =get_wmiobj_pointer (instance_id,DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID ); +if (!obj) +return -AE_ERROR ; + po_data[instance_id].is_password_set = + (uintptr_t )obj->package.elements[IS_PASS_SET ].string.pointer; +kfree (obj); +return sprintf (buf,"%d\n" , po_data[instance_id].is_password_set); + } +return -EIO ; +} + +struct kobj_attribute po_is_pass_set = +__ATTR_RO (is_password_set); + +static ssize_t current_password_store(struct kobject *kobj,
drivers/platform/x86/dell-wmi-passobj-attributes.c line 58
Quoted 10 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +10
-0+struct kobj_attribute *attr, + const char *buf, size_t count) +{ + char *p = memchr(buf, '\n', count); +int ret; + +if (p !=NULL ) + *p ='\0' ; +if (strlen (buf) >MAX_BUFF ) +return -EINVAL ;
This check fails to take strlen(buf) == MAX_BUFF into account, in that case the strncpy below:
drivers/platform/x86/dell-wmi-passobj-attributes.c line 61
Quoted 3 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +3
-0+ +if (strcmp (kobj->name,"Admin" ) ==0 ) +strncpy (wmi_priv.current_admin_password, buf, (strlen (buf) +1 ));
Will write MAX_BUFF + 1 bytes to wmi_priv.current_admin_password !
Looking at the string handling in this driver in general, I am not really happy with it.
It seems that strncpy is used everywhere and strncpy is a horrible function, which sreally should never be used. The reason for this is that the source string having a length greater then the passed in buffer-length will result in the destination buffer not being 0 terminated. Now sometimes that is a feature, but in that case you should probably use memcpy to make it clear that you expect the string to not be 0 terminated.
In other cases using strlcpy is better since it guarantees 0 termination (truncating the input to fit in the destination-buffer).
Now I see that you try to correctly deal with strncpy-s nastiness everywhere, but please just don't use it all.
Not using strncpy at all is much better.
A lot of the strncpy usage is hidden in:
strncpy_attr(char *dest, char *src)
{
size_t len = strlen(src) + 1;
if (len > 1 && len < MAX_BUFF)
strncpy(dest, src, len);
}Why is there no warning printed when the source string is too long ? Now we just quietly throw away the data, which seems undesirable.
Also wouldn't truncating the data to fit in MAX_BUFF be better? (honest question, I do not know which option is better)
Quoted 9 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +9
-0+if (strcmp (kobj->name,"System" ) ==0 ) +strncpy (wmi_priv.current_system_password, buf, (strlen (buf) +1 )); +return ret ? ret : count; +} + +struct kobj_attribute po_current_password = +__ATTR_WO (current_password); + +static ssize_t new_password_store(struct kobject *kobj,
drivers/platform/x86/dell-wmi-passobj-attributes.c line 80
Quoted 10 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +10
-0+struct kobj_attribute *attr, + const char *buf, size_t count) +{ + char *p = memchr(buf, '\n', count); +int ret; + +if (p !=NULL ) + *p ='\0' ; +if (strlen (buf) >MAX_BUFF ) +return -EINVAL ;
Same issue with the length check.
Quoted 112 lines
drivers/platform/x86/dell-wmi-passobj-attributes.c new file +85
-0+ + ret =set_new_password (kobj->name, buf); +return ret ? ret : count; +} + +struct kobj_attribute po_new_password = +__ATTR_WO (new_password); + +attribute_n_property_show (min_password_length, po); +struct kobj_attribute po_min_pass_length = +__ATTR_RO (min_password_length); + +attribute_n_property_show (max_password_length, po); +struct kobj_attribute po_max_pass_length = +__ATTR_RO (max_password_length); + +attribute_s_property_show (type, po); +struct kobj_attribute po_type = +__ATTR_RO (type); + +static struct attribute *po_attrs[] = { + &po_is_pass_set.attr, + &po_min_pass_length.attr, + &po_max_pass_length.attr, + &po_current_password.attr, + &po_new_password.attr, + &po_type.attr, +NULL , +}; + +static const struct attribute_group po_attr_group = { + .attrs = po_attrs, +}; + +int alloc_po_data (void ) +{ +int ret =0 ; + + po_instances_count =get_instance_count (DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID ); + po_data =kzalloc ((sizeof (struct po_data ) * po_instances_count),GFP_KERNEL ); +if (!po_data) + ret = -ENOMEM ; +return ret; +} + +/** +* populate_po_data() - Populate all properties of an instance under password object attribute +* @po_obj: ACPI object with password object data +* @instance_id: The instance to enumerate +* @attr_name_kobj: The parent kernel object +**/ +int populate_po_data (union acpi_object *po_obj,int instance_id,struct kobject *attr_name_kobj) +{ +int retval =sysfs_create_group (attr_name_kobj, &po_attr_group); + +if (retval) + goto out; + +mutex_lock (&wmi_priv.mutex); +strncpy_attr (po_data[instance_id].attribute_name, po_obj[ATTR_NAME ].string.pointer); + po_data[instance_id].is_password_set = (uintptr_t )po_obj[IS_PASS_SET ].string.pointer; + po_data[instance_id].min_password_length = (uintptr_t )po_obj[MIN_PASS_LEN ].string.pointer; + po_data[instance_id].max_password_length = (uintptr_t ) po_obj[MAX_PASS_LEN ].string.pointer; +strncpy_attr (po_data[instance_id].type,"password_object" ); +mutex_unlock (&wmi_priv.mutex); + +out: +return retval; +} + +/** +* exit_po_attributes() - Clear all attribute data +* +* Clears all data allocated for this group of attributes +**/ +void exit_po_attributes (void ) +{ +struct kobject *pos, *next; + +list_for_each_entry_safe (pos, next, &wmi_priv.password_dir_kset->list, entry) { +/* this removes only enumeration atribute group under main_dir_kset */ +sysfs_remove_group (pos, &po_attr_group); + } +kfree (po_data); +}drivers/platform/x86/dell-wmi-passwordattr-interface.c new file +21
-0@@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Functions corresponding to SET password methods under BIOS attributes interface GUID +* +* Copyright (c) 2020 Dell Inc. +*/ + +#include <linux/nls.h> +#include <linux/wmi.h> +#include "dell-wmi-sysman-attributes.h" + +static int call_password_interface (struct wmi_device *wdev,char *in_args,size_t size) +{ +struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input; +union acpi_object *obj; +acpi_status status; +int ret = -EIO ; + + input.length = (acpi_size ) size; + input.pointer = in_args;
drivers/platform/x86/dell-wmi-passwordattr-interface.c line 31
Quoted 10 lines
drivers/platform/x86/dell-wmi-passwordattr-interface.c new file +10
-0+ status =wmidev_evaluate_method (wdev,0 ,1 , &input, &output); +if (ACPI_FAILURE (status)) +return -EIO ; + obj = (union acpi_object *)output.pointer; +if (obj->type ==ACPI_TYPE_INTEGER ) + ret = obj->integer.value; + +kfree (output.pointer); +/* let userland know it may need to check is_password_set again */ +kobject_uevent (&wdev->dev.kobj,KOBJ_CHANGE );
Hmm, I see so there is more then one boolean for user-space to monitor.
I guess that in that case udev change events might make sense. That would also be easier to describe in the sysfs API, we can just say that if anything changes a udev change event is send.
Note you should still make sure to only do the other kobject_uevent() call on the first change of pending_changes from 0 -> 1, after that it does not change, so there is no need to spam userspace with more uevents.
Regards,
Hans
Quoted 1 line · Hans de Goede
On 9/17/20 8:55 AM, Divya Bharathi wrote:
...
Quoted 14 lines
Now I see that you try to correctly deal with strncpy-s nastiness everywhere, but please just don't use it all.
Not using strncpy at all is much better.A lot of the strncpy usage is hidden in:
strncpy_attr(char *dest, char *src){ size_t len = strlen(src) + 1; if (len > 1 && len < MAX_BUFF) strncpy(dest, src, len); }
Quoted 6 lines
Why is there no warning printed when the source string is too long ? Now we just quietly throw away the data, which seems undesirable.
Also wouldn't truncating the data to fit in
MAX_BUFFbe better? (honest question, I do not know which option is better)
And don't forget new compiler warning if it can prove that string will be NUL-terminated.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 1 line · Hans de Goede
On 9/17/20 8:55 AM, Divya Bharathi wrote:
...
Quoted 18 lines
Now I see that you try to correctly deal with strncpy-s nastiness everywhere, but please just don't use it all.
Not using strncpy at all is much better.A lot of the strncpy usage is hidden in:
strncpy_attr(char *dest, char *src){ size_t len = strlen(src) + 1; if (len > 1 && len < MAX_BUFF) strncpy(dest, src, len); }Why is there no warning printed when the source string is too long ? Now we just quietly throw away the data, which seems undesirable.
Quoted 5 lines
Quoted 2 lines
Also wouldn't truncating the data to fit in
MAX_BUFFbe better? (honest question, I do not know which option is better)And don't forget new compiler warning if it can prove that string will be NUL-terminated.
can -> can't
Signature · 2 lines
With Best Regards, Andy Shevchenko