Skip to contentSkip to conversation

Introduction of HP-BIOSCFG driver

PATCH Superseded Jorge Lopez 2 participants 17 messages Dec 2, 2022 – Jan 30, 2023 1 message not in the archive

Subsystems (4)

v5 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v5 cover Introduction of HP-BIOSCFG driver

Version 5 restructures the patches submitted in previous versions. Earlier hp-bioscfg patches were squashed together before creating the new split.

Version 5.0 breaks down the changes into 5 patches

The driver files were broken down in 5 patches of 3 files each with exception of patch 1/5

Jorge Lopez (5):
Introduction of HP-BIOSCFG driver (1)
Introduction of HP-BIOSCFG driver (2)
Introduction of HP-BIOSCFG driver (3)
Introduction of HP-BIOSCFG driver (4)
Introduction of HP-BIOSCFG driver (5)

 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |    6 +
 drivers/platform/x86/hp/Kconfig               |   16 +
 drivers/platform/x86/hp/Makefile              |    1 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  283 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1066 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  673 +++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       |  499 ++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        |  450 +++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    |  549 +++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |   51 +
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  |  631 ++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     |  419 +++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     |  425 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 ++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  149 +++
 17 files changed, 6430 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/sureadmin-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/5 Introduction of HP-BIOSCFG driver (1)

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../testing/sysfs-class-firmware-attributes   | 181 +++++++++++++++++-
 MAINTAINERS                                   |   6 +
 drivers/platform/x86/hp/Kconfig               |  16 ++
 drivers/platform/x86/hp/Makefile              |   1 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |  19 ++
 5 files changed, 221 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile
Documentation/ABI/testing/sysfs-class-firmware-attributes +179 -2
index 4cdba3477176..da8e06d9bb43 100644
@@ -22,6 +22,13 @@ Description:
 			- integer: a range of numerical values
 			- string
 
+		HP specific types
+		-----------------
+			- ordered-list - a set of ordered list valid values
+			- sure-admin
+			- sure-start
+
+
 		All attribute types support the following values:
 
 		current_value:
@@ -126,6 +133,67 @@ Description:
 					value will not be effective through sysfs until this rule is
 					met.
 
+		HP specific class extensions
+		------------------------------
+
+		On HP systems the following additional attributes are available:
+
+		"ordered-list"-type specific properties:
+
+		elements:
+					A file that can be read to obtain the possible
+					list of values of the <attr>. Values are separated using
+					semi-colon (``;``). The order individual elements are listed
+					according to their priority.  An Element listed first has the
+					hightest priority. Writing the list in a different order to
+					current_value alters the priority order for the particular
+					attribute.
+
+		"sure-admin"-type specific properties:
+
+		settings:
+					A file associated with Sure Admin. BIOS settings can
+					be read or written through the Sure Admin settings file in sysfs.
+
+					[BIOS setting],[new value],[auth token]
+
+					Sample settings reported data
+
+					{
+						"Class": "HPBIOS_BIOSEnumeration",
+						"Name": "USB Storage Boot",
+						"Path": "\\Advanced\\Boot Options",
+						"IsReadOnly": 0,
+						...
+						"Value": "Enable",
+						"Size": 2,
+						"PossibleValues": [
+							"Disable",
+							"Enable"
+							]
+					}
+
+					This file can also be written to in order to update
+					the value sof a <attr> using a CMSL generated payload.
+					For example:
+
+					<attr>,[value],[CMSL generated payload]
+
+		"sure-start"-type specific properties:
+
+		audit_log_entries:
+					A read-only file that returns the events in the log.
+
+					Audit log entry format
+
+					Byte 0-15:   Requested Audit Log entry  (Each Audit log is 16 bytes)
+					Byte 16-127: Unused
+
+		audit_log_entry_count:
+					A read-only file that returns the number of existing audit log events available to be read.
+
+					[No of entries],[log entry size],[Max number of entries supported]
+
 What:		/sys/class/firmware-attributes/*/authentication/
 Date:		February 2021
 KernelVersion:	5.11
@@ -206,7 +274,7 @@ Description:
 		Drivers may emit a CHANGE uevent when a password is set or unset
 		userspace may check it again.
 
-		On Dell and Lenovo systems, if Admin password is set, then all BIOS attributes
+		On Dell, Lenovo, and HP systems, if Admin password is set, then all BIOS attributes
 		require password validation.
 		On Lenovo systems if you change the Admin password the new password is not active until
 		the next boot.
@@ -296,6 +364,15 @@ Description:
 						echo "signature" > authentication/Admin/signature
 						echo "password" > authentication/Admin/certificate_to_password
 
+		HP specific class extensions
+		--------------------------------
+
+		On HP systems the following additional settings are available:
+
+		role: enhanced-bios-auth:
+					This role is specific to Secure Platform Management (SPM) attribute.
+					It requires configuring an endorsement (kek) and signing certificate (sk).
+
 
 What:		/sys/class/firmware-attributes/*/attributes/pending_reboot
 Date:		February 2021
@@ -311,7 +388,7 @@ Description:
 			==	=========================================
 			0	All BIOS attributes setting are current
 			1	A reboot is necessary to get pending BIOS
-			        attribute changes applied
+				attribute changes applied
 			==	=========================================
 
 		Note, userspace applications need to follow below steps for efficient
@@ -364,3 +441,103 @@ Description:
 		use it to enable extra debug attributes or BIOS features for testing purposes.
 
 		Note that any changes to this attribute requires a reboot for changes to take effect.
+
+
+		HP specific class extensions
+		--------------------------------
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/kek
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'kek' is a write-only file that can be used to configure the
+		RSA public key that will be used by the BIOS to verify
+		signatures when setting the signing key.  When written,
+		the bytes should correspond to the KEK certificate
+		(x509 .DER format containing an OU).  The size of the
+		certificate must be less than or equal to 4095 bytes.
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/sk
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'sk' is a write-only file that can be used to configure the RSA
+		public key that will be used by the BIOS to verify signatures
+		when configuring BIOS settings and security features.  When
+		written, the bytes should correspond to the modulus of the
+		public key.  The exponent is assumed to be 0x10001.
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/status
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'status' is a read-only file that returns ASCII text reporting
+		the status information.
+
+		  State:  Not Provisioned / Provisioned / Provisioning in progress
+		  Version:  Major.   Minor
+		  Feature Bit Mask: <16-bit unsigned number display in hex>
+		  SPM Counter: <16-bit unsigned number display in base 10>
+		  Signing Key Public Key Modulus (base64):
+		  KEK Public Key Modulus (base64):
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/statusbin
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'statusbin' is a read-only file that returns identical status
+		information reported by 'status' file in binary format.
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Admin/settings
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'settings' is a file associated with Sure Admin. BIOS settings can
+		be read or written through the Sure Admin settings file in sysfs.
+
+		Expected data format to update BIOS setting
+
+		  [BIOS setting],[new value],[auth token]
+
+		Sample settings reported data
+
+		  {
+			  "Class": "HPBIOS_BIOSEnumeration",
+			  "Name": "USB Storage Boot",
+			  "Path": "\\Advanced\\Boot Options",
+			  "IsReadOnly": 0,
+			  ...
+			  "Value": "Enable",
+			  "Size": 2,
+			  "PossibleValues": [
+				"Disable",
+				"Enable"
+				]
+		  }
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_entry_count
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	audit_log_entry_count is a read-only file that returns the
+		number of existing audit log events available to be read.
+
+		  [No of entries],[log entry size],[Max number of entries supported]
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_entries
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	audit_log_entries is a read-only file that returns the events
+		in the log.
+
+		Audit log entry format
+
+		  Byte 0-15:   Requested Audit Log entry  (Each Audit log is 16 bytes)
+		  Byte 16-127: Unused
MAINTAINERS +6 -0
index 893c63e8beef..6cc9dd0c9ec2 100644
@@ -9363,6 +9363,12 @@ S:	Obsolete
 W:	http://w1.fi/hostap-driver.html
 F:	drivers/net/wireless/intersil/hostap/
 
+HP BIOSCFG DRIVER
+M:	Jorge Lopez <[email protected]>
+S:	Maintained
+L:      [email protected]
+F:	drivers/platform/x86/hp/hp-bioscfg/
+
 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
 L:	[email protected]
 S:	Orphan
drivers/platform/x86/hp/Kconfig +16 -0
index ae165955311c..7fef4f12e498 100644
@@ -60,4 +60,20 @@ config TC1100_WMI
 	  This is a driver for the WMI extensions (wireless and bluetooth power
 	  control) of the HP Compaq TC1100 tablet.
 
+config HP_BIOSCFG
+	tristate "HP BIOS Configuration Driver"
+	default m
+	depends on ACPI_WMI
+	select NLS
+	select FW_ATTR_CLASS
+	help
+	  This driver enables administrators to securely manage BIOS settings
+	  using digital certificates and public-key cryptography that eliminate
+	  the need for passwords for both remote and local management. It supports
+	  changing BIOS settings on many HP 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 hp-bioscfg.
+
 endif # X86_PLATFORM_DRIVERS_HP
drivers/platform/x86/hp/Makefile +1 -0
index db1eed4cd7c7..e4f908a61acf 100644
@@ -8,3 +8,4 @@
 obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
 obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
 obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
+obj-$(CONFIG_HP_BIOSCFG)	+= hp-bioscfg/
drivers/platform/x86/hp/hp-bioscfg/Makefile new file +19 -0
new file mode 100644
index 000000000000..cc1a613f9223
@@ -0,0 +1,19 @@
+obj-$(CONFIG_HP_BIOSCFG) := hp-bioscfg.o
+
+hp-bioscfg-objs := bioscfg.o	\
+	enum-attributes.o	\
+	int-attributes.o	\
+	string-attributes.o	\
+	passwdobj-attributes.o	\
+	biosattr-interface.o	\
+	passwdattr-interface.o	\
+	ordered-attributes.o	\
+	surestart-attributes.o	\
+	spmobj-attributes.o	\
+	sureadmin-attributes.o
+
+default:
+	make -C /lib/modules/`uname -r`/build M=$(PWD) hp-bioscfg.ko
+
+clean:
+	make -C /lib/modules/`uname -r`/build M=$(PWD) clean
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/5] Introduction of HP-BIOSCFG driver (1)

Hi Jorge,

Quoted 48 lines · Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

Quoted 6 lines
---
 .../testing/sysfs-class-firmware-attributes   | 181 +++++++++++++++++-
 MAINTAINERS                                   |   6 +
 drivers/platform/x86/hp/Kconfig               |  16 ++
 drivers/platform/x86/hp/Makefile              |   1 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |  19 ++

This patch really should be the last patch in the series since the Makefile points to a bunch of files which don't exist until the other patches are merged.

Quoted 30 lines
 5 files changed, 221 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile
Documentation/ABI/testing/sysfs-class-firmware-attributes +12 -0
index 4cdba3477176..da8e06d9bb43 100644
@@ -22,6 +22,13 @@ Description:
 			- integer: a range of numerical values
 			- string
 
+		HP specific types
+		-----------------
+			- ordered-list - a set of ordered list valid values
+			- sure-admin
+			- sure-start
+
+
 		All attribute types support the following values:
 
 		current_value:
@@ -126,6 +133,67 @@ Description:
 					value will not be effective through sysfs until this rule is
 					met.
 
+		HP specific class extensions
+		------------------------------
+
+		On HP systems the following additional attributes are available:
+

Documentation/ABI/testing/sysfs-class-firmware-attributes Description: · line 150

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +10 -0
+		"ordered-list"-type specific properties:
+
+		elements:
+					A file that can be read to obtain the possible
+					list of values of the <attr>. Values are separated using
+					semi-colon (``;``). The order individual elements are listed
+					according to their priority.  An Element listed first has the
+					hightest priority. Writing the list in a different order to
+					current_value alters the priority order for the particular
+					attribute.

Ok, this new ordered-list type is fine.

Quoted 20 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +20 -0
+
+		"sure-admin"-type specific properties:
+
+		settings:
+					A file associated with Sure Admin. BIOS settings can
+					be read or written through the Sure Admin settings file in sysfs.
+
+					[BIOS setting],[new value],[auth token]
+
+					Sample settings reported data
+
+					{
+						"Class": "HPBIOS_BIOSEnumeration",
+						"Name": "USB Storage Boot",
+						"Path": "\\Advanced\\Boot Options",
+						"IsReadOnly": 0,
+						...
+						"Value": "Enable",
+						"Size": 2,
+						"PossibleValues": [

Documentation/ABI/testing/sysfs-class-firmware-attributes Description: · line 180

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +10 -0
+							"Disable",
+							"Enable"
+							]
+					}
+
+					This file can also be written to in order to update
+					the value sof a <attr> using a CMSL generated payload.
+					For example:
+
+					<attr>,[value],[CMSL generated payload]

This is basically a run-around around the actual firmware attributes API, so NACK for this.

Looking at how sure_admin_settings_write() encodes things I don't see any difference between how auth-tokens/CFML-payloads are handled vs regular passwords inside hp_set_attribute().

Except for the BEAM_PREFIX thing, which can be added to calculate_security_buffer() / populate_security_buffer() too and in that case all 3 of the following should simply work, taking a boot-delay integer attribute as example:

echo "password" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

echo "auth-token" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

cat csml-payload.file > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

The only reason why this would not work is if things may get bigger then the size of a single memory page (bigger then 4096 bytes).

But in that case you should just change the code implementing current_password to use the bin_attribute interface and replace the static buffer for storing it with a pointer to kmalloc-ed memory, which is NULL when the password is not set.

This will also remove a lot of finicky parsing which is currently done inside sure_admin_settings_write()

###

As for the reading which returns a large large list of data blocks like this:

					{
						"Class": "HPBIOS_BIOSEnumeration",
						"Name": "USB Storage Boot",
						"Path": "\\Advanced\\Boot Options",
						"IsReadOnly": 0,
						...
						"Value": "Enable",
						"Size": 2,
						"PossibleValues": [
							"Disable",
							"Enable"
							]
					}

This sort of thing really does not belong in the kernel. I see that this does export some info which is not available in the standard firmware-attributes interface, like path and prerequisites and physical-presence.

If you want to export that info please just add extra HP specific attributes to the integer, string, etc. attributes sets. Like how Dell has the dell_modifier thing.

And if you have some consumers for data in the above format then give your users a shell or python script or small C program which uses the sysfs interface to output the information in the above format. Generating this format does not belong in the kernel.

Quoted 96 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +66 -2
+
+		"sure-start"-type specific properties:
+
+		audit_log_entries:
+					A read-only file that returns the events in the log.
+
+					Audit log entry format
+
+					Byte 0-15:   Requested Audit Log entry  (Each Audit log is 16 bytes)
+					Byte 16-127: Unused
+
+		audit_log_entry_count:
+					A read-only file that returns the number of existing audit log events available to be read.
+
+					[No of entries],[log entry size],[Max number of entries supported]
+
 What:		/sys/class/firmware-attributes/*/authentication/
 Date:		February 2021
 KernelVersion:	5.11
@@ -206,7 +274,7 @@ Description:
 		Drivers may emit a CHANGE uevent when a password is set or unset
 		userspace may check it again.
 
-		On Dell and Lenovo systems, if Admin password is set, then all BIOS attributes
+		On Dell, Lenovo, and HP systems, if Admin password is set, then all BIOS attributes
 		require password validation.
 		On Lenovo systems if you change the Admin password the new password is not active until
 		the next boot.
@@ -296,6 +364,15 @@ Description:
 						echo "signature" > authentication/Admin/signature
 						echo "password" > authentication/Admin/certificate_to_password
 
+		HP specific class extensions
+		--------------------------------
+
+		On HP systems the following additional settings are available:
+
+		role: enhanced-bios-auth:
+					This role is specific to Secure Platform Management (SPM) attribute.
+					It requires configuring an endorsement (kek) and signing certificate (sk).
+
 
 What:		/sys/class/firmware-attributes/*/attributes/pending_reboot
 Date:		February 2021
@@ -311,7 +388,7 @@ Description:
 			==	=========================================
 			0	All BIOS attributes setting are current
 			1	A reboot is necessary to get pending BIOS
-			        attribute changes applied
+				attribute changes applied
 			==	=========================================
 
 		Note, userspace applications need to follow below steps for efficient
@@ -364,3 +441,103 @@ Description:
 		use it to enable extra debug attributes or BIOS features for testing purposes.
 
 		Note that any changes to this attribute requires a reboot for changes to take effect.
+
+
+		HP specific class extensions
+		--------------------------------
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/kek
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'kek' is a write-only file that can be used to configure the
+		RSA public key that will be used by the BIOS to verify
+		signatures when setting the signing key.  When written,
+		the bytes should correspond to the KEK certificate
+		(x509 .DER format containing an OU).  The size of the
+		certificate must be less than or equal to 4095 bytes.
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/sk
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'sk' is a write-only file that can be used to configure the RSA
+		public key that will be used by the BIOS to verify signatures
+		when configuring BIOS settings and security features.  When
+		written, the bytes should correspond to the modulus of the
+		public key.  The exponent is assumed to be 0x10001.
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/status
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'status' is a read-only file that returns ASCII text reporting
+		the status information.
+
+		  State:  Not Provisioned / Provisioned / Provisioning in progress
+		  Version:  Major.   Minor
+		  Feature Bit Mask: <16-bit unsigned number display in hex>
+		  SPM Counter: <16-bit unsigned number display in base 10>

Documentation/ABI/testing/sysfs-class-firmware-attributes Description: · line 492

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +10 -0
+		  Signing Key Public Key Modulus (base64):
+		  KEK Public Key Modulus (base64):
+
+
+What:		/sys/class/firmware-attributes/*/authentication/SPM/statusbin
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'statusbin' is a read-only file that returns identical status
+		information reported by 'status' file in binary format.

The above is all fine.

The sure-admin thing needs to go away as already mentioned.

Quoted 41 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +41 -0
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Admin/settings
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	'settings' is a file associated with Sure Admin. BIOS settings can
+		be read or written through the Sure Admin settings file in sysfs.
+
+		Expected data format to update BIOS setting
+
+		  [BIOS setting],[new value],[auth token]
+
+		Sample settings reported data
+
+		  {
+			  "Class": "HPBIOS_BIOSEnumeration",
+			  "Name": "USB Storage Boot",
+			  "Path": "\\Advanced\\Boot Options",
+			  "IsReadOnly": 0,
+			  ...
+			  "Value": "Enable",
+			  "Size": 2,
+			  "PossibleValues": [
+				"Disable",
+				"Enable"
+				]
+		  }
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_entry_count
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	audit_log_entry_count is a read-only file that returns the
+		number of existing audit log events available to be read.
+
+		  [No of entries],[log entry size],[Max number of entries supported]
+
+
+What:		/sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_entries

Documentation/ABI/testing/sysfs-class-firmware-attributes Description: · line 543

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +10 -0
+Date:		March 29
+KernelVersion:	5.18
+Contact:	"Jorge Lopez" <[email protected]>
+Description:	audit_log_entries is a read-only file that returns the events
+		in the log.
+
+		Audit log entry format
+
+		  Byte 0-15:   Requested Audit Log entry  (Each Audit log is 16 bytes)
+		  Byte 16-127: Unused

This audit_log info is duplicate with the documentation already added for this above, please drop these entries.

Quoted 60 lines
MAINTAINERS +6 -0
index 893c63e8beef..6cc9dd0c9ec2 100644
@@ -9363,6 +9363,12 @@ S:	Obsolete
 W:	http://w1.fi/hostap-driver.html
 F:	drivers/net/wireless/intersil/hostap/
 
+HP BIOSCFG DRIVER
+M:	Jorge Lopez <[email protected]>
+S:	Maintained
+L:      [email protected]
+F:	drivers/platform/x86/hp/hp-bioscfg/
+
 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
 L:	[email protected]
 S:	Orphan
drivers/platform/x86/hp/Kconfig +16 -0
index ae165955311c..7fef4f12e498 100644
@@ -60,4 +60,20 @@ config TC1100_WMI
 	  This is a driver for the WMI extensions (wireless and bluetooth power
 	  control) of the HP Compaq TC1100 tablet.
 
+config HP_BIOSCFG
+	tristate "HP BIOS Configuration Driver"
+	default m
+	depends on ACPI_WMI
+	select NLS
+	select FW_ATTR_CLASS
+	help
+	  This driver enables administrators to securely manage BIOS settings
+	  using digital certificates and public-key cryptography that eliminate
+	  the need for passwords for both remote and local management. It supports
+	  changing BIOS settings on many HP 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 hp-bioscfg.
+
 endif # X86_PLATFORM_DRIVERS_HP
drivers/platform/x86/hp/Makefile +1 -0
index db1eed4cd7c7..e4f908a61acf 100644
@@ -8,3 +8,4 @@
 obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
 obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
 obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
+obj-$(CONFIG_HP_BIOSCFG)	+= hp-bioscfg/
drivers/platform/x86/hp/hp-bioscfg/Makefile new file +3 -0
new file mode 100644
index 000000000000..cc1a613f9223
@@ -0,0 +1,19 @@
+obj-$(CONFIG_HP_BIOSCFG) := hp-bioscfg.o
+
+hp-bioscfg-objs := bioscfg.o	\

drivers/platform/x86/hp/hp-bioscfg/Makefile line 13

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/Makefile new file +10 -0
+	enum-attributes.o	\
+	int-attributes.o	\
+	string-attributes.o	\
+	passwdobj-attributes.o	\
+	biosattr-interface.o	\
+	passwdattr-interface.o	\
+	ordered-attributes.o	\
+	surestart-attributes.o	\
+	spmobj-attributes.o	\
+	sureadmin-attributes.o

Everything below here:

drivers/platform/x86/hp/hp-bioscfg/Makefile line 19

Quoted 6 lines
drivers/platform/x86/hp/hp-bioscfg/Makefile new file +6 -0
+
+default:
+	make -C /lib/modules/`uname -r`/build M=$(PWD) hp-bioscfg.ko
+
+clean:
+	make -C /lib/modules/`uname -r`/build M=$(PWD) clean

Does not belong here, please drop it.

Regards,

Hans

#3 lore raw

Re: [PATCH v5 1/5] Introduction of HP-BIOSCFG driver (1)

Hi Hans,

Quoted 36 lines
Quoted 21 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +20 -0
+
+             "sure-admin"-type specific properties:
+
+             settings:
+                                     A file associated with Sure Admin. BIOS settings can
+                                     be read or written through the Sure Admin settings file in sysfs.
+
+                                     [BIOS setting],[new value],[auth token]
+
+                                     Sample settings reported data
+
+                                     {
+                                             "Class": "HPBIOS_BIOSEnumeration",
+                                             "Name": "USB Storage Boot",
+                                             "Path": "\\Advanced\\Boot Options",
+                                             "IsReadOnly": 0,
+                                             ...
+                                             "Value": "Enable",
+                                             "Size": 2,
+                                             "PossibleValues": [

Documentation/ABI/testing/sysfs-class-firmware-attributes Description: · line 180

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-firmware-attributes +10 -0
+                                                     "Disable",
+                                                     "Enable"
+                                                     ]
+                                     }
+
+                                     This file can also be written to in order to update
+                                     the value sof a <attr> using a CMSL generated payload.
+                                     For example:
+
+                                     <attr>,[value],[CMSL generated payload]

This is basically a run-around around the actual firmware attributes API, so NACK for this.

Quoted 3 lines

Looking at how sure_admin_settings_write() encodes things I don't see any difference between how auth-tokens/CFML-payloads are handled vs regular passwords inside hp_set_attribute().

Yes. The handling of auth-tokens/CMSL-payloads vs regular passwords are similar with the exception of their size. auth-tokens/CMSL-payloads are in the size larger than 64 bytes while passwords are limited to 64 bytes.

Quoted 5 lines

Except for the BEAM_PREFIX thing, which can be added to calculate_security_buffer() / populate_security_buffer() too and in that case all 3 of the following should simply work, taking a boot-delay integer attribute as example:

Quoted 8 lines

echo "password" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

echo "auth-token" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

cat csml-payload.file > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

Last two cases cannot be handled by passing auth-token/CMSL payloads values to the current password due to their possible sizes. Passwords are limited to 64 bytes in size while auth-tokens/CFML-payloads are in the size larger than 64 bytes Here are examples of CMSL flow for your records. Most of generated payloads are stored remotely and signed by customer to ensure the data
integrity. The full benefit of this process is better represented
when configuring Security settings in BIOS. (Sure Run, Sure Start, Sure Recovery, etc)
.
1. Customer generates a signed CMSL payload to set BIOS "USB Storage Boot" value to "Enable"

CMSL command:

New-HPSureAdminBIOSSettingValuePayload -Name "USB Storage Boot" -Value "Enable" -SigningKeyFile sk.pfx -SigningKeyPassword test

Generated payload:

{"timestamp":"2022-09-26T16:01:22.7887948-05:00","purpose":"hp:sureadmin:biossetting","Data":[123,10,32,32,34,78,97,109,101,34,58,32,34,85,83,66,32,83,116,111,114,97,103,101,32,66,111,111,116,34,44,10,32,32,34,86,97,108,117,101,34,58,32,34,69,110,97,98,108,101,34,44,10,32,32,34,65,117,116,104,83,116,114,105,110,103,34,58,32,34,60,66,69,65,77,47,62,65,83,65,65,68,65,65,65,73,120,77,121,89,119,72,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,68,85,78,87,111,74,67,117,122,51,73,69,71,57,75,51,80,113,107,103,121,76,52,108,100,119,83,67,79,69,65,83,47,98,108,68,122,111,116,47,105,77,43,86,103,122,90,77,69,116,43,48,75,87,75,78,103,119,89,99,86,102,121,97,70,56,99,104,102,57,85,47,86,82,106,51,52,122,112,53,111,43,85,112,97,119,97,116,106,50,74,103,115,97,105,104,113,54,90,53,84,48,101,49,114,56,78,80,109,69,105,119,103,113,118,77,51,108,97,86,83,98,116,101,66,112,80,81,88,119,102,66,56,101,105,112,119,120,104,121,67,68,65,85,111,118,69,113,82,51,84,71,79,54,109,101,75,119,71,100,73,104,72,103,102,50,112,72,75,90,50,107,47,66,116,104,97,98,110,115,118,78,77,114,98,74,69,103,76,72,76,121,87,84,119,98,76,74,87,108,101,106,112,71,121,47,70,100,83,105,74,114,101,66,114,81,115,114,106,90,113,100,76,75,72,90,71,117,108,52,70,108,43,117,47,72,102,107,48,119,121,81,69,106,121,97,99,51,52,57,105,90,55,97,104,49,72,56,50,85,97,50,49,55,109,74,51,88,56,87,113,80,111,50,86,72,65,85,57,71,102,47,113,107,97,85,101,75,76,84,97,75,87,101,121,122,116,68,109,105,68,98,115,114,47,86,51,51,106,114,101,67,88,65,65,109,120,68,76,73,73,66,103,83,88,79,82,82,117,98,80,53,113,80,78,69,53,67,76,120,104,119,61,61,34,10,125],"Meta1":null,"Meta2":null,"Meta3":null,"Meta4":null}

The application reads the CMSL payload and sends the command to the driver. The payload is translated to [BIOS setting], [Value], [Password || auth-token]

echo "USB Storage Boot,Enable,<BEAM/>ASAADAAANZ9AYwH/////////////////////64bPg7ygUv4xanoHIFrzME9mIsxeJh32fkhR7sgHpXdEHjetMXxNVhEK/twhhXhHS93kp9JpGhsr+J6AMKV2ldE99iJHo6ul1IxJQuBSxBoN1mf49Mm/ROCNll+IhsAn4ow+xlDwKQn2EzKtQc2Wf1eC646KPcl+ZCtiFhvLzXZrGSXsB2hJy0+IzegUPzLY6jaN0lYyQMtQ0KpcyGnK6xZSKCKfotygWawWY8BD3oewyrVLdKMGjrtX4HtHaeo5A9VVXVt89i7lZAmV3VkRtu70LEv240ue/SOhwrxGtydgNmtpV3dSn/ancnY4ONbTxBRiw8cifObEiNOidYzhpQ=="

Quoted 1 line

/sys/class/firmware-attributes/hp-bioscfg/attributes/Sure_Admin/settings'

As you can see, the auth-token "<BEAN/>.....==" portion varies in size depending on the signing certificate size used.

A method that can be used to address your comments and allow the driver to handle both auth-tokens and password using command

echo "auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

is adding an modifier to indicate if the input is a password or auth-token

For instance... using [Token] modifier to identify the data is an authentication token

echo "[token] auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

If the modifier is missing, the driver will treat the data as a password.

This new method will conform with the firmware class framework and provide the flexibility needed for HP solution.

Please advise.

Quoted 29 lines

The only reason why this would not work is if things may get bigger then the size of a single memory page (bigger then 4096 bytes).

But in that case you should just change the code implementing current_password to use the bin_attribute interface and replace the static buffer for storing it with a pointer to kmalloc-ed memory, which is NULL when the password is not set.

This will also remove a lot of finicky parsing which is currently done inside sure_admin_settings_write()

###

As for the reading which returns a large large list of data blocks like this:

                                        {
                                                "Class": "HPBIOS_BIOSEnumeration",
                                                "Name": "USB Storage Boot",
                                                "Path": "\\Advanced\\Boot Options",
                                                "IsReadOnly": 0,
                                                ...
                                                "Value": "Enable",
                                                "Size": 2,
                                                "PossibleValues": [
                                                        "Disable",
                                                        "Enable"
                                                        ]
                                        }
Quoted 1 line

This sort of thing really does not belong in the kernel.

I concur with your statement and behavior will be removed from driver code.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [PATCH v5 1/5] Introduction of HP-BIOSCFG driver (1)

Hi Mark,

Quoted 89 lines · Mark Pearson

Hi Jorge,

On Fri, Jan 20, 2023, at 4:58 PM, Jorge Lopez wrote:

Hi Hans,

<snip>

Yes. The handling of auth-tokens/CMSL-payloads vs regular passwords are similar with the exception of their size. auth-tokens/CMSL-payloads are in the size larger than 64 bytes while passwords are limited to 64 bytes.

Quoted 5 lines

Except for the BEAM_PREFIX thing, which can be added to calculate_security_buffer() / populate_security_buffer() too and in that case all 3 of the following should simply work, taking a boot-delay integer attribute as example:

Quoted 8 lines

echo "password" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

echo "auth-token" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

cat csml-payload.file > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

Last two cases cannot be handled by passing auth-token/CMSL payloads values to the current password due to their possible sizes. Passwords are limited to 64 bytes in size while auth-tokens/CFML-payloads are in the size larger than 64 bytes Here are examples of CMSL flow for your records. Most of generated payloads are stored remotely and signed by customer to ensure the data
integrity. The full benefit of this process is better represented
when configuring Security settings in BIOS. (Sure Run, Sure Start, Sure Recovery, etc)
.
1. Customer generates a signed CMSL payload to set BIOS "USB Storage Boot" value to "Enable"

CMSL command:

New-HPSureAdminBIOSSettingValuePayload -Name "USB Storage Boot" -Value "Enable" -SigningKeyFile sk.pfx -SigningKeyPassword test

Generated payload:

{"timestamp":"2022-09-26T16:01:22.7887948-05:00","purpose":"hp:sureadmin:biossetting","Data":[123,10,32,32,34,78,97,109,101,34,58,32,34,85,83,66,32,83,116,111,114,97,103,101,32,66,111,111,116,34,44,10,32,32,34,86,97,108,117,101,34,58,32,34,69,110,97,98,108,101,34,44,10,32,32,34,65,117,116,104,83,116,114,105,110,103,34,58,32,34,60,66,69,65,77,47,62,65,83,65,65,68,65,65,65,73,120,77,121,89,119,72,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,68,85,78,87,111,74,67,117,122,51,73,69,71,57,75,51,80,113,107,103,121,76,52,108,100,119,83,67,79,69,65,83,47,98,108,68,122,111,116,47,105,77,43,86,103,122,90,77,69,116,43,48,75,87,75,78,103,119,89,99,86,102,121,97,70,56,99,104,102,57,85,47,86,82,106,51,52,122,112,53,111,43,85,112,97,119,97,116,106,50,74,103,115,97,105,104,113,54,90,53,84,48,101,49,114,56,78,80,109,69,105,119,103,113,118,77,51,108,97,86,83,98,116,101,66,112,80,81,88,119,102,66,56,101,105,112,119,120,104,121,67,68,65,85,111,118,69,113,82,51,84,71,79,54,109,101,75,119,71,100,73,104,72,103,102,50,112,72,75,90,50,107,47,66,116,104,97,98,110,115,118,78,77,114,98,74,69,103,76,72,76,121,87,84,119,98,76,74,87,108,101,106,112,71,121,47,70,100,83,105,74,114,101,66,114,81,115,114,106,90,113,100,76,75,72,90,71,117,108,52,70,108,43,117,47,72,102,107,48,119,121,81,69,106,121,97,99,51,52,57,105,90,55,97,104,49,72,56,50,85,97,50,49,55,109,74,51,88,56,87,113,80,111,50,86,72,65,85,57,71,102,47,113,107,97,85,101,75,76,84,97,75,87,101,121,122,116,68,109,105,68,98,115,114,47,86,51,51,106,114,101,67,88,65,65,109,120,68,76,73,73,66,103,83,88,79,82,82,117,98,80,53,113,80,78,69,53,67,76,120,104,119,61,61,34,10,125],"Meta1":null,"Meta2":null,"Meta3":null,"Meta4":null}

The application reads the CMSL payload and sends the command to the driver. The payload is translated to [BIOS setting], [Value], [Password || auth-token]

echo "USB Storage Boot,Enable,<BEAM/>ASAADAAANZ9AYwH/////////////////////64bPg7ygUv4xanoHIFrzME9mIsxeJh32fkhR7sgHpXdEHjetMXxNVhEK/twhhXhHS93kp9JpGhsr+J6AMKV2ldE99iJHo6ul1IxJQuBSxBoN1mf49Mm/ROCNll+IhsAn4ow+xlDwKQn2EzKtQc2Wf1eC646KPcl+ZCtiFhvLzXZrGSXsB2hJy0+IzegUPzLY6jaN0lYyQMtQ0KpcyGnK6xZSKCKfotygWawWY8BD3oewyrVLdKMGjrtX4HtHaeo5A9VVXVt89i7lZAmV3VkRtu70LEv240ue/SOhwrxGtydgNmtpV3dSn/ancnY4ONbTxBRiw8cifObEiNOidYzhpQ=="

Quoted 1 line

/sys/class/firmware-attributes/hp-bioscfg/attributes/Sure_Admin/settings'

As you can see, the auth-token "<BEAN/>.....==" portion varies in size depending on the signing certificate size used.

A method that can be used to address your comments and allow the driver to handle both auth-tokens and password using command

echo "auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

is adding an modifier to indicate if the input is a password or auth-token

For instance... using [Token] modifier to identify the data is an authentication token

echo "[token] auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

If the modifier is missing, the driver will treat the data as a password.

This new method will conform with the firmware class framework and provide the flexibility needed for HP solution.

Please advise.

I don't know if this is helpful or not as I've not read your code in any detail and was just being nosy whilst skimming the mailing list posts - but I did similar for the Lenovo platforms recently. In our case we added a 'signature' sysfs entry under authentication/Admin that is used for what is (I think) the equivalent of 'auth-token' when certificate based authentication is enabled. We didn't try to re-use the password entry.

Quoted 8 lines

So if certificate authentication is enabled the user ends up doing:
echo "crypto-string" > authentication/Admin/signature
echo "value" > attribute/"setting"
and if password authentication is enabled
echo "password" > authentication/Admin/password
echo "value" > attribute/"setting"
and the thinklmi driver takes care of figuring out the rest to pass as WMI calls to the BIOS (for us this is done at init time and is only changed by a reboot). Note for completeness - we have a signature and a save_signature....for reasons of BIOS (sigh).

Thank you for your suggestion. Separating 'password' and signature
is a better approach and easier to implement since most of the supporting code is already implemented.

Quoted 2 lines

I'd also suggest that anything password/authentication related should go under the authentication directory to be consistent. This is what is in the sysfs-class-firmware-attributes document :)

Yes. SPM (auth-token), 'Setup Password' (admin), and 'Power On password' are listed under 'authentication' directory

Quoted 1 line

Mark

#6 lore raw

Re: [PATCH v5 1/5] Introduction of HP-BIOSCFG driver (1)

Hi,

Quoted 100 lines · Jorge Lopez

Hi Mark,

Quoted 89 lines · Mark Pearson

Hi Jorge,

On Fri, Jan 20, 2023, at 4:58 PM, Jorge Lopez wrote:

Hi Hans,

<snip>

Yes. The handling of auth-tokens/CMSL-payloads vs regular passwords are similar with the exception of their size. auth-tokens/CMSL-payloads are in the size larger than 64 bytes while passwords are limited to 64 bytes.

Quoted 5 lines

Except for the BEAM_PREFIX thing, which can be added to calculate_security_buffer() / populate_security_buffer() too and in that case all 3 of the following should simply work, taking a boot-delay integer attribute as example:

Quoted 8 lines

echo "password" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

echo "auth-token" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

cat csml-payload.file > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

Last two cases cannot be handled by passing auth-token/CMSL payloads values to the current password due to their possible sizes. Passwords are limited to 64 bytes in size while auth-tokens/CFML-payloads are in the size larger than 64 bytes Here are examples of CMSL flow for your records. Most of generated payloads are stored remotely and signed by customer to ensure the data
integrity. The full benefit of this process is better represented
when configuring Security settings in BIOS. (Sure Run, Sure Start, Sure Recovery, etc)
.
1. Customer generates a signed CMSL payload to set BIOS "USB Storage Boot" value to "Enable"

CMSL command:

New-HPSureAdminBIOSSettingValuePayload -Name "USB Storage Boot" -Value "Enable" -SigningKeyFile sk.pfx -SigningKeyPassword test

Generated payload:

{"timestamp":"2022-09-26T16:01:22.7887948-05:00","purpose":"hp:sureadmin:biossetting","Data":[123,10,32,32,34,78,97,109,101,34,58,32,34,85,83,66,32,83,116,111,114,97,103,101,32,66,111,111,116,34,44,10,32,32,34,86,97,108,117,101,34,58,32,34,69,110,97,98,108,101,34,44,10,32,32,34,65,117,116,104,83,116,114,105,110,103,34,58,32,34,60,66,69,65,77,47,62,65,83,65,65,68,65,65,65,73,120,77,121,89,119,72,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,68,85,78,87,111,74,67,117,122,51,73,69,71,57,75,51,80,113,107,103,121,76,52,108,100,119,83,67,79,69,65,83,47,98,108,68,122,111,116,47,105,77,43,86,103,122,90,77,69,116,43,48,75,87,75,78,103,119,89,99,86,102,121,97,70,56,99,104,102,57,85,47,86,82,106,51,52,122,112,53,111,43,85,112,97,119,97,116,106,50,74,103,115,97,105,104,113,54,90,53,84,48,101,49,114,56,78,80,109,69,105,119,103,113,118,77,51,108,97,86,83,98,116,101,66,112,80,81,88,119,102,66,56,101,105,112,119,120,104,121,67,68,65,85,111,118,69,113,82,51,84,71,79,54,109,101,75,119,71,100,73,104,72,103,102,50,112,72,75,90,50,107,47,66,116,104,97,98,110,115,118,78,77,114,98,74,69,103,76,72,76,121,87,84,119,98,76,74,87,108,101,106,112,71,121,47,70,100,83,105,74,114,101,66,114,81,115,114,106,90,113,100,76,75,72,90,71,117,108,52,70,108,43,117,47,72,102,107,48,119,121,81,69,106,121,97,99,51,52,57,105,90,55,97,104,49,72,56,50,85,97,50,49,55,109,74,51,88,56,87,113,80,111,50,86,72,65,85,57,71,102,47,113,107,97,85,101,75,76,84,97,75,87,101,121,122,116,68,109,105,68,98,115,114,47,86,51,51,106,114,101,67,88,65,65,109,120,68,76,73,73,66,103,83,88,79,82,82,117,98,80,53,113,80,78,69,53,67,76,120,104,119,61,61,34,10,125],"Meta1":null,"Meta2":null,"Meta3":null,"Meta4":null}

The application reads the CMSL payload and sends the command to the driver. The payload is translated to [BIOS setting], [Value], [Password || auth-token]

echo "USB Storage Boot,Enable,<BEAM/>ASAADAAANZ9AYwH/////////////////////64bPg7ygUv4xanoHIFrzME9mIsxeJh32fkhR7sgHpXdEHjetMXxNVhEK/twhhXhHS93kp9JpGhsr+J6AMKV2ldE99iJHo6ul1IxJQuBSxBoN1mf49Mm/ROCNll+IhsAn4ow+xlDwKQn2EzKtQc2Wf1eC646KPcl+ZCtiFhvLzXZrGSXsB2hJy0+IzegUPzLY6jaN0lYyQMtQ0KpcyGnK6xZSKCKfotygWawWY8BD3oewyrVLdKMGjrtX4HtHaeo5A9VVXVt89i7lZAmV3VkRtu70LEv240ue/SOhwrxGtydgNmtpV3dSn/ancnY4ONbTxBRiw8cifObEiNOidYzhpQ=="

Quoted 1 line

/sys/class/firmware-attributes/hp-bioscfg/attributes/Sure_Admin/settings'

As you can see, the auth-token "<BEAN/>.....==" portion varies in size depending on the signing certificate size used.

A method that can be used to address your comments and allow the driver to handle both auth-tokens and password using command

echo "auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

is adding an modifier to indicate if the input is a password or auth-token

For instance... using [Token] modifier to identify the data is an authentication token

echo "[token] auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

If the modifier is missing, the driver will treat the data as a password.

This new method will conform with the firmware class framework and provide the flexibility needed for HP solution.

Please advise.

I don't know if this is helpful or not as I've not read your code in any detail and was just being nosy whilst skimming the mailing list posts - but I did similar for the Lenovo platforms recently. In our case we added a 'signature' sysfs entry under authentication/Admin that is used for what is (I think) the equivalent of 'auth-token' when certificate based authentication is enabled. We didn't try to re-use the password entry.

Quoted 8 lines

So if certificate authentication is enabled the user ends up doing:
echo "crypto-string" > authentication/Admin/signature
echo "value" > attribute/"setting"
and if password authentication is enabled
echo "password" > authentication/Admin/password
echo "value" > attribute/"setting"
and the thinklmi driver takes care of figuring out the rest to pass as WMI calls to the BIOS (for us this is done at init time and is only changed by a reboot). Note for completeness - we have a signature and a save_signature....for reasons of BIOS (sigh).

Quoted 3 lines

Thank you for your suggestion. Separating 'password' and signature
is a better approach and easier to implement since most of the supporting code is already implemented.

Ok, using a separate signature file under authentication/Admin/signature (or something similar) for this is fine with me.

Regards,

Hans

#7 lore raw

Re: [PATCH v5 1/5] Introduction of HP-BIOSCFG driver (1)

Great, thanks!

Quoted 117 lines · Hans de Goede

Hi,

Quoted 100 lines · Jorge Lopez

Hi Mark,

Quoted 89 lines · Mark Pearson

Hi Jorge,

On Fri, Jan 20, 2023, at 4:58 PM, Jorge Lopez wrote:

Hi Hans,

<snip>

Yes. The handling of auth-tokens/CMSL-payloads vs regular passwords are similar with the exception of their size. auth-tokens/CMSL-payloads are in the size larger than 64 bytes while passwords are limited to 64 bytes.

Quoted 5 lines

Except for the BEAM_PREFIX thing, which can be added to calculate_security_buffer() / populate_security_buffer() too and in that case all 3 of the following should simply work, taking a boot-delay integer attribute as example:

Quoted 8 lines

echo "password" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

echo "auth-token" > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

cat csml-payload.file > /sys/class/firmware-attributes/hp-bioscfg/"Setup Password"/current_password echo 5 > /sys/class/firmware-attributes/hp-bioscfg/attributes/boot-delay/current_value

Last two cases cannot be handled by passing auth-token/CMSL payloads values to the current password due to their possible sizes. Passwords are limited to 64 bytes in size while auth-tokens/CFML-payloads are in the size larger than 64 bytes Here are examples of CMSL flow for your records. Most of generated payloads are stored remotely and signed by customer to ensure the data
integrity. The full benefit of this process is better represented
when configuring Security settings in BIOS. (Sure Run, Sure Start, Sure Recovery, etc)
.
1. Customer generates a signed CMSL payload to set BIOS "USB Storage Boot" value to "Enable"

CMSL command:

New-HPSureAdminBIOSSettingValuePayload -Name "USB Storage Boot" -Value "Enable" -SigningKeyFile sk.pfx -SigningKeyPassword test

Generated payload:

{"timestamp":"2022-09-26T16:01:22.7887948-05:00","purpose":"hp:sureadmin:biossetting","Data":[123,10,32,32,34,78,97,109,101,34,58,32,34,85,83,66,32,83,116,111,114,97,103,101,32,66,111,111,116,34,44,10,32,32,34,86,97,108,117,101,34,58,32,34,69,110,97,98,108,101,34,44,10,32,32,34,65,117,116,104,83,116,114,105,110,103,34,58,32,34,60,66,69,65,77,47,62,65,83,65,65,68,65,65,65,73,120,77,121,89,119,72,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,68,85,78,87,111,74,67,117,122,51,73,69,71,57,75,51,80,113,107,103,121,76,52,108,100,119,83,67,79,69,65,83,47,98,108,68,122,111,116,47,105,77,43,86,103,122,90,77,69,116,43,48,75,87,75,78,103,119,89,99,86,102,121,97,70,56,99,104,102,57,85,47,86,82,106,51,52,122,112,53,111,43,85,112,97,119,97,116,106,50,74,103,115,97,105,104,113,54,90,53,84,48,101,49,114,56,78,80,109,69,105,119,103,113,118,77,51,108,97,86,83,98,116,101,66,112,80,81,88,119,102,66,56,101,105,112,119,120,104,121,67,68,65,85,111,118,69,113,82,51,84,71,79,54,109,101,75,119,71,100,73,104,72,103,102,50,112,72,75,90,50,107,47,66,116,104,97,98,110,115,118,78,77,114,98,74,69,103,76,72,76,121,87,84,119,98,76,74,87,108,101,106,112,71,121,47,70,100,83,105,74,114,101,66,114,81,115,114,106,90,113,100,76,75,72,90,71,117,108,52,70,108,43,117,47,72,102,107,48,119,121,81,69,106,121,97,99,51,52,57,105,90,55,97,104,49,72,56,50,85,97,50,49,55,109,74,51,88,56,87,113,80,111,50,86,72,65,85,57,71,102,47,113,107,97,85,101,75,76,84,97,75,87,101,121,122,116,68,109,105,68,98,115,114,47,86,51,51,106,114,101,67,88,65,65,109,120,68,76,73,73,66,103,83,88,79,82,82,117,98,80,53,113,80,78,69,53,67,76,120,104,119,61,61,34,10,125],"Meta1":null,"Meta2":null,"Meta3":null,"Meta4":null}

The application reads the CMSL payload and sends the command to the driver. The payload is translated to [BIOS setting], [Value], [Password || auth-token]

echo "USB Storage Boot,Enable,<BEAM/>ASAADAAANZ9AYwH/////////////////////64bPg7ygUv4xanoHIFrzME9mIsxeJh32fkhR7sgHpXdEHjetMXxNVhEK/twhhXhHS93kp9JpGhsr+J6AMKV2ldE99iJHo6ul1IxJQuBSxBoN1mf49Mm/ROCNll+IhsAn4ow+xlDwKQn2EzKtQc2Wf1eC646KPcl+ZCtiFhvLzXZrGSXsB2hJy0+IzegUPzLY6jaN0lYyQMtQ0KpcyGnK6xZSKCKfotygWawWY8BD3oewyrVLdKMGjrtX4HtHaeo5A9VVXVt89i7lZAmV3VkRtu70LEv240ue/SOhwrxGtydgNmtpV3dSn/ancnY4ONbTxBRiw8cifObEiNOidYzhpQ=="

Quoted 1 line

/sys/class/firmware-attributes/hp-bioscfg/attributes/Sure_Admin/settings'

As you can see, the auth-token "<BEAN/>.....==" portion varies in size depending on the signing certificate size used.

A method that can be used to address your comments and allow the driver to handle both auth-tokens and password using command

echo "auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

is adding an modifier to indicate if the input is a password or auth-token

For instance... using [Token] modifier to identify the data is an authentication token

echo "[token] auth-token" >
/sys/class/firmware-attributes/hp-bioscfg/"Setup
Password"/current_password

If the modifier is missing, the driver will treat the data as a password.

This new method will conform with the firmware class framework and provide the flexibility needed for HP solution.

Please advise.

I don't know if this is helpful or not as I've not read your code in any detail and was just being nosy whilst skimming the mailing list posts - but I did similar for the Lenovo platforms recently. In our case we added a 'signature' sysfs entry under authentication/Admin that is used for what is (I think) the equivalent of 'auth-token' when certificate based authentication is enabled. We didn't try to re-use the password entry.

Quoted 8 lines

So if certificate authentication is enabled the user ends up doing:
echo "crypto-string" > authentication/Admin/signature
echo "value" > attribute/"setting"
and if password authentication is enabled
echo "password" > authentication/Admin/password
echo "value" > attribute/"setting"
and the thinklmi driver takes care of figuring out the rest to pass as WMI calls to the BIOS (for us this is done at init time and is only changed by a reboot). Note for completeness - we have a signature and a save_signature....for reasons of BIOS (sigh).

Quoted 3 lines

Thank you for your suggestion. Separating 'password' and signature
is a better approach and easier to implement since most of the supporting code is already implemented.

Ok, using a separate signature file under authentication/Admin/signature (or something similar) for this is fine with me.

Regards,

Hans

#8 lore raw

PATCH v5 2/5 Introduction of HP-BIOSCFG driver (2)

In reply to Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  283 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1066 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  673 +++++++++++
 3 files changed, 2022 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +283 -0
new file mode 100644
index 000000000000..20620762dcaa
@@ -0,0 +1,283 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to methods under BIOS interface GUID
+ * for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 Hewlett-Packard Inc.
+ */
+
+#include <linux/wmi.h>
+#include "bioscfg.h"
+
+#define SET_DEFAULT_VALUES_METHOD_ID	0x02
+#define SET_BIOS_DEFAULTS_METHOD_ID	0x03
+#define SET_ATTRIBUTE_METHOD_ID		0x04
+
+/*
+ * set_attribute() - Update an attribute value
+ * @a_name: The attribute name
+ * @a_value: The attribute value
+ *
+ * Sets an attribute to new value
+ */
+int hp_set_attribute(const char *a_name, const char *a_value)
+{
+	size_t security_area_size;
+	size_t a_name_size, a_value_size;
+	u16 *buffer = NULL;
+	u16 *start = NULL;
+	int  buffer_size;
+	int ret;
+	int instance;
+	char *auth_empty_value = "";
+
+	mutex_lock(&bioscfg_drv.mutex);
+	if (!bioscfg_drv.bios_attr_wdev) {
+		ret = -ENODEV;
+		goto out_set_attribute;
+	}
+
+	instance = get_password_instance_for_type(SETUP_PASSWD);
+	if (instance < 0)
+		goto out_set_attribute;
+
+	if (strlen(bioscfg_drv.password_data[instance].current_password) == 0)
+		strscpy(bioscfg_drv.password_data[instance].current_password,
+			auth_empty_value,
+			sizeof(bioscfg_drv.password_data[instance].current_password));
+
+	a_name_size = calculate_string_buffer(a_name);
+	a_value_size = calculate_string_buffer(a_value);
+	security_area_size = calculate_security_buffer(bioscfg_drv.password_data[instance].current_password);
+	buffer_size = a_name_size + a_value_size + security_area_size;
+
+	buffer = kzalloc(buffer_size, GFP_KERNEL);
+	if (!buffer) {
+		ret = -ENOMEM;
+		goto out_set_attribute;
+	}
+
+	/* build variables to set */
+	start = buffer;
+	start = ascii_to_utf16_unicode(start, a_name);
+	if (!start)
+		goto out_set_attribute;
+
+	start = ascii_to_utf16_unicode(start, a_value);
+	if (!start)
+		goto out_set_attribute;
+
+	populate_security_buffer(start, bioscfg_drv.password_data[instance].current_password);
+	ret = hp_wmi_set_bios_setting(buffer, buffer_size);
+
+
+out_set_attribute:
+	kfree(buffer);
+	mutex_unlock(&bioscfg_drv.mutex);
+	return ret;
+}
+
+/*
+ * hp_wmi_perform_query
+ *
+ * query:	The commandtype (enum hp_wmi_commandtype)
+ * write:	The command (enum hp_wmi_command)
+ * buffer:	Buffer used as input and/or output
+ * insize:	Size of input buffer
+ * outsize:	Size of output buffer
+ *
+ * returns zero on success
+ *         an HP WMI query specific error code (which is positive)
+ *         -EINVAL if the query was not successful at all
+ *         -EINVAL if the output buffer size exceeds buffersize
+ *
+ * Note: The buffersize must at least be the maximum of the input and output
+ *       size. E.g. Battery info query is defined to have 1 byte input
+ *       and 128 byte output. The caller would do:
+ *       buffer = kzalloc(128, GFP_KERNEL);
+ *       ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ,
+ *				    buffer, 1, 128)
+ */
+int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer,
+			 int insize, int outsize)
+{
+	struct acpi_buffer input, output = { ACPI_ALLOCATE_BUFFER, NULL };
+	struct bios_return *bios_return;
+	union acpi_object *obj = NULL;
+	struct bios_args *args = NULL;
+	int mid, actual_insize, actual_outsize;
+	size_t bios_args_size;
+	int ret;
+
+	mid = encode_outsize_for_pvsz(outsize);
+	if (WARN_ON(mid < 0))
+		return mid;
+
+	actual_insize = insize;
+	bios_args_size = struct_size(args, data, insize);
+	args = kmalloc(bios_args_size, GFP_KERNEL);
+	if (!args)
+		return -ENOMEM;
+
+	input.length = bios_args_size;
+	input.pointer = args;
+
+	args->signature = 0x55434553;
+	args->command = command;
+	args->commandtype = query;
+	args->datasize = insize;
+	memcpy(args->data, buffer, flex_array_size(args, data, insize));
+
+	ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);
+	bioscfg_drv.last_wmi_status = ret;
+	if (ret)
+		goto out_free;
+
+	obj = output.pointer;
+	if (!obj) {
+		ret = -EINVAL;
+		goto out_free;
+	}
+
+
+	bios_return = (struct bios_return *)obj->buffer.pointer;
+	if (!bios_return) {
+		ret = -EINVAL;
+		goto out_free;
+	}
+
+
+	ret = bios_return->return_code;
+	bioscfg_drv.last_wmi_status = ret;
+	if (ret) {
+		if (ret != HPWMI_RET_UNKNOWN_COMMAND &&
+		    ret != HPWMI_RET_UNKNOWN_CMDTYPE)
+			pr_warn("query 0x%x returned error 0x%x\n", query, ret);
+		goto out_free;
+	}
+
+	/* Ignore output data of zero size */
+	if (!outsize)
+		goto out_free;
+
+	actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
+	memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
+	memset(buffer + actual_outsize, 0, outsize - actual_outsize);
+
+out_free:
+	kfree(obj);
+	kfree(args);
+	return ret;
+}
+
+/*
+ * ascii_to_utf16_unicode -  Convert ascii string to UTF-16 unicode
+ *
+ * @p:   Unicode buffer address
+ * @str: string to convert to unicode
+ *
+ * Returns a void pointer to the buffer containing unicode string
+ */
+void *ascii_to_utf16_unicode(u16 *p, const u8 *str)
+{
+	int len = strlen(str);
+	int ret;
+
+	/*
+	 * Add null character when reading an empty string
+	 */
+	if (len == 0) {
+		*p++ = 2;
+		*p++ = (u8)0x00;
+		return p;
+	}
+	*p++ = len * 2;
+	ret = utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN, p, len);
+
+	if (ret < 0) {
+		dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n");
+		goto ascii_to_utf16_unicode_out;
+	}
+
+	if ((ret * sizeof(u16)) > U16_MAX) {
+		dev_err(bioscfg_drv.class_dev, "Error string too long\n");
+		goto ascii_to_utf16_unicode_out;
+	}
+
+ascii_to_utf16_unicode_out:
+	p += len;
+	return p;
+}
+
+/*
+ * hp_wmi_set_bios_setting - Set setting's value in BIOS
+ *
+ * @input_buffer: Input buffer address
+ * @input_size:   Input buffer size
+ *
+ * Returns: Count of unicode characters written to BIOS if successful, otherwise
+ *		-ENOMEM unable to allocate memory
+ *		-EINVAL buffer not allocated or too small
+ */
+int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size)
+{
+	union acpi_object *obj;
+	struct acpi_buffer input = {input_size, input_buffer};
+	struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
+	int ret = 0;
+
+	ret = wmi_evaluate_method(HP_WMI_SET_BIOS_SETTING_GUID, 0, 1, &input, &output);
+
+	obj = output.pointer;
+	if (!obj)
+		return -EINVAL;
+
+	if (obj->type != ACPI_TYPE_INTEGER)
+		ret = -EINVAL;
+
+	ret = obj->integer.value;
+	bioscfg_drv.last_wmi_status = ret;
+
+	kfree(obj);
+	return ret;
+}
+
+static int bios_attr_set_interface_probe(struct wmi_device *wdev, const void *context)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.bios_attr_wdev = wdev;
+	mutex_unlock(&bioscfg_drv.mutex);
+	return 0;
+}
+
+static void bios_attr_set_interface_remove(struct wmi_device *wdev)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.bios_attr_wdev = NULL;
+	mutex_unlock(&bioscfg_drv.mutex);
+}
+
+static const struct wmi_device_id bios_attr_set_interface_id_table[] = {
+	{ .guid_string = HP_WMI_BIOS_GUID},
+	{ },
+};
+static struct wmi_driver bios_attr_set_interface_driver = {
+	.driver = {
+		.name = DRIVER_NAME
+	},
+	.probe = bios_attr_set_interface_probe,
+	.remove = bios_attr_set_interface_remove,
+	.id_table = bios_attr_set_interface_id_table,
+};
+
+int init_bios_attr_set_interface(void)
+{
+	return wmi_driver_register(&bios_attr_set_interface_driver);
+}
+
+void exit_bios_attr_set_interface(void)
+{
+	wmi_driver_unregister(&bios_attr_set_interface_driver);
+}
+
+MODULE_DEVICE_TABLE(wmi, bios_attr_set_interface_id_table);
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1066 -0

1,066 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +673 -0

673 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v5 2/5] Introduction of HP-BIOSCFG driver (2)

Hi Jorge,

First of all some generic remarks which apply to all patches:

1. Quite a few non local / non static functions have generic names like e.g. calculate_string_buffer().

If this code is build into the main kernel vmlinuz then these will all be part of a global namespace, leading to potential symbol collisions to avoid these please make the following 2 changes

i) Make functions which are only used in a single .c file static e.g. wmi_error_and_message()
ii) Prefix others with hp_bioscfg_, e.g. hp_bioscfg_calculate_string_buffer()
to avoid possible symbol clashes

More detailed review remarks inline below.

Quoted 82 lines · Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  283 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1066 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  673 +++++++++++
 3 files changed, 2022 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..20620762dcaa
@@ -0,0 +1,283 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to methods under BIOS interface GUID
+ * for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 Hewlett-Packard Inc.
+ */
+
+#include <linux/wmi.h>
+#include "bioscfg.h"
+
+#define SET_DEFAULT_VALUES_METHOD_ID	0x02
+#define SET_BIOS_DEFAULTS_METHOD_ID	0x03
+#define SET_ATTRIBUTE_METHOD_ID		0x04
+
+/*
+ * set_attribute() - Update an attribute value
+ * @a_name: The attribute name
+ * @a_value: The attribute value

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 29

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+ *
+ * Sets an attribute to new value
+ */
+int hp_set_attribute(const char *a_name, const char *a_value)
+{
+	size_t security_area_size;
+	size_t a_name_size, a_value_size;
+	u16 *buffer = NULL;
+	u16 *start = NULL;
+	int  buffer_size;

You have 2 spaces here between "int' and "buffer_size", please drop 1 of the spaces.

Quoted 8 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +8 -0
+	int ret;
+	int instance;
+	char *auth_empty_value = "";
+
+	mutex_lock(&bioscfg_drv.mutex);
+	if (!bioscfg_drv.bios_attr_wdev) {
+		ret = -ENODEV;
+		goto out_set_attribute;

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 47

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+	}
+
+	instance = get_password_instance_for_type(SETUP_PASSWD);
+	if (instance < 0)
+		goto out_set_attribute;
+
+	if (strlen(bioscfg_drv.password_data[instance].current_password) == 0)
+		strscpy(bioscfg_drv.password_data[instance].current_password,
+			auth_empty_value,
+			sizeof(bioscfg_drv.password_data[instance].current_password));

Since auth_empty_value has a strlen of 0 now, you are replacing an empty string with an empty string now, so this entire if can be remove since it is a no-op.

Quoted 83 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +83 -0
+
+	a_name_size = calculate_string_buffer(a_name);
+	a_value_size = calculate_string_buffer(a_value);
+	security_area_size = calculate_security_buffer(bioscfg_drv.password_data[instance].current_password);
+	buffer_size = a_name_size + a_value_size + security_area_size;
+
+	buffer = kzalloc(buffer_size, GFP_KERNEL);
+	if (!buffer) {
+		ret = -ENOMEM;
+		goto out_set_attribute;
+	}
+
+	/* build variables to set */
+	start = buffer;
+	start = ascii_to_utf16_unicode(start, a_name);
+	if (!start)
+		goto out_set_attribute;
+
+	start = ascii_to_utf16_unicode(start, a_value);
+	if (!start)
+		goto out_set_attribute;
+
+	populate_security_buffer(start, bioscfg_drv.password_data[instance].current_password);
+	ret = hp_wmi_set_bios_setting(buffer, buffer_size);
+
+
+out_set_attribute:
+	kfree(buffer);
+	mutex_unlock(&bioscfg_drv.mutex);
+	return ret;
+}
+
+/*
+ * hp_wmi_perform_query
+ *
+ * query:	The commandtype (enum hp_wmi_commandtype)
+ * write:	The command (enum hp_wmi_command)
+ * buffer:	Buffer used as input and/or output
+ * insize:	Size of input buffer
+ * outsize:	Size of output buffer
+ *
+ * returns zero on success
+ *         an HP WMI query specific error code (which is positive)
+ *         -EINVAL if the query was not successful at all
+ *         -EINVAL if the output buffer size exceeds buffersize
+ *
+ * Note: The buffersize must at least be the maximum of the input and output
+ *       size. E.g. Battery info query is defined to have 1 byte input
+ *       and 128 byte output. The caller would do:
+ *       buffer = kzalloc(128, GFP_KERNEL);
+ *       ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ,
+ *				    buffer, 1, 128)
+ */
+int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer,
+			 int insize, int outsize)
+{
+	struct acpi_buffer input, output = { ACPI_ALLOCATE_BUFFER, NULL };
+	struct bios_return *bios_return;
+	union acpi_object *obj = NULL;
+	struct bios_args *args = NULL;
+	int mid, actual_insize, actual_outsize;
+	size_t bios_args_size;
+	int ret;
+
+	mid = encode_outsize_for_pvsz(outsize);
+	if (WARN_ON(mid < 0))
+		return mid;
+
+	actual_insize = insize;
+	bios_args_size = struct_size(args, data, insize);
+	args = kmalloc(bios_args_size, GFP_KERNEL);
+	if (!args)
+		return -ENOMEM;
+
+	input.length = bios_args_size;
+	input.pointer = args;
+
+	args->signature = 0x55434553;
+	args->command = command;
+	args->commandtype = query;
+	args->datasize = insize;
+	memcpy(args->data, buffer, flex_array_size(args, data, insize));
+

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 140

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+	ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);
+	bioscfg_drv.last_wmi_status = ret;
+	if (ret)
+		goto out_free;
+
+	obj = output.pointer;
+	if (!obj) {
+		ret = -EINVAL;
+		goto out_free;
+	}

You need to do some sanity checks on the returned buffer here before consuming it. Something like this:

	if (obj->type != ACPI_TYPE_BUFFER ||
	    obj->buffer.length > sizeof(*bios_return)) {
		pr_warn("query 0x%x returned wrong type or too small buffer\n", query);
		ret = -EINVAL;
		goto out_free;
	}

Note that the type check must be done before using any obj->buffer.* members

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 147

Quoted 8 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +7 -0
+
+
+	bios_return = (struct bios_return *)obj->buffer.pointer;
 
+	if (!bios_return) {
+		ret = -EINVAL;
+		goto out_free;
+	}

You don't need to check obj->buffer.pointer (after the added sanity checks above) if the type == ACPI_TYPE_BUFFER and length > 0 then you can always safely dereference obj->buffer.pointer, so you can drop this check.

Quoted 38 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +38 -0
+
+
+	ret = bios_return->return_code;
+	bioscfg_drv.last_wmi_status = ret;
+	if (ret) {
+		if (ret != HPWMI_RET_UNKNOWN_COMMAND &&
+		    ret != HPWMI_RET_UNKNOWN_CMDTYPE)
+			pr_warn("query 0x%x returned error 0x%x\n", query, ret);
+		goto out_free;
+	}
+
+	/* Ignore output data of zero size */
+	if (!outsize)
+		goto out_free;
+
+	actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
+	memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
+	memset(buffer + actual_outsize, 0, outsize - actual_outsize);
+
+out_free:
+	kfree(obj);
+	kfree(args);
+	return ret;
+}
+
+/*
+ * ascii_to_utf16_unicode -  Convert ascii string to UTF-16 unicode
+ *
+ * @p:   Unicode buffer address
+ * @str: string to convert to unicode
+ *
+ * Returns a void pointer to the buffer containing unicode string
+ */
+void *ascii_to_utf16_unicode(u16 *p, const u8 *str)
+{
+	int len = strlen(str);
+	int ret;
+

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 195

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+	/*
+	 * Add null character when reading an empty string
+	 */
+	if (len == 0) {
+		*p++ = 2;
+		*p++ = (u8)0x00;
+		return p;
+	}
+	*p++ = len * 2;
+	ret = utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN, p, len);

The actual length returned by utf8s_to_utf16smay be different from len * 2. E.g. a multi-byte UTF8 sequence might fit in a single UTF16. So you should remove the:

	*p++ = len * 2;

Here and pass "p + 1" to utf8s_to_utf16s to reserve the space and then store the length after the conversion based on the return value of utf8s_to_utf16s().

drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c line 205

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+
+	if (ret < 0) {
+		dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n");
+		goto ascii_to_utf16_unicode_out;
+	}
+
+	if ((ret * sizeof(u16)) > U16_MAX) {
+		dev_err(bioscfg_drv.class_dev, "Error string too long\n");
+		goto ascii_to_utf16_unicode_out;
+	}

In case of one of these 2 errors you are now just leaving garbage in the buffer, instead incase of error just file the destination buffer with an empty string like you do for len == 0 above. To make this easier maybe add a little helper like this:

static void *utf16_empty_string(u16 *p)

{
	*p++ = 2;
	*p++ = (u8)0x00;
	return p;
}

And then do:

	if (len == 0)
		return utf16_empty_string(p);

...

	if (ret < 0) {
		dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n");
		return utf16_empty_string(p);
	}

	if ((ret * sizeof(u16)) > U16_MAX) {
		dev_err(bioscfg_drv.class_dev, "Error string too long\n");
		return utf16_empty_string(p);
	}

	*p = ret * sizeof(u16);
	return p + len;
}
Quoted 98 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +78 -0
+
+ascii_to_utf16_unicode_out:
+	p += len;
+	return p;
+}
+
+/*
+ * hp_wmi_set_bios_setting - Set setting's value in BIOS
+ *
+ * @input_buffer: Input buffer address
+ * @input_size:   Input buffer size
+ *
+ * Returns: Count of unicode characters written to BIOS if successful, otherwise
+ *		-ENOMEM unable to allocate memory
+ *		-EINVAL buffer not allocated or too small
+ */
+int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size)
+{
+	union acpi_object *obj;
+	struct acpi_buffer input = {input_size, input_buffer};
+	struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
+	int ret = 0;
+
+	ret = wmi_evaluate_method(HP_WMI_SET_BIOS_SETTING_GUID, 0, 1, &input, &output);
+
+	obj = output.pointer;
+	if (!obj)
+		return -EINVAL;
+
+	if (obj->type != ACPI_TYPE_INTEGER)
+		ret = -EINVAL;
+
+	ret = obj->integer.value;
+	bioscfg_drv.last_wmi_status = ret;
+
+	kfree(obj);
+	return ret;
+}
+
+static int bios_attr_set_interface_probe(struct wmi_device *wdev, const void *context)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.bios_attr_wdev = wdev;
+	mutex_unlock(&bioscfg_drv.mutex);
+	return 0;
+}
+
+static void bios_attr_set_interface_remove(struct wmi_device *wdev)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.bios_attr_wdev = NULL;
+	mutex_unlock(&bioscfg_drv.mutex);
+}
+
+static const struct wmi_device_id bios_attr_set_interface_id_table[] = {
+	{ .guid_string = HP_WMI_BIOS_GUID},
+	{ },
+};
+static struct wmi_driver bios_attr_set_interface_driver = {
+	.driver = {
+		.name = DRIVER_NAME
+	},
+	.probe = bios_attr_set_interface_probe,
+	.remove = bios_attr_set_interface_remove,
+	.id_table = bios_attr_set_interface_id_table,
+};
+
+int init_bios_attr_set_interface(void)
+{
+	return wmi_driver_register(&bios_attr_set_interface_driver);
+}
+
+void exit_bios_attr_set_interface(void)
+{
+	wmi_driver_unregister(&bios_attr_set_interface_driver);
+}
+
+MODULE_DEVICE_TABLE(wmi, bios_attr_set_interface_id_table);
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +14 -0
new file mode 100644
index 000000000000..def37b99b03b
@@ -0,0 +1,1066 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Common methods for use with hp-bioscfg driver
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include <asm-generic/errno-base.h>
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/wmi.h>

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 24

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+#include "bioscfg.h"
+#include "../../firmware_attributes_class.h"
+#include <linux/nls.h>
+
+MODULE_AUTHOR("Jorge Lopez <[email protected]>");
+MODULE_DESCRIPTION("HP BIOS Configuration Driver");
+MODULE_LICENSE("GPL");
+
+
+#define MAX_TYPES  4

This MAX_TYPES define is not used anywhere please drop it.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 31

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+
+struct bioscfg_priv bioscfg_drv = {
+	.mutex = __MUTEX_INITIALIZER(bioscfg_drv.mutex),
+};
+
+/* reset bios to defaults */
+static const char * const reset_types[] = {"builtinsafe", "lastknowngood", "factory", "custom"};

This reset_types variable is not used anywhere, please drop it.

Quoted 88 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +88 -0
+static struct class *fw_attr_class;
+
+int get_integer_from_buffer(int **buffer, int *buffer_size, int *integer)
+{
+	int *ptr = PTR_ALIGN(*buffer, 4);
+
+	/* Ensure there is enough space remaining to read the integer */
+	if (*buffer_size < sizeof(int))
+		return -EINVAL;
+
+	*integer = *(ptr++);
+	*buffer = ptr;
+	*buffer_size -= sizeof(int);
+
+	return 0;
+}
+
+int get_string_from_buffer(u16 **buffer, int *buffer_size, char **str)
+{
+	u16 *ptr = *buffer;
+	u16 ptrlen;
+
+	u16 size;
+	int i;
+	char *output = NULL;
+	int escape = 0;
+
+	ptrlen = *(ptr++);
+	size = ptrlen / 2;
+
+	/* Ensure there is enough space remaining to read and convert
+	 * the string
+	 */
+	if (*buffer_size < (size *  sizeof(u16)))
+		return -EINVAL;
+
+
+	for (i = 0; i < size; i++)
+		if (ptr[i] == '\\' || ptr[i] == '\r' || ptr[i] == '\n' || ptr[i] == '\t')
+			escape++;
+
+	size += escape;
+	*str = kcalloc(size + 1, sizeof(char), GFP_KERNEL);
+	if (!*str)
+		return -ENOMEM;
+
+	output = *str;
+
+	/*
+	 * convert from UTF-16 unicode to ASCII
+	 */
+	utf16s_to_utf8s(ptr, ptrlen, UTF16_HOST_ENDIAN, output, size);
+
+	for (i = 0; i < size; i++) {
+		if (*ptr == '\\' || *ptr == '\r' || *ptr == '\n' || *ptr == '\t')
+			output[i++] = '\\';
+
+		if (*ptr == '\r')
+			output[i] = 'r';
+		else if (*ptr == '\n')
+			output[i] = 'n';
+		else if (*ptr == '\t')
+			output[i] = 't';
+		else if (*ptr == '"')
+			output[i] = '\'';
+		else
+			output[i] = *ptr;
+		ptr++;
+	}
+
+	*buffer = ptr;
+	*buffer_size -= size * sizeof(u16);
+	return size;
+}
+
+/*
+ * populate_string_buffer() - populates a string buffer
+ * @buffer: the start of the destination buffer
+ * @buffer_len: length of the destination buffer
+ * @str: the string to insert into buffer
+ */
+ssize_t populate_string_buffer(u16 *buffer, size_t buffer_len, const char *str)
+{
+	u16 *target = buffer;
+	int ret;
+
+	ret = utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN,
+			      target, buffer_len - sizeof(u16));

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 129

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	if (ret < 0) {
+		dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n");
+		return ret;
+	}
+	if ((ret * sizeof(u16)) > U16_MAX) {
+		dev_err(bioscfg_drv.class_dev, "Error string too long\n");
+		return -ERANGE;
+	}
+	return buffer_len;
+}

This (populate_string_buffer) function is not used anywhere, so please just drop it and don't forget to also remove it from bioscfg.h .

Also note that it does not store the length in front of the converted string, so it also seems to be buggy.

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+
+/*
+ * calculate_string_buffer() - determines size of string buffer for use with BIOS communication
+ * @str: the string to calculate based upon
+ */
+size_t calculate_string_buffer(const char *str)
+{

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 146

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	int length = strlen(str);
+	int size;
+
+	/* BIOS expects 4 bytes when an empty string is found */
+	if (!length)
+		length = 1;
+
+
+	/* u16 length field + one UTF16 char for each input char */
+	size =  sizeof(u16) + length * sizeof(u16);

There are 2 spaces after the "=" here, please drop 1 space.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 151

Quoted 5 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +5 -0
+
+	return size;
+}
+
+int wmi_error_and_message(int error_code, char *msg)

This function is only used for last_error_show(), I see how its use to convert an error to a kernel error code can be useful elsewhere (although it is not used as such atm).

But in case of the last_error_show() usage the
current use is a problem, see below.

static and drop the prototype from bioscfg.h .

Quoted 95 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +95 -0
+{
+	char *error_msg = NULL;
+	int ret = -EIO;
+
+	switch (error_code) {
+	case SUCCESS:
+		error_msg = "Success";
+		ret = 0;
+		break;
+	case CMD_FAILED:
+		error_msg = "Command failed";
+		ret = -EINVAL;
+		break;
+	case INVALID_SIGN:
+		error_msg = "Invalid signature";
+		ret = -EINVAL;
+		break;
+	case INVALID_CMD_VALUE:
+		error_msg = "Invalid command value/Feature not supported";
+		ret = -EOPNOTSUPP;
+		break;
+	case INVALID_CMD_TYPE:
+		error_msg = "Invalid command type";
+		ret = -EINVAL;
+		break;
+	case INVALID_DATA_SIZE:
+		error_msg = "Invalid data size";
+		ret = -EINVAL;
+		break;
+	case INVALID_CMD_PARAM:
+		error_msg = "Invalid command parameter";
+		ret = -EINVAL;
+		break;
+	case ENCRYP_CMD_REQUIRED:
+		error_msg = "Secure/encrypted command required";
+		ret = -EACCES;
+		break;
+	case NO_SECURE_SESSION:
+		error_msg = "No secure session established";
+		ret = -EACCES;
+		break;
+	case SECURE_SESSION_FOUND:
+		error_msg = "Secure session already established";
+		ret = -EACCES;
+		break;
+	case SECURE_SESSION_FAILED:
+		error_msg = "Secure session failed";
+		ret = -EIO;
+		break;
+	case AUTH_FAILED:
+		error_msg = "Other permission/Authentication failed";
+		ret = -EACCES;
+		break;
+	case INVALID_BIOS_AUTH:
+		error_msg = "Invalid BIOS administrator password";
+		ret = -EINVAL;
+		break;
+	case NONCE_DID_NOT_MATCH:
+		error_msg = "Nonce did not match";
+		ret = -EINVAL;
+		break;
+	case GENERIC_ERROR:
+		error_msg = "Generic/Other error";
+		ret = -EIO;
+		break;
+	case BIOS_ADMIN_POLICY_NOT_MET:
+		error_msg = "BIOS Admin password does not meet password policy requirements";
+		ret = -EINVAL;
+		break;
+	case BIOS_ADMIN_NOT_SET:
+		error_msg = "BIOS Setup password is not set.";
+		ret = -EPERM;
+		break;
+	case P21_NO_PROVISIONED:
+		error_msg = "P21 is not provisioned";
+		ret = -EPERM;
+		break;
+	case P21_PROVISION_IN_PROGRESS:
+		error_msg = "P21 is already provisioned or provisioning is in progress and a signing key has already been sent.";
+		ret = -EINPROGRESS;
+		break;
+	case P21_IN_USE:
+		error_msg = "P21 in use (cannot deprovision)";
+		ret = -EPERM;
+		break;
+	case HEP_NOT_ACTIVE:
+		error_msg = "HEP not activated";
+		ret = -EPERM;
+		break;
+	case HEP_ALREADY_SET:
+		error_msg = "HEP Transport already set";
+		ret = -EINVAL;
+		break;
+	case HEP_CHECK_STATE:
+		error_msg = "Check the current HEP state";

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 256

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+		ret = -EINVAL;
+		break;
+	default:
+		error_msg = "Generic/Other error";
+		ret = -EIO;
+		break;
+	}
+
+	if (msg != NULL)
+		sprintf(msg, "%d,\"%s\"", error_code, error_msg);

Since this is intended for last_error_show usage, this really should be:

	if (msg != NULL)
		return sysfs_emit(msg, "%d,\"%s\"", error_code, error_msg);
Quoted 24 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +24 -0
+	return error_code;
+}
+
+
+/*
+ * pending_reboot_show() - sysfs implementaton for read pending_reboot
+ * @kobj: Kernel object for this attribute
+ * @attr: Kernel object attribute
+ * @buf: The buffer to display to userspace
+ *
+ * Stores default value as 0
+ * When current_value is changed this attribute is set to 1 to notify reboot may be required
+ */
+static ssize_t pending_reboot_show(struct kobject *kobj,
+				   struct kobj_attribute *attr,
+				   char *buf)
+{
+	return sysfs_emit(buf, "%d\n", bioscfg_drv.pending_reboot);
+}
+static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
+
+/*
+ * last_error_show() - sysfs implementaton for reporting the WMI
+ * error/success value.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 290

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+ * @kobj: Kernel object for this attribute
+ * @attr: Kernel object attribute
+ * @buf: The buffer to display to userspace
+ */
+static ssize_t last_error_show(struct kobject *kobj,
+			       struct kobj_attribute *attr,
+				   char *buf)
+{
+	wmi_error_and_message(bioscfg_drv.last_wmi_status, buf);
+	return sysfs_emit(buf, "%s\n", buf);

You may never pass the same dest and source buffers to printf like functions, this can go very wrong, instead just directly call sysfs_emit inside wmi_error_and_message() as suggested above and then you can just do:

	return wmi_error_and_message(bioscfg_drv.last_wmi_status, buf);

here.

Also please document last_error in Documentation/ABI/testing/sysfs-class-firmware-attributes

Quoted 72 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +72 -0
+}
+static struct kobj_attribute last_error = __ATTR_RO(last_error);
+
+/*
+ * create_attributes_level_sysfs_files() - Creates reset_bios,
+ * pending_reboot, and last_error attributes
+ */
+static int create_attributes_level_sysfs_files(void)
+{
+	int ret;
+
+	ret = sysfs_create_file(&bioscfg_drv.main_dir_kset->kobj, &pending_reboot.attr);
+	if (ret)
+		return ret;
+
+	ret = sysfs_create_file(&bioscfg_drv.main_dir_kset->kobj, &last_error.attr);
+	if (ret)
+		return ret;
+
+	bioscfg_drv.last_wmi_status = 0;
+	return 0;
+}
+
+
+static ssize_t bioscfg_attr_show(struct kobject *kobj, struct attribute *attr,
+				    char *buf)
+{
+	struct kobj_attribute *kattr;
+	ssize_t ret = -EIO;
+
+	kattr = container_of(attr, struct kobj_attribute, attr);
+	if (kattr->show)
+		ret = kattr->show(kobj, kattr, buf);
+	return ret;
+}
+
+static ssize_t bioscfg_attr_store(struct kobject *kobj, struct attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct kobj_attribute *kattr;
+	ssize_t ret = -EIO;
+
+	kattr = container_of(attr, struct kobj_attribute, attr);
+	if (kattr->store)
+		ret = kattr->store(kobj, kattr, buf, count);
+	return ret;
+}
+
+static const struct sysfs_ops bioscfg_kobj_sysfs_ops = {
+	.show	= bioscfg_attr_show,
+	.store	= bioscfg_attr_store,
+};
+
+static void attr_name_release(struct kobject *kobj)
+{
+	kfree(kobj);
+}
+
+static struct kobj_type attr_name_ktype = {
+	.release	= attr_name_release,
+	.sysfs_ops	= &bioscfg_kobj_sysfs_ops,
+};
+
+/*
+ * strlcpy_attr - Copy a length-limited, NULL-terminated string with bound checks
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ */
+void strlcpy_attr(char *dest, char *src)
+{
+	size_t len = strlen(src) + 1;
+

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 372

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	if (len > 1 && len <= MAX_BUFF)
+		strscpy(dest, src, len);
+
+	/*
+	 * len can be zero because any property not-applicable to attribute can
+	 * be empty so check only for too long buffers and log error
+	 */
+	if (len > MAX_BUFF)
+		pr_err("Source string returned from BIOS is out of bound!\n");
+}

This function is not used anywhere,
please drop it and don't forget to also remove it from bioscfg.h .

Quoted 67 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +67 -0
+
+/*
+ * get_wmiobj_pointer() - Get Content of WMI block for particular instance
+ *
+ * @instance_id: WMI instance ID
+ * @guid_string: WMI GUID (in str form)
+ *
+ * Fetches the content for WMI block (instance_id) under GUID (guid_string)
+ * Caller must kfree the return
+ */
+union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string)
+{
+	struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+
+	status = wmi_query_block(guid_string, instance_id, &out);
+	return ACPI_SUCCESS(status) ? (union acpi_object *)out.pointer : NULL;
+}
+
+/*
+ * get_instance_count() - Compute total number of instances under guid_string
+ *
+ * @guid_string: WMI GUID (in string form)
+ */
+int get_instance_count(const char *guid_string)
+{
+	union acpi_object *wmi_obj = NULL;
+	int i = 0;
+
+	do {
+		kfree(wmi_obj);
+		wmi_obj = get_wmiobj_pointer(i, guid_string);
+		i++;
+	} while (wmi_obj);
+
+	return (i-1);
+}
+
+/*
+ * alloc_attributes_data() - Allocate attributes data for a particular type
+ *
+ * @attr_type: Attribute type to allocate
+ */
+static int alloc_attributes_data(int attr_type)
+{
+	int retval = 0;
+
+	switch (attr_type) {
+	case HPWMI_STRING_TYPE:
+		retval = alloc_string_data();
+		break;
+	case HPWMI_INTEGER_TYPE:
+		retval = alloc_integer_data();
+		break;
+	case HPWMI_ENUMERATION_TYPE:
+		retval = alloc_enumeration_data();
+		break;
+	case HPWMI_ORDERED_LIST_TYPE:
+		retval = alloc_ordered_list_data();
+		break;
+	case HPWMI_PASSWORD_TYPE:
+		retval = alloc_password_data();
+		break;
+	default:
+		break;
+	}
+

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 449

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	return retval;
+}
+
+int convert_hexstr_to_int(char *str, int *int_value)
+{
+	int ret;
+
+	ret = kstrtou32(str, 10, int_value);
+	return ret;
+}

This function is not used anywhere,
please drop it and don't forget to also remove it from bioscfg.h .

Quoted 48 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +48 -0
+
+int convert_hexstr_to_str(char **hex, int input_len, char **str, int *len)
+{
+	int ret = 0;
+	int new_len = 0;
+	char tmp[] = "0x00";
+	char *input = *hex;
+	char *new_str = NULL;
+	long  ch;
+	int i;
+
+	if (input_len <= 0 || hex == NULL || str == NULL || len == NULL)
+		return -EINVAL;
+
+	*len = 0;
+	*str = NULL;
+
+	new_str = kmalloc(input_len, GFP_KERNEL);
+	if (!new_str)
+		return -ENOMEM;
+
+	for (i = 0; i < input_len; i += 5) {
+		strncpy(tmp, input + i, strlen(tmp));
+		if (kstrtol(tmp, 16, &ch) == 0) {
+			// escape char
+			if (ch == '\\' || ch == '\r' || ch == '\n' || ch == '\t') {
+				if (ch == '\r')
+					ch = 'r';
+				else if (ch == '\n')
+					ch = 'n';
+				else if (ch == '\t')
+					ch = 't';
+				new_str[new_len++] = '\\';
+			}
+			new_str[new_len++] = ch;
+			if (ch == '\0')
+				break;
+		}
+	}
+
+	if (new_len) {
+		new_str[new_len] = '\0';
+		*str = krealloc(new_str, (new_len + 1) * sizeof(char), GFP_KERNEL);
+		if (*str)
+			*len = new_len;
+		else
+			ret = -ENOMEM;
+	} else {

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 507

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+		ret = -EFAULT;
+	}
+
+	if (ret)
+		kfree(new_str);
+	return ret;
+}
+
+/* map output size to the corresponding WMI method id */
+inline int encode_outsize_for_pvsz(int outsize)

Please drop the inline here.

Quoted 734 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +559 -0
+{
+	if (outsize > 4096)
+		return -EINVAL;
+	if (outsize > 1024)
+		return 5;
+	if (outsize > 128)
+		return 4;
+	if (outsize > 4)
+		return 3;
+	if (outsize > 0)
+		return 2;
+	return 1;
+}
+
+/*
+ * Update friendly display name for several attributes associated to
+ * 'Schedule Power-On'
+ */
+void friendly_user_name_update(char *path, const char *attr_name,
+				char *attr_display, int attr_size)
+{
+	char *found = NULL;
+
+	found = strstr(path, SCHEDULE_POWER_ON);
+	if (found)
+		snprintf(attr_display,
+			 attr_size,
+			 "%s - %s",
+			 SCHEDULE_POWER_ON,
+			 attr_name);
+	else
+		strscpy(attr_display, attr_name, attr_size);
+}
+
+/**
+ * update_attribute_permissions() - Update attributes permissions when
+ * isReadOnly value is 1
+ *
+ * @isReadOnly:  ReadOnly value
+ * @current_val: kobj_attribute corresponding to attribute.
+ *
+ **/
+void update_attribute_permissions(u32 isReadOnly, struct kobj_attribute *current_val)
+{
+	if (isReadOnly)
+		current_val->attr.mode = (umode_t)0444;
+	else
+		current_val->attr.mode = (umode_t)0644;
+}
+
+
+/**
+ * destroy_attribute_objs() - Free a kset of kobjects
+ * @kset: The kset to destroy
+ *
+ * Fress kobjects created for each attribute_name under attribute type kset
+ */
+static void destroy_attribute_objs(struct kset *kset)
+{
+	struct kobject *pos, *next;
+
+	list_for_each_entry_safe(pos, next, &kset->list, entry)
+		kobject_put(pos);
+}
+
+/**
+ * release_attributes_data() - Clean-up all sysfs directories and files created
+ */
+static void release_attributes_data(void)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+
+	exit_string_attributes();
+	exit_integer_attributes();
+	exit_enumeration_attributes();
+	exit_ordered_list_attributes();
+	exit_password_attributes();
+	exit_sure_start_attributes();
+	exit_sure_admin_attributes();
+	exit_secure_platform_attributes();
+
+	if (bioscfg_drv.authentication_dir_kset) {
+		destroy_attribute_objs(bioscfg_drv.authentication_dir_kset);
+		kset_unregister(bioscfg_drv.authentication_dir_kset);
+		bioscfg_drv.authentication_dir_kset = NULL;
+	}
+	if (bioscfg_drv.main_dir_kset) {
+		sysfs_remove_file(&bioscfg_drv.main_dir_kset->kobj, &pending_reboot.attr);
+		sysfs_remove_file(&bioscfg_drv.main_dir_kset->kobj, &last_error.attr);
+		destroy_attribute_objs(bioscfg_drv.main_dir_kset);
+		kset_unregister(bioscfg_drv.main_dir_kset);
+		bioscfg_drv.main_dir_kset = NULL;
+	}
+	mutex_unlock(&bioscfg_drv.mutex);
+}
+
+
+/*
+ * hp_add_other_attributes - Initialize HP custom attributes not reported by
+ * BIOS and required to support Secure Platform, Sure Start, and Sure
+ * Admin.
+ * @attr_type: Custom HP attribute not reported by BIOS
+ *
+ * Initialiaze all 3 types of attributes: Platform, Sure Start, and Sure
+ * Admin object.  Populates each attrbute types respective properties
+ * under sysfs files.
+ *
+ * Returns zero(0) if successful.  Otherwise, a negative value.
+ */
+static int hp_add_other_attributes(int attr_type)
+{
+	struct kobject *attr_name_kobj;
+	union acpi_object *obj = NULL;
+	int retval = 0;
+	u8 *attr_name;
+
+	mutex_lock(&bioscfg_drv.mutex);
+
+	attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL);
+	if (!attr_name_kobj) {
+		retval = -ENOMEM;
+		goto err_other_attr_init;
+	}
+
+	/* Check if attribute type is supported */
+	switch (attr_type) {
+	case HPWMI_SECURE_PLATFORM_TYPE:
+		attr_name_kobj->kset = bioscfg_drv.authentication_dir_kset;
+		attr_name = SPM_STR;
+		break;
+
+	case HPWMI_SURE_START_TYPE:
+		attr_name_kobj->kset = bioscfg_drv.main_dir_kset;
+		attr_name = SURE_START_STR;
+		break;
+
+	case HPWMI_SURE_ADMIN_TYPE:
+		attr_name_kobj->kset = bioscfg_drv.main_dir_kset;
+		attr_name = SURE_ADMIN_STR;
+		break;
+	default:
+		pr_err("Error: Unknown attr_type: %d\n", attr_type);
+		retval = -EINVAL;
+		goto err_other_attr_init;
+	}
+
+	retval = kobject_init_and_add(attr_name_kobj, &attr_name_ktype,
+				      NULL, "%s", attr_name);
+	if (retval) {
+		pr_err("Error encountered [%d]\n", retval);
+		kobject_put(attr_name_kobj);
+		goto err_other_attr_init;
+	}
+
+	/* Populate attribute data */
+	switch (attr_type) {
+	case HPWMI_SECURE_PLATFORM_TYPE:
+		retval = populate_secure_platform_data(attr_name_kobj);
+		break;
+
+	case HPWMI_SURE_START_TYPE:
+		retval = populate_sure_start_data(attr_name_kobj);
+		break;
+
+	case HPWMI_SURE_ADMIN_TYPE:
+		retval = populate_sure_admin_data(attr_name_kobj);
+		break;
+
+	default:
+		goto err_other_attr_init;
+	}
+
+	mutex_unlock(&bioscfg_drv.mutex);
+	return 0;
+
+err_other_attr_init:
+	mutex_unlock(&bioscfg_drv.mutex);
+	kfree(obj);
+	return retval;
+}
+
+/*
+ * hp_init_bios_attributes - Initialize all attributes for a type
+ * @attr_type: The attribute type to initialize
+ * @guid: The WMI GUID associated with this type to initialize
+ *
+ * Initialiaze all 5 types of attributes: enumeration, integer,
+ * string, password, ordered list  object.  Populates each attrbute types
+ * respective properties under sysfs files
+ */
+static int hp_init_bios_attributes(int attr_type, const char *guid)
+{
+	struct kobject *attr_name_kobj;
+	union acpi_object *obj = NULL;
+	union acpi_object *elements;
+	struct kset *tmp_set;
+	int min_elements;
+	char *str = NULL;
+	char *temp_str = NULL;
+	char *str_value = NULL;
+	int str_len;
+	int ret = 0;
+
+	u8 *buffer_ptr = NULL;
+	int buffer_size;
+
+
+	/* instance_id needs to be reset for each type GUID
+	 * also, instance IDs are unique within GUID but not across
+	 */
+	int instance_id = 0;
+	int retval = 0;
+
+	retval = alloc_attributes_data(attr_type);
+	if (retval)
+		return retval;
+
+	switch (attr_type) {
+	case HPWMI_STRING_TYPE:
+		min_elements = 12;
+		break;
+	case HPWMI_INTEGER_TYPE:
+		min_elements = 13;
+		break;
+	case HPWMI_ENUMERATION_TYPE:
+		min_elements = 13;
+		break;
+	case HPWMI_ORDERED_LIST_TYPE:
+		min_elements = 12;
+		break;
+	case HPWMI_PASSWORD_TYPE:
+		min_elements = 15;
+		break;
+	default:
+		pr_err("Error: Unknown attr_type: %d\n", attr_type);
+		return -EINVAL;
+	}
+
+	/* need to use specific instance_id and guid combination to get right data */
+	obj = get_wmiobj_pointer(instance_id, guid);
+
+	if (!obj)
+		return -ENODEV;
+
+	mutex_lock(&bioscfg_drv.mutex);
+	while (obj) {
+		if (obj->type != ACPI_TYPE_PACKAGE && obj->type != ACPI_TYPE_BUFFER) {
+			pr_err("Error: Expected ACPI-package or buffer type, got: %d\n", obj->type);
+			retval = -EIO;
+			goto err_attr_init;
+		}
+
+		/* Take action appropriate to each ACPI TYPE */
+		if (obj->type == ACPI_TYPE_PACKAGE) {
+			if (obj->package.count < min_elements) {
+				pr_err("Error: ACPI-package does not have enough elements: %d < %d\n",
+				       obj->package.count, min_elements);
+				goto nextobj;
+			}
+
+			elements = obj->package.elements;
+			/* sanity checking */
+			if (elements[NAME].type != ACPI_TYPE_STRING) {
+				pr_debug("incorrect element type\n");
+				goto nextobj;
+			}
+			if (strlen(elements[NAME].string.pointer) == 0) {
+				pr_debug("empty attribute found\n");
+				goto nextobj;
+			}
+			if (attr_type == HPWMI_PASSWORD_TYPE)
+				tmp_set = bioscfg_drv.authentication_dir_kset;
+			else
+				tmp_set = bioscfg_drv.main_dir_kset;
+
+			/* convert attribute name to string */
+			retval = convert_hexstr_to_str(&(elements[NAME].string.pointer),
+						       elements[NAME].string.length,
+						       &str_value, &str_len);
+
+			if (ACPI_FAILURE(retval)) {
+				pr_debug("Failed to populate integer package data. Error [0%0x]\n", ret);
+				kfree(str_value);
+				return ret;
+			}
+
+			if (kset_find_obj(tmp_set, str_value)) {
+				pr_debug("Duplicate attribute name found - %s\n",
+					 str_value);
+				goto nextobj;
+			}
+
+			/* build attribute */
+			attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL);
+			if (!attr_name_kobj) {
+				retval = -ENOMEM;
+				goto err_attr_init;
+			}
+
+			attr_name_kobj->kset = tmp_set;
+
+			retval = kobject_init_and_add(attr_name_kobj, &attr_name_ktype,
+						      NULL, "%s", str_value);
+			if (retval) {
+				kobject_put(attr_name_kobj);
+				goto err_attr_init;
+			}
+
+			/* enumerate all of these attributes */
+			switch (attr_type) {
+			case HPWMI_STRING_TYPE:
+				retval = populate_string_package_data(elements,
+								      instance_id,
+								      attr_name_kobj);
+				break;
+			case HPWMI_INTEGER_TYPE:
+				retval = populate_integer_package_data(elements,
+								       instance_id,
+								       attr_name_kobj);
+				break;
+			case HPWMI_ENUMERATION_TYPE:
+				retval = populate_enumeration_package_data(elements,
+									   instance_id,
+									   attr_name_kobj);
+				break;
+			case HPWMI_ORDERED_LIST_TYPE:
+				retval = populate_ordered_list_package_data(elements,
+									    instance_id,
+									    attr_name_kobj);
+				break;
+			case HPWMI_PASSWORD_TYPE:
+				retval = populate_password_package_data(elements,
+									instance_id,
+									attr_name_kobj);
+				break;
+			default:
+				break;
+			}
+
+			kfree(str_value);
+		}
+
+		if (obj->type == ACPI_TYPE_BUFFER) {
+
+			buffer_size = obj->buffer.length;
+			buffer_ptr = obj->buffer.pointer;
+
+			retval = get_string_from_buffer((u16 **)&buffer_ptr, &buffer_size, &str);
+			if (retval < 0)
+				goto err_attr_init;
+
+			if (attr_type == HPWMI_PASSWORD_TYPE || attr_type == HPWMI_SECURE_PLATFORM_TYPE)
+				tmp_set = bioscfg_drv.authentication_dir_kset;
+			else
+				tmp_set = bioscfg_drv.main_dir_kset;
+
+			if (kset_find_obj(tmp_set, str)) {
+				pr_warn("Duplicate attribute name found - %s\n",
+					 str);
+				goto nextobj;
+			}
+
+			/* build attribute */
+			attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL);
+			if (!attr_name_kobj) {
+				retval = -ENOMEM;
+				goto err_attr_init;
+			}
+
+			attr_name_kobj->kset = tmp_set;
+
+			temp_str = str;
+			if (attr_type == HPWMI_SECURE_PLATFORM_TYPE)
+				temp_str = "SPM";
+
+			retval = kobject_init_and_add(attr_name_kobj,
+						      &attr_name_ktype, NULL, "%s",
+						      temp_str);
+			if (retval) {
+				kobject_put(attr_name_kobj);
+				goto err_attr_init;
+			}
+
+			/* enumerate all of these attributes */
+			switch (attr_type) {
+			case HPWMI_STRING_TYPE:
+				retval = populate_string_buffer_data(buffer_ptr,
+								     &buffer_size,
+								     instance_id,
+								     attr_name_kobj);
+				break;
+			case HPWMI_INTEGER_TYPE:
+				retval = populate_integer_buffer_data(buffer_ptr,
+								      &buffer_size,
+								      instance_id,
+								      attr_name_kobj);
+				break;
+			case HPWMI_ENUMERATION_TYPE:
+				retval = populate_enumeration_buffer_data(buffer_ptr,
+									  &buffer_size,
+									  instance_id,
+									  attr_name_kobj);
+				break;
+			case HPWMI_ORDERED_LIST_TYPE:
+				retval = populate_ordered_list_buffer_data(buffer_ptr,
+									   &buffer_size,
+									   instance_id,
+									   attr_name_kobj);
+				break;
+			case HPWMI_PASSWORD_TYPE:
+				retval = populate_password_buffer_data(buffer_ptr,
+								       &buffer_size,
+								       instance_id,
+								       attr_name_kobj);
+				break;
+			default:
+				break;
+			}
+		}
+
+nextobj:
+		kfree(obj);
+		instance_id++;
+		obj = get_wmiobj_pointer(instance_id, guid);
+	}
+	mutex_unlock(&bioscfg_drv.mutex);
+	return 0;
+
+err_attr_init:
+	mutex_unlock(&bioscfg_drv.mutex);
+	kfree(obj);
+	return retval;
+}
+
+static int __init bioscfg_init(void)
+{
+	int ret = 0;
+	int bios_capable = wmi_has_guid(HP_WMI_BIOS_GUID);
+
+	if (!bios_capable) {
+		pr_err("Unable to run on non-HP system\n");
+		return -ENODEV;
+	}
+
+	ret = init_bios_attr_set_interface();
+	if (ret)
+		return ret;
+
+	ret = init_bios_attr_pass_interface();
+	if (ret)
+		goto err_exit_bios_attr_set_interface;
+
+	if (!bioscfg_drv.bios_attr_wdev || !bioscfg_drv.password_attr_wdev) {
+		pr_debug("Failed to find set or pass interface\n");
+		ret = -ENODEV;
+		goto err_exit_bios_attr_pass_interface;
+	}
+
+	ret = fw_attributes_class_get(&fw_attr_class);
+	if (ret)
+		goto err_exit_bios_attr_pass_interface;
+
+	bioscfg_drv.class_dev = device_create(fw_attr_class, NULL, MKDEV(0, 0),
+					      NULL, "%s", DRIVER_NAME);
+	if (IS_ERR(bioscfg_drv.class_dev)) {
+		ret = PTR_ERR(bioscfg_drv.class_dev);
+		goto err_unregister_class;
+	}
+
+	bioscfg_drv.main_dir_kset = kset_create_and_add("attributes", NULL,
+						     &bioscfg_drv.class_dev->kobj);
+	if (!bioscfg_drv.main_dir_kset) {
+		ret = -ENOMEM;
+		pr_debug("Failed to create and add attributes\n");
+		goto err_destroy_classdev;
+	}
+
+	bioscfg_drv.authentication_dir_kset = kset_create_and_add("authentication", NULL,
+								&bioscfg_drv.class_dev->kobj);
+	if (!bioscfg_drv.authentication_dir_kset) {
+		ret = -ENOMEM;
+		pr_debug("Failed to create and add authentication\n");
+		goto err_release_attributes_data;
+	}
+
+	/*
+	 * sysfs level attributes.
+	 * - reset_bios
+	 * - pending_reboot
+	 * - last_error (WMI error)
+	 */
+	ret = create_attributes_level_sysfs_files();
+	if (ret)
+		pr_debug("Failed to create sysfs level attributes\n");
+
+	ret = hp_init_bios_attributes(HPWMI_STRING_TYPE, HP_WMI_BIOS_STRING_GUID);
+	if (ret)
+		pr_debug("Failed to populate string type attributes\n");
+
+	ret = hp_init_bios_attributes(HPWMI_INTEGER_TYPE, HP_WMI_BIOS_INTEGER_GUID);
+	if (ret)
+		pr_debug("Failed to populate integer type attributes\n");
+
+	ret = hp_init_bios_attributes(HPWMI_ENUMERATION_TYPE, HP_WMI_BIOS_ENUMERATION_GUID);
+	if (ret)
+		pr_debug("Failed to populate enumeration type attributes\n");
+
+	ret = hp_init_bios_attributes(HPWMI_ORDERED_LIST_TYPE, HP_WMI_BIOS_ORDERED_LIST_GUID);
+	if (ret)
+		pr_debug("Failed to populate ordered list object type attributes\n");
+
+	ret = hp_init_bios_attributes(HPWMI_PASSWORD_TYPE, HP_WMI_BIOS_PASSWORD_GUID);
+	if (ret)
+		pr_debug("Failed to populate password object type attributes\n");
+
+	ret = hp_add_other_attributes(HPWMI_SECURE_PLATFORM_TYPE);
+	if (ret)
+		pr_debug("Failed to populate secure platform object type attribute\n");
+
+	ret = hp_add_other_attributes(HPWMI_SURE_START_TYPE);
+	if (ret)
+		pr_debug("Failed to populate sure start object type attribute\n");
+
+	ret = hp_add_other_attributes(HPWMI_SURE_ADMIN_TYPE);
+	if (ret)
+		pr_debug("Failed to populate sure admin object type attribute\n");
+
+	return 0;
+
+err_release_attributes_data:
+	release_attributes_data();
+
+err_destroy_classdev:
+	device_destroy(fw_attr_class, MKDEV(0, 0));
+
+err_unregister_class:
+	fw_attributes_class_put();
+
+err_exit_bios_attr_pass_interface:
+	exit_bios_attr_pass_interface();
+
+err_exit_bios_attr_set_interface:
+	exit_bios_attr_set_interface();
+
+	return ret;
+}
+
+static void __exit bioscfg_exit(void)
+{
+	release_attributes_data();
+	device_destroy(fw_attr_class, MKDEV(0, 0));
+
+	fw_attributes_class_put();
+	exit_bios_attr_set_interface();
+	exit_bios_attr_pass_interface();
+}
+
+module_init(bioscfg_init);
+module_exit(bioscfg_exit);
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +169 -0
new file mode 100644
index 000000000000..6d9c896bf14a
@@ -0,0 +1,673 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Definitions for kernel modules using hp_bioscfg driver
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#ifndef _HP_BIOSCFG_H_
+#define _HP_BIOSCFG_H_
+
+#include <linux/wmi.h>
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/capability.h>
+#include <linux/nls.h>
+
+
+#define DRIVER_NAME	"hp-bioscfg"
+
+#define MAX_BUFF		512
+#define MAX_KEY_MOD		256
+#define MAX_PASSWD_SIZE		64
+#define MAX_MESSAGE_SIZE        256
+
+#define SPM_STR_DESC	"Secure Platform Management"
+#define SPM_STR		"SPM"
+#define SURE_START_DESC "Sure Start"
+#define SURE_START_STR  "Sure_Start"
+#define SURE_ADMIN_DESC "Sure Admin"
+#define SURE_ADMIN_STR  "Sure_Admin"
+#define SETUP_PASSWD	"Setup Password"
+#define POWER_ON_PASSWD	"Power-On Password"
+
+#define LANG_CODE_STR		"en_US.UTF-8"
+#define SCHEDULE_POWER_ON	"Scheduled Power-On"
+
+/* Sure Admin Functions */
+
+#define UTF_PREFIX	((unsigned char *)"<utf-16/>")
+#define BEAM_PREFIX	((unsigned char *)"<BEAM/>")
+
+/* mechanism - Authentication attribute */
+
+#define MAX_MECHANISM_TYPES 3
+
+enum mechanism_values {
+	PASSWORD	= 0x00,
+	NOT_PROVISION   = 0x00,
+	SIGNING_KEY	= 0x01,
+	ENDORSEMENT_KEY = 0x02
+};
+
+static const char * const spm_mechanism_types[] = {
+	"not provision",
+	"signing-key",
+	"endorsement-key"
+};
+
+static const char * const passwd_mechanism_types[] = {
+	"password",
+};
+
+/* roles - Authentication attribute */
+enum role_values {
+	BIOS_ADMIN	= 0x00,
+	POWER_ON	= 0x01,
+	BIOS_SPM	= 0x02
+};
+
+static const char * const role_type[] = {
+	"bios-admin",
+	"power-on",
+	"enhanced-bios-auth"
+};
+
+
+#define HP_WMI_BIOS_GUID		"5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
+
+#define HP_WMI_BIOS_STRING_GUID		"988D08E3-68F4-4c35-AF3E-6A1B8106F83C"
+#define HP_WMI_BIOS_INTEGER_GUID	"8232DE3D-663D-4327-A8F4-E293ADB9BF05"
+#define HP_WMI_BIOS_ENUMERATION_GUID	"2D114B49-2DFB-4130-B8FE-4A3C09E75133"
+#define HP_WMI_BIOS_ORDERED_LIST_GUID	"14EA9746-CE1F-4098-A0E0-7045CB4DA745"
+#define HP_WMI_BIOS_PASSWORD_GUID	"322F2028-0F84-4901-988E-015176049E2D"
+#define HP_WMI_SET_BIOS_SETTING_GUID	"1F4C91EB-DC5C-460b-951D-C7CB9B4B8D5E"
+
+enum hp_wmi_spm_commandtype {
+	HPWMI_SECUREPLATFORM_GET_STATE  = 0x10,
+	HPWMI_SECUREPLATFORM_SET_KEK	= 0x11,
+	HPWMI_SECUREPLATFORM_SET_SK	= 0x12,
+};
+
+enum hp_wmi_surestart_commandtype {
+	HPWMI_SURESTART_GET_LOG_COUNT	= 0x01,
+	HPWMI_SURESTART_GET_LOG		= 0x02,
+};
+
+enum hp_wmi_command {
+	HPWMI_READ		= 0x01,
+	HPWMI_WRITE		= 0x02,
+	HPWMI_ODM		= 0x03,
+	HPWMI_SURESTART		= 0x20006,
+	HPWMI_GM		= 0x20008,
+	HPWMI_SECUREPLATFORM	= 0x20010,
+};
+
+struct bios_return {
+	u32 sigpass;
+	u32 return_code;
+};
+
+enum hp_return_value {
+	HPWMI_RET_WRONG_SIGNATURE	= 0x02,
+	HPWMI_RET_UNKNOWN_COMMAND	= 0x03,
+	HPWMI_RET_UNKNOWN_CMDTYPE	= 0x04,
+	HPWMI_RET_INVALID_PARAMETERS	= 0x05,
+};
+
+enum wmi_error_values {
+	SUCCESS			= 0x00,
+	CMD_FAILED			= 0x01,
+	INVALID_SIGN			= 0x02,
+	INVALID_CMD_VALUE		= 0x03,
+	INVALID_CMD_TYPE		= 0x04,
+	INVALID_DATA_SIZE		= 0x05,
+	INVALID_CMD_PARAM		= 0x06,
+	ENCRYP_CMD_REQUIRED		= 0x07,
+	NO_SECURE_SESSION		= 0x08,
+	SECURE_SESSION_FOUND		= 0x09,
+	SECURE_SESSION_FAILED		= 0x0A,
+	AUTH_FAILED			= 0x0B,
+	INVALID_BIOS_AUTH		= 0x0E,
+	NONCE_DID_NOT_MATCH		= 0x18,
+	GENERIC_ERROR			= 0x1C,
+	BIOS_ADMIN_POLICY_NOT_MET	= 0x28,
+	BIOS_ADMIN_NOT_SET		= 0x38,
+	P21_NO_PROVISIONED		= 0x1000,
+	P21_PROVISION_IN_PROGRESS	= 0x1001,
+	P21_IN_USE			= 0x1002,
+	HEP_NOT_ACTIVE			= 0x1004,
+	HEP_ALREADY_SET		= 0x1006,
+	HEP_CHECK_STATE		= 0x1007
+};
+
+enum spm_features {
+	HEP_ENABLED		= 0x01,
+	PLATFORM_RECOVERY	= 0x02,
+	ENHANCED_BIOS_AUTH_MODE	= 0x04
+};
+
+
+/*
+ * struct bios_args buffer is dynamically allocated.  New WMI command types
+ * were introduced that exceeds 128-byte data size.  Changes to handle
+ * the data size allocation scheme were kept in hp_wmi_perform_qurey function.
+ */
+struct bios_args {
+	u32 signature;
+	u32 command;
+	u32 commandtype;
+	u32 datasize;
+	u8 data[];
+};
+
+
+#pragma pack(1)
+struct secureplatform_provisioning_data {
+	u8 state;

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h line 179

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+	u8 version[2];
+	u8 reserved1;
+	u32 features;
+	u32 nonce;
+	u8 reserved2[28];
+	u8 sk_mod[MAX_KEY_MOD];
+	u8 kek_mod[MAX_KEY_MOD];
+};
+
+#pragma pack()

There is no need for this, since these structures are not shared with the firmware.

Please drop this.

Quoted 286 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +286 -0
+
+
+struct string_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+	u8 current_value[MAX_BUFF];
+	u8 new_value[MAX_BUFF];
+	u8 path[MAX_BUFF];
+	u32 is_readonly;
+	u32 display_in_ui;
+	u32 requires_physical_presence;
+	u32 sequence;
+	u32 prerequisitesize;
+	u8 prerequisites[MAX_BUFF];
+	u32 security_level;
+	u32 min_length;
+	u32 max_length;
+	u8 display_name_language_code[MAX_BUFF];
+	u32 type;
+};
+
+struct integer_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+	u32 current_value;
+	u32 new_value;
+	u8 path[MAX_BUFF];
+	u32 is_readonly;
+	u32 display_in_ui;
+	u32 requires_physical_presence;
+	u32 sequence;
+	u32 prerequisitesize;
+	u8 prerequisites[MAX_BUFF];
+	u32 security_level;
+	u32 lower_bound;
+	u32 upper_bound;
+	u32 scalar_increment;
+	u8 display_name_language_code[MAX_BUFF];
+	u32 type;
+};
+
+struct enumeration_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+	u8 path[MAX_BUFF];
+	u32 is_readonly;
+	u32 display_in_ui;
+	u32 requires_physical_presence;
+	u32 sequence;
+	u32 prerequisitesize;
+	u8 prerequisites[MAX_BUFF];
+	u32 security_level;
+	u8 current_value[MAX_BUFF];
+	u8 new_value[MAX_BUFF];
+	u32 size;
+	u8 possible_values[MAX_BUFF];
+	u8 display_name_language_code[MAX_BUFF];
+	u32 type;
+};
+
+struct ordered_list_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+	u8 current_value[MAX_BUFF];
+	u8 new_value[MAX_BUFF];
+	u8 path[MAX_BUFF];
+	u32 is_readonly;
+	u32 display_in_ui;
+	u32 requires_physical_presence;
+	u32 sequence;
+	u32 prerequisitesize;
+	u8 prerequisites[MAX_BUFF];
+	u32 security_level;
+	u32 size;
+	u8 elements[MAX_BUFF];
+	u8 display_name_language_code[MAX_BUFF];
+	u32 type;
+};
+
+struct password_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+	u8 current_password[MAX_PASSWD_SIZE];
+	u8 new_password[MAX_PASSWD_SIZE];
+	u8 path[MAX_BUFF];
+	u32 is_readonly;
+	u32 display_in_ui;
+	u32 requires_physical_presence;
+	u32 sequence;
+	u32 prerequisitesize;
+	u8 prerequisites[MAX_BUFF];
+	u32 security_level;
+	u32 min_password_length;
+	u32 max_password_length;
+	u32 encoding_size;
+	u8 supported_encoding[MAX_BUFF];
+	u8 display_name_language_code[MAX_BUFF];
+	u32 is_enabled;
+
+	// 'bios-admin' 'power-on'
+	u32 role;
+
+	//'password'
+	u32 mechanism;
+	u32 type;
+};
+
+struct secure_platform_data {
+	struct kobject *attr_name_kobj;
+	u8 attribute_name[MAX_BUFF];
+	u8 display_name[MAX_BUFF];
+
+	u8 *endorsement_key;
+	u8 *signing_key;
+
+	u32 is_enabled;
+	u32 mechanism;
+	u32 type;
+};
+
+struct bioscfg_priv {
+	struct wmi_device *password_attr_wdev;
+	struct wmi_device *bios_attr_wdev;
+	struct kset *authentication_dir_kset;
+	struct kset *main_dir_kset;
+	struct device *class_dev;
+	struct string_data *string_data;
+	u32 string_instances_count;
+	struct integer_data *integer_data;
+	u32 integer_instances_count;
+	struct enumeration_data *enumeration_data;
+	u32 enumeration_instances_count;
+	struct ordered_list_data *ordered_list_data;
+	u32 ordered_list_instances_count;
+	struct password_data *password_data;
+	u32 password_instances_count;
+
+	struct kobject *sure_start_attr_kobj;
+	struct kobject *sure_admin_attr_kobj;
+	struct secure_platform_data spm_data;
+
+	int  last_wmi_status;
+	bool pending_reboot;
+	struct mutex mutex;
+};
+
+/* global structure used by multiple WMI interfaces */
+extern struct bioscfg_priv bioscfg_drv;
+
+enum hp_wmi_data_type {
+	HPWMI_STRING_TYPE		= 0x00,
+	HPWMI_INTEGER_TYPE		= 0x01,
+	HPWMI_ENUMERATION_TYPE		= 0x02,
+	HPWMI_ORDERED_LIST_TYPE		= 0x03,
+	HPWMI_PASSWORD_TYPE		= 0x04,
+	HPWMI_SECURE_PLATFORM_TYPE	= 0x05,
+	HPWMI_SURE_START_TYPE		= 0x06,
+	HPWMI_SURE_ADMIN_TYPE           = 0x07,
+};
+
+enum hp_wmi_data_elements {
+
+	/* Common elements */
+	NAME = 0,
+	VALUE = 1,
+	PATH = 2,
+	IS_READONLY = 3,
+	DISPLAY_IN_UI = 4,
+	REQUIRES_PHYSICAL_PRESENCE = 5,
+	SEQUENCE = 6,
+	PREREQUISITE_SIZE = 7,
+	PREREQUISITES = 8,
+	SECURITY_LEVEL = 9,
+
+	/* String elements */
+	STR_MIN_LENGTH = 10,
+	STR_MAX_LENGTH = 11,
+
+	/* Integer elements */
+	INT_LOWER_BOUND = 10,
+	INT_UPPER_BOUND = 11,
+	INT_SCALAR_INCREMENT = 12,
+
+	/* Enumeration elements */
+	ENUM_CURRENT_VALUE = 10,
+	ENUM_SIZE = 11,
+	ENUM_POSSIBLE_VALUES = 12,
+
+	/* Ordered list elements */
+	ORD_LIST_SIZE = 10,
+	ORD_LIST_ELEMENTS = 11,
+
+	/* Password elements */
+	PSWD_MIN_LENGTH = 10,
+	PSWD_MAX_LENGTH = 11,
+	PSWD_SIZE = 12,
+	PSWD_SUPPORTED_ENCODING = 13,
+	PSWD_IS_SET = 14
+};
+
+
+static const int hp_wmi_elements_count[] = {
+	12,   // string
+	13,   // integer
+	13,   // enumeration
+	12,   // ordered list
+	15    // password
+};
+
+#define get_instance_id(type)							\
+static int get_##type##_instance_id(struct kobject *kobj)			\
+{										\
+	int i; \
+								\
+	for (i = 0; i <= bioscfg_drv.type##_instances_count; i++) { \
+		if (!(strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name))) \
+			return i;						\
+	}									\
+	return -EIO;								\
+}
+
+#define get_instance_id_for_attribute(type)			\
+static int get_instance_id_for_##type(char *attr_name)		\
+{										\
+	int i;									\
+										\
+	for (i = 0; i < bioscfg_drv.type##_instances_count; i++) {		\
+		if (strcmp(bioscfg_drv.type##_data[i].attr_name_kobj->name, attr_name) == 0)						\
+			return i;						\
+	}									\
+	return -EIO;								\
+}
+
+#define attribute_s_property_show(name, type)					\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr,	\
+			   char *buf)						\
+{										\
+	int i = get_##type##_instance_id(kobj);					\
+	if (i >= 0)								\
+		return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].name);	\
+	return 0;								\
+}
+/* There is no need to keep track of default and current values
+ * separately
+ */
+#define attribute_s_default_property_show(name, type, new_name)			\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr,	\
+			   char *buf)						\
+{										\
+	int i = get_##type##_instance_id(kobj);					\
+	if (i >= 0)								\
+		return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].new_name);	\
+	return 0;								\
+}
+
+#define attribute_n_default_property_show(name, type, new_name)			\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr,	\
+			   char *buf)						\
+{										\
+	int i = get_##type##_instance_id(kobj);					\
+	if (i >= 0)								\
+		return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].new_name); \
+	return 0;								\
+}
+
+#define attribute_n_property_show(name, type)					\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr,	\
+			   char *buf)						\
+{										\
+	int i = get_##type##_instance_id(kobj);					\
+	if (i >= 0)								\
+		return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].name);	\
+	return 0;								\
+}
+
+
+#define attribute_property_store(curr_val, type)				\
+static ssize_t curr_val##_store(struct kobject *kobj,				\
+				struct kobj_attribute *attr,			\
+				const char *buf, size_t count)			\
+{										\

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h line 498

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+	char *p = NULL;							\
+	char *attr_value = NULL;						\
+	char *attr_name = NULL;							\
+	int i;									\
+	int ret = -EIO;								\
+										\
+	attr_name = kstrdup(kobj->name, GFP_KERNEL);				\
+	if (!attr_name)								\
+		return -ENOMEM;							\
+

Since you don't modify attr_name (unlike attr_value) there is no need to make a local copy, just use kobj->name directly instead of the copy stored in attr_name.

										\
Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +7 -0
+	attr_value = kstrdup(buf, GFP_KERNEL);					\
+	if (!attr_value)							\
+		return -ENOMEM;							\
+										\
+	p = memchr(attr_value, '\n', count);					\
+	if (p != NULL)								\
+		*p = '\0';							\

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h line 492

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+										\
+	i = get_##type##_instance_id(kobj);					\
+	if (i >= 0)								\
+		ret = validate_##type##_input(i, attr_value);			\
+	if (!ret)								\
+		ret = hp_set_attribute(attr_name, attr_value);			\
+	if (!ret)								\
+		update_##type##_value(i, attr_value);				\
+										\
+	clear_all_passwords();							\

Why ?

At a minimum add a comment explaining this.

Quoted 169 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +169 -0
+	kfree(attr_name);							\
+	kfree(attr_value);							\
+										\
+	return ret ? ret : count;						\
+}
+
+#define attribute_spm_n_property_show(name, type)				\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
+{									\
+	return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data.name);\
+}
+
+#define attribute_spm_s_property_show(name, type)				\
+static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
+{									\
+	return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data.name);		\
+}
+
+#define check_property_type(attr, prop, valuetype)\
+	(attr##_obj[prop].type != valuetype)
+
+#define HPWMI_BINATTR_RW(_group, _name, _size)	\
+static struct bin_attribute _group##_##_name =	\
+__BIN_ATTR(_name, 0444 | 0200, _group##_##_name##_read, _group##_##_name##_write, _size)
+
+/*
+ * Prototypes
+ */
+union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string);
+int get_instance_count(const char *guid_string);
+void strlcpy_attr(char *dest, char *src);
+void update_attribute_permissions(u32 isReadOnly, struct kobj_attribute *current_val);
+void friendly_user_name_update(char *path, const char *attr_name,
+				char *attr_display, int attr_size);
+
+/* String attributes */
+int populate_string_buffer_data(u8 *buffer_ptr, int *buffer_size,
+			 int instance_id,
+			 struct kobject *attr_name_kobj);
+int populate_string_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					 int instance_id,
+					 enum hp_wmi_data_type type);
+int alloc_string_data(void);
+void exit_string_attributes(void);
+int populate_string_package_data(union acpi_object *str_obj,
+				 int instance_id,
+				 struct kobject *attr_name_kobj);
+int populate_string_elements_from_package(union acpi_object *str_obj,
+						  int instance_id,
+						  enum hp_wmi_data_type type);
+
+/* Integer attributes */
+int populate_integer_buffer_data(u8 *buffer_ptr, int *buffer_size,
+			  int instance_id,
+			  struct kobject *attr_name_kobj);
+int populate_integer_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					  int instance_id,
+					  enum hp_wmi_data_type type);
+int alloc_integer_data(void);
+void exit_integer_attributes(void);
+int populate_integer_package_data(union acpi_object *integer_obj,
+				  int instance_id,
+				  struct kobject *attr_name_kobj);
+int populate_integer_elements_from_package(union acpi_object *integer_obj,
+						  int instance_id,
+						  enum hp_wmi_data_type type);
+
+/* Enumeration attributes */
+int populate_enumeration_buffer_data(u8 *buffer_ptr, int *buffer_size,
+			      int instance_id,
+			      struct kobject *attr_name_kobj);
+int populate_enumeration_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					      int instance_id,
+					      enum hp_wmi_data_type type);
+int alloc_enumeration_data(void);
+void exit_enumeration_attributes(void);
+int populate_enumeration_package_data(union acpi_object *enum_obj,
+				      int instance_id,
+				      struct kobject *attr_name_kobj);
+int populate_enumeration_elements_from_package(union acpi_object *enum_obj,
+					       int instance_id,
+					       enum hp_wmi_data_type type);
+
+/* Ordered list */
+int populate_ordered_list_buffer_data(u8 *buffer_ptr,
+				      int *buffer_size,
+				      int instance_id,
+				      struct kobject *attr_name_kobj);
+int populate_ordered_list_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					       int instance_id,
+					       enum hp_wmi_data_type type);
+int alloc_ordered_list_data(void);
+void exit_ordered_list_attributes(void);
+int populate_ordered_list_package_data(union acpi_object *order_obj,
+				       int instance_id,
+				       struct kobject *attr_name_kobj);
+int populate_ordered_list_elements_from_package(union acpi_object *order_obj,
+						int instance_id,
+						enum hp_wmi_data_type type);
+
+/* Password authentication attributes */
+int populate_password_buffer_data(u8 *buffer_ptr, int *buffer_size,
+			   int instance_id,
+			   struct kobject *attr_name_kobj);
+int populate_password_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					   int instance_id,
+					   enum hp_wmi_data_type type);
+int populate_password_package_data(union acpi_object *password_obj,
+				   int instance_id,
+				   struct kobject *attr_name_kobj);
+int populate_password_elements_from_package(union acpi_object *password_obj,
+					   int instance_id,
+					    enum hp_wmi_data_type type);
+int alloc_password_data(void);
+int alloc_secure_platform_data(void);
+void exit_password_attributes(void);
+void exit_secure_platform_attributes(void);
+int populate_secure_platform_data(struct kobject *attr_name_kobj);
+int password_is_set(const char *auth);
+int check_spm_is_enabled(void);
+int wmi_error_and_message(int error_code, char *message);
+int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size);
+int hp_wmi_perform_query(int query, enum hp_wmi_command command,
+				void *buffer, int insize, int outsize);
+
+/* Sure Start attributes */
+void exit_sure_start_attributes(void);
+int populate_sure_start_data(struct kobject *attr_name_kobj);
+
+/* Sure Admin Attributes */
+void exit_sure_admin_attributes(void);
+int populate_sure_admin_data(struct kobject *attr_name_kobj);
+int hp_set_attribute(const char *a_name, const char *a_value);
+int hp_set_attribute_with_payload(const char *a_name,
+				  const char *a_value,
+				  const char *auth_payload);
+int update_attribute_value(char *attr_name, char *attr_value);
+int hp_bios_settings_fill_buffer(void);
+int hp_bios_settings_free_buffer(void);
+int hp_bios_settings_realloc_buffer(char **buf, int *buf_size,
+					   int *alloc_size);
+int append_read_string_attributes(char *buf, int alloc_size,
+					int instance,
+					enum hp_wmi_data_type type);
+int append_read_integer_attributes(char *buf, int alloc_size,
+					 int instance,
+					 enum hp_wmi_data_type type);
+int append_read_enumeration_attributes(char *buf, int alloc_size,
+					     int instance,
+					     enum hp_wmi_data_type type);
+int append_read_ordered_list_attributes(char *buf, int alloc_size,
+					      int instance,
+					      enum hp_wmi_data_type type);
+int append_read_password_attributes(char *buf, int alloc_size,
+					 int instance,
+					 enum hp_wmi_data_type type);
+int append_read_settings(enum hp_wmi_data_type type, char **buf,
+			      int *buf_size, int *alloc_size);
+int append_read_attributes(char **buf, int alloc_size,
+				 int instance, enum hp_wmi_data_type type);
+int set_bios_defaults(u8 defType);
+int get_password_instance_for_type(const char *name);
+int clear_all_passwords(void);
+int clear_passwords(const int instance);
+void exit_bios_attr_set_interface(void);
+int init_bios_attr_set_interface(void);
+size_t calculate_string_buffer(const char *str);
+size_t calculate_security_buffer(const char *authentication);
+void populate_security_buffer(u16 *buffer, const char *authentication);

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h line 671

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+ssize_t populate_string_buffer(u16 *buffer, size_t buffer_len, const char *str);
+int set_new_password(const char *password_type, const char *new_password);
+int init_bios_attr_pass_interface(void);
+void exit_bios_attr_pass_interface(void);
+void *ascii_to_utf16_unicode(u16 *p, const u8 *str);
+int get_integer_from_buffer(int **buffer, int *buffer_size, int *integer);
+int get_string_from_buffer(u16 **buffer, int *buffer_size, char **str);
+int convert_hexstr_to_str(char **hex, int input_len, char **str, int *len);
+int convert_hexstr_to_int(char *str, int *int_value);
+inline int encode_outsize_for_pvsz(int outsize);

Please drop the inline here.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h line 673

Quoted 2 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +2 -0
+
+#endif

Regards,

Hans

p.s.

I've run out of time / energy for today I will continue reviewing this patch-set tomorrow.

#10 lore raw

Re: [PATCH v5 2/5] Introduction of HP-BIOSCFG driver (2)

Hi Jorge,

Quoted 7 lines · Hans de Goede

Hi Jorge,

First of all some generic remarks which apply to all patches:

1. Quite a few non local / non static functions have generic names like e.g. calculate_string_buffer().

Quoted 8 lines

If this code is build into the main kernel vmlinuz then these will all be part of a global namespace, leading to potential symbol collisions to avoid these please make the following 2 changes

i) Make functions which are only used in a single .c file static e.g. wmi_error_and_message()
ii) Prefix others with hp_bioscfg_, e.g. hp_bioscfg_calculate_string_buffer()
to avoid possible symbol clashes

One more generic remark. All the struct string_data, struct integer_data, etc. structs have an attribute_name member. But except for some leftover code filling (but never reading) that in spmobj-attributes.c there is no code using that. Please remove the attribute_name member from all the string_ / integer_ / enumeration_data, etc. structs.

Also some more issues in this patch which I noticed while looking at patch 3/5:

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 36

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+int get_integer_from_buffer(int **buffer, int *buffer_size, int *integer)
+{
+	int *ptr = PTR_ALIGN(*buffer, 4);

This may move the ptr, but if it does, then buffer_size should be modified accordingly since you have just consumed some buffer-space by moving the pointer.

So you will want to add something like this:

	int align_size = (char *)ptr - (char *)(*buffer);

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 40

Quoted 4 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +4 -0
+
+	/* Ensure there is enough space remaining to read the integer */
+	if (*buffer_size < sizeof(int))
+		return -EINVAL;

This check is not correct, because you are not taking the alignment adjustment which I mentioned above into account instead this should be:

	if (*buffer_size < (sizeof(int) + align_size))
		return -EINVAL;

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 43

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+
+	*integer = *(ptr++);
+	*buffer = ptr;

And this:

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 44

Quoted 1 line
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1 -0
+	*buffer_size -= sizeof(int);

Should be:

	*buffer_size -= sizeof(int) + align_size;
Quoted 4 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +4 -0
+
+	return 0;
+}
+

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 58

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+int get_string_from_buffer(u16 **buffer, int *buffer_size, char **str)
+{
+	u16 *ptr = *buffer;
+	u16 ptrlen;
+
+	u16 size;
+	int i;
+	char *output = NULL;
+	int escape = 0;
+

What if *buffer_size is 0 at this point already, now you have just read past the end of the buffer.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 65

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+	ptrlen = *(ptr++);
+	size = ptrlen / 2;
+
+	/* Ensure there is enough space remaining to read and convert
+	 * the string
+	 */
+	if (*buffer_size < (size *  sizeof(u16)))

Use " < ptrlen" here ?

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 72

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+		return -EINVAL;
+
+
+	for (i = 0; i < size; i++)
+		if (ptr[i] == '\\' || ptr[i] == '\r' || ptr[i] == '\n' || ptr[i] == '\t')
+			escape++;
+

There are a number of issues with the code below.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 73

Quoted 1 line
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1 -0
+	size += escape;

This not only increases the allocated size, but also causes the for (i = 0; i < size; i++) to loop over the extra space allocated for escaping special chars, while it also does:

		if (*ptr == '\\' || *ptr == '\r' || *ptr == '\n' || *ptr == '\t')
			output[i++] = '\\';

Which increases i, so in the end this will end up writing

size + esc times to output even though the size of output is only size + 1.

so I think you simply want to put the + escape inside the kcalloc like this:

	*str = kcalloc(size + escape + 1, sizeof(char), GFP_KERNEL);

And keep size at it was (instead of incrementing it with esc).

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 83

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	*str = kcalloc(size + 1, sizeof(char), GFP_KERNEL);
+	if (!*str)
+		return -ENOMEM;
+
+	output = *str;
+
+	/*
+	 * convert from UTF-16 unicode to ASCII
+	 */
+	utf16s_to_utf8s(ptr, ptrlen, UTF16_HOST_ENDIAN, output, size);

There are 4 issues with just this single line:

1. The inlen parameter of utf16s_to_utf8s is in wchar_t-s not in bytes, so you should pass size here, not ptrlen
2. The size of the destination buffer is simply the number of u16-s in the source string, but a single u16 may expand to a multi-byte UTF8 sequence so that might be too small.
3. In the for loop below you are completely overwriting the result of this conversion, so you might just as well not have made this call at all
4. You are not using the return value which may be different from size because of the multi-byte sequence expansion.

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+
+	for (i = 0; i < size; i++) {
+		if (*ptr == '\\' || *ptr == '\r' || *ptr == '\n' || *ptr == '\t')
+			output[i++] = '\\';
+
+		if (*ptr == '\r')
+			output[i] = 'r';

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 100

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+		else if (*ptr == '\n')
+			output[i] = 'n';
+		else if (*ptr == '\t')
+			output[i] = 't';
+		else if (*ptr == '"')
+			output[i] = '\'';
+		else
+			output[i] = *ptr;
+		ptr++;
+	}

You are not properly 0 terminating the string here, since you have kcalloc-ed the memory this will be fine (if we forget about the possible buffer overruns when escaping). But it would be better to use a regular malloc, avoiding needlessly clearing the mem and then explicitly add the 0 termination here.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 103

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+
+	*buffer = ptr;
+	*buffer_size -= size * sizeof(u16);

This is not taking into account the 2 bytes used by the size header, those should also be subtracted.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return size;
+}

As for determining outsize, I notice that in all the call sites of get_string_from_buffer() you are copying the returned string to a fixed-size destination buffer, so instead of allocating it here, you can just pass in that fixed size buffer right away, also removig a needless malloc + strcpy + free in the process.

So all in all I think this function should look something like this (untested):

int get_string_from_buffer(u8 **buffer, int *buffer_size, char *dst, int dst_size)

{
	u16 *src = (u16 *)(*buffer);
	int in, out, src_size, len;

	if (buffer_size < sizeof(u16))
		return -EINVAL;

	src_size = *src++;
	*buffer_size -= sizeof(u16)

	if (*buffer_size < src_size)
		return -EINVAL;

	/* convert size bytes -> u16 units */
	src_size /= sizeof(u16);

	in = 0;
	out = 0;
	while (in < src_size && out < dst_size) {
		len = 0;
		while (in + len < src_size && src[in + len] != '\\' && src[in + len] != '\r' && src[in + len] != '\n' && src[in + len] != '\t' && src[in + len] != '"')
			len++;

		if (len) {
			out += utf16s_to_utf8s(src + in, len, UTF16_HOST_ENDIAN, dst + out, dst_size - out);
			in += len;
			continue;
		}

		/* Special case convert " -> ' */
		if (src[in] == '"') {
			dst[out++] = '\'';
			in++;
			continue;
		}

		dst[out++] = '\\';
		if (out == dst_size)
			break;

		if (src[in] == '\\')
			dst[out++] = '\\';
		else if (src[in] == '\r')
			dst[out++] = 'r';
		else if (src[in] == '\n')
			dst[out++] = 'n';
		else if (src[in] == '\t')
			dst[out++] = 't';

		in++;
	}

	if (out == output_size) {
		pr_warn("UTF16 string too long, truncated\n");
		out--;
	}

	dst[out] = 0;

	*buffer += src_size * sizeof(u16);
	*buffer_size -= in * sizeof(u16);
	return 0;
}

Note I have also changed the buffer function parameter type from u16 ** to u8** so that callers don't need to cast it.

Regards,

Hans

I'll continue reviewing this patch-set later, not sure yet when ...

#11 lore raw

Re: [PATCH v5 2/5] Introduction of HP-BIOSCFG driver (2)

Hi,

Quoted 238 lines · Hans de Goede

Hi Jorge,

Quoted 7 lines · Hans de Goede

Hi Jorge,

First of all some generic remarks which apply to all patches:

1. Quite a few non local / non static functions have generic names like e.g. calculate_string_buffer().

Quoted 8 lines

If this code is build into the main kernel vmlinuz then these will all be part of a global namespace, leading to potential symbol collisions to avoid these please make the following 2 changes

i) Make functions which are only used in a single .c file static e.g. wmi_error_and_message()
ii) Prefix others with hp_bioscfg_, e.g. hp_bioscfg_calculate_string_buffer()
to avoid possible symbol clashes

One more generic remark. All the struct string_data, struct integer_data, etc. structs have an attribute_name member. But except for some leftover code filling (but never reading) that in spmobj-attributes.c there is no code using that. Please remove the attribute_name member from all the string_ / integer_ / enumeration_data, etc. structs.

Also some more issues in this patch which I noticed while looking at patch 3/5:

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 36

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+int get_integer_from_buffer(int **buffer, int *buffer_size, int *integer)
+{
+	int *ptr = PTR_ALIGN(*buffer, 4);

This may move the ptr, but if it does, then buffer_size should be modified accordingly since you have just consumed some buffer-space by moving the pointer.

So you will want to add something like this:

	int align_size = (char *)ptr - (char *)(*buffer);

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 40

Quoted 4 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +4 -0
+
+	/* Ensure there is enough space remaining to read the integer */
+	if (*buffer_size < sizeof(int))
+		return -EINVAL;

This check is not correct, because you are not taking the alignment adjustment which I mentioned above into account instead this should be:

	if (*buffer_size < (sizeof(int) + align_size))
		return -EINVAL;

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 43

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+
+	*integer = *(ptr++);
+	*buffer = ptr;

And this:

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 44

Quoted 1 line
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1 -0
+	*buffer_size -= sizeof(int);

Should be:

	*buffer_size -= sizeof(int) + align_size;
Quoted 4 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +4 -0
+
+	return 0;
+}
+

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 58

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+int get_string_from_buffer(u16 **buffer, int *buffer_size, char **str)
+{
+	u16 *ptr = *buffer;
+	u16 ptrlen;
+
+	u16 size;
+	int i;
+	char *output = NULL;
+	int escape = 0;
+

What if *buffer_size is 0 at this point already, now you have just read past the end of the buffer.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 65

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+	ptrlen = *(ptr++);
+	size = ptrlen / 2;
+
+	/* Ensure there is enough space remaining to read and convert
+	 * the string
+	 */
+	if (*buffer_size < (size *  sizeof(u16)))

Use " < ptrlen" here ?

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 72

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+		return -EINVAL;
+
+
+	for (i = 0; i < size; i++)
+		if (ptr[i] == '\\' || ptr[i] == '\r' || ptr[i] == '\n' || ptr[i] == '\t')
+			escape++;
+

There are a number of issues with the code below.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 73

Quoted 1 line
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1 -0
+	size += escape;

This not only increases the allocated size, but also causes the for (i = 0; i < size; i++) to loop over the extra space allocated for escaping special chars, while it also does:

		if (*ptr == '\\' || *ptr == '\r' || *ptr == '\n' || *ptr == '\t')
			output[i++] = '\\';

Which increases i, so in the end this will end up writing

size + esc times to output even though the size of output is only size + 1.

so I think you simply want to put the + escape inside the kcalloc like this:

	*str = kcalloc(size + escape + 1, sizeof(char), GFP_KERNEL);

And keep size at it was (instead of incrementing it with esc).

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 83

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+	*str = kcalloc(size + 1, sizeof(char), GFP_KERNEL);
+	if (!*str)
+		return -ENOMEM;
+
+	output = *str;
+
+	/*
+	 * convert from UTF-16 unicode to ASCII
+	 */
+	utf16s_to_utf8s(ptr, ptrlen, UTF16_HOST_ENDIAN, output, size);

There are 4 issues with just this single line:

1. The inlen parameter of utf16s_to_utf8s is in wchar_t-s not in bytes, so you should pass size here, not ptrlen
2. The size of the destination buffer is simply the number of u16-s in the source string, but a single u16 may expand to a multi-byte UTF8 sequence so that might be too small.
3. In the for loop below you are completely overwriting the result of this conversion, so you might just as well not have made this call at all
4. You are not using the return value which may be different from size because of the multi-byte sequence expansion.

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +7 -0
+
+	for (i = 0; i < size; i++) {
+		if (*ptr == '\\' || *ptr == '\r' || *ptr == '\n' || *ptr == '\t')
+			output[i++] = '\\';
+
+		if (*ptr == '\r')
+			output[i] = 'r';

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 100

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +10 -0
+		else if (*ptr == '\n')
+			output[i] = 'n';
+		else if (*ptr == '\t')
+			output[i] = 't';
+		else if (*ptr == '"')
+			output[i] = '\'';
+		else
+			output[i] = *ptr;
+		ptr++;
+	}

You are not properly 0 terminating the string here, since you have kcalloc-ed the memory this will be fine (if we forget about the possible buffer overruns when escaping). But it would be better to use a regular malloc, avoiding needlessly clearing the mem and then explicitly add the 0 termination here.

drivers/platform/x86/hp/hp-bioscfg/bioscfg.c line 103

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +3 -0
+
+	*buffer = ptr;
+	*buffer_size -= size * sizeof(u16);

This is not taking into account the 2 bytes used by the size header, those should also be subtracted.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return size;
+}

As for determining outsize, I notice that in all the call sites of get_string_from_buffer() you are copying the returned string to a fixed-size destination buffer, so instead of allocating it here, you can just pass in that fixed size buffer right away, also removig a needless malloc + strcpy + free in the process.

So all in all I think this function should look something like this (untested):

int get_string_from_buffer(u8 **buffer, int *buffer_size, char *dst, int dst_size)

{
	u16 *src = (u16 *)(*buffer);
	int in, out, src_size, len;

	if (buffer_size < sizeof(u16))
		return -EINVAL;

	src_size = *src++;
	*buffer_size -= sizeof(u16)

	if (*buffer_size < src_size)
		return -EINVAL;

	/* convert size bytes -> u16 units */
	src_size /= sizeof(u16);

	in = 0;
	out = 0;
	while (in < src_size && out < dst_size) {
		len = 0;
		while (in + len < src_size && src[in + len] != '\\' && src[in + len] != '\r' && src[in + len] != '\n' && src[in + len] != '\t' && src[in + len] != '"')
			len++;

		if (len) {
			out += utf16s_to_utf8s(src + in, len, UTF16_HOST_ENDIAN, dst + out, dst_size - out);
			in += len;
			continue;
		}

		/* Special case convert " -> ' */
		if (src[in] == '"') {
			dst[out++] = '\'';
			in++;
			continue;
		}

		dst[out++] = '\\';
		if (out == dst_size)
			break;

		if (src[in] == '\\')
			dst[out++] = '\\';
		else if (src[in] == '\r')
			dst[out++] = 'r';
		else if (src[in] == '\n')
Quoted 8 lines
			dst[out++] = 'n';
		else if (src[in] == '\t')
			dst[out++] = 't';

		in++;
	}

	if (out == output_size) {

Correction should be:

if (out == dst_size) {

Quoted 8 lines
		pr_warn("UTF16 string too long, truncated\n");
		out--;
	}

	dst[out] = 0;

	*buffer += src_size * sizeof(u16);
	*buffer_size -= in * sizeof(u16);

Correction this line should be:

*buffer_size -= src_size * sizeof(u16);

Normally these will be the same but if we run out of output space then that might break the loop and then in < src_size.

Quoted 15 lines
	return 0;
}

Note I have also changed the buffer function parameter type from u16 ** to u8** so that callers don't need to cast it.

Regards,

Hans

I'll continue reviewing this patch-set later, not sure yet when ...

#12 lore raw

PATCH v5 3/5 Introduction of HP-BIOSCFG driver (3)

In reply to Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 499 ++++++++++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        | 450 ++++++++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    | 549 ++++++++++++++++++
 3 files changed, 1498 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +499 -0
new file mode 100644
index 000000000000..5ef81daf0099
@@ -0,0 +1,499 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to enumeration type attributes under
+ * BIOS Enumeration GUID for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include "bioscfg.h"
+
+get_instance_id(enumeration);
+
+static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+	int instance_id = get_enumeration_instance_id(kobj);
+	ssize_t ret;
+
+	if (instance_id < 0)
+		return -EIO;
+
+	ret = sysfs_emit(buf, "%s\n",
+			    bioscfg_drv.enumeration_data[instance_id].current_value);
+
+	return ret;
+}
+
+/*
+ * validate_enumeration_input() -
+ * Validate input of current_value against possible values
+ *
+ * @instance_id: The instance on which input is validated
+ * @buf: Input value
+ */
+static int validate_enumeration_input(int instance_id, const char *buf)
+{
+	char *options = NULL;
+	char *p;
+	int ret = 0;
+	int found = 0;
+
+	/* Is it a read only attribute */
+	if (bioscfg_drv.enumeration_data[instance_id].is_readonly)
+		return -EIO;
+
+	options = kstrdup(bioscfg_drv.enumeration_data[instance_id].possible_values,
+			  GFP_KERNEL);
+
+	if (!options) {
+		ret = -ENOMEM;
+		goto exit_validate_enum_input;
+	}
+
+
+	while ((p = strsep(&options, ";")) != NULL) {
+		if (!*p)
+			continue;
+
+		if (!strcasecmp(p, buf)) {
+			found = 1;
+			break;
+		}
+	}
+
+	if (!found) {
+		ret = -EINVAL;
+		goto exit_validate_enum_input;
+	}
+
+	/*
+	 * set pending reboot flag depending on
+	 * "RequiresPhysicalPresence" value
+	 */
+	if (bioscfg_drv.enumeration_data[instance_id].requires_physical_presence)
+		bioscfg_drv.pending_reboot = TRUE;
+
+exit_validate_enum_input:
+	kfree(options);
+	return ret;
+}
+
+static void update_enumeration_value(int instance_id, char *attr_value)
+{
+	strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+		attr_value,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));
+}
+
+
+attribute_s_property_show(display_name_language_code, enumeration);
+static struct kobj_attribute enumeration_display_langcode =
+		__ATTR_RO(display_name_language_code);
+
+attribute_s_property_show(display_name, enumeration);
+static struct kobj_attribute  enumeration_display_name =
+		__ATTR_RO(display_name);
+
+attribute_property_store(current_value, enumeration);
+static struct kobj_attribute enumeration_current_val =
+	__ATTR_RW_MODE(current_value, 0644);
+
+attribute_s_property_show(possible_values, enumeration);
+static struct kobj_attribute  enumeration_poss_val =
+		__ATTR_RO(possible_values);
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sysfs_emit(buf, "enumeration\n");
+}
+static struct kobj_attribute enumeration_type =
+		__ATTR_RO(type);
+
+static struct attribute *enumeration_attrs[] = {
+	&enumeration_display_langcode.attr,
+	&enumeration_display_name.attr,
+	&enumeration_current_val.attr,
+	&enumeration_poss_val.attr,
+	&enumeration_type.attr,
+	NULL,
+};
+
+static const struct attribute_group enumeration_attr_group = {
+	.attrs = enumeration_attrs,
+};
+
+int alloc_enumeration_data(void)
+{
+	int ret = 0;
+
+	bioscfg_drv.enumeration_instances_count =
+		get_instance_count(HP_WMI_BIOS_ENUMERATION_GUID);
+
+	bioscfg_drv.enumeration_data = kcalloc(bioscfg_drv.enumeration_instances_count,
+					sizeof(struct enumeration_data), GFP_KERNEL);
+	if (!bioscfg_drv.enumeration_data) {
+		bioscfg_drv.enumeration_instances_count = 0;
+		ret = -ENOMEM;
+	}
+	return ret;
+}
+
+/*
+ * populate_enumeration_package_data() -
+ * Populate all properties of an instance under enumeration attribute
+ *
+ * @enum_obj: ACPI object with enumeration data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_enumeration_package_data(union acpi_object *enum_obj, int instance_id,
+			struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;
+	bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	populate_enumeration_elements_from_package(enum_obj, instance_id, HPWMI_ENUMERATION_TYPE);
+	update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+				     &enumeration_current_val);
+	/*
+	 * Several attributes have names such "MONDAY".  Friendly
+	 * user nane is generated to make the name more descriptive
+	 */
+	friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.enumeration_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+	return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
+}
+
+int populate_enumeration_elements_from_package(union acpi_object *enum_obj,
+					   int instance_id,
+					   enum hp_wmi_data_type type)
+{
+	char *str_value = NULL;
+	int value_len;
+	int status = 0;
+	u32 size = 0;
+	u32 int_value;
+	int elem = 0;
+	int reqs;
+	int eloc;
+	int pos_values;
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name_language_code));
+
+	for (elem = 1, eloc = 1; elem < hp_wmi_elements_count[type]; elem++, eloc++) {
+
+		switch (enum_obj[elem].type) {
+		case ACPI_TYPE_STRING:
+
+			if (PREREQUISITES != elem && ENUM_POSSIBLE_VALUES != elem) {
+				status = convert_hexstr_to_str(&enum_obj[elem].string.pointer,
+							       enum_obj[elem].string.length,
+							       &str_value, &value_len);
+				if (ACPI_FAILURE(status))
+					continue;
+
+			}
+			break;
+		case ACPI_TYPE_INTEGER:
+			int_value = (u32)enum_obj[elem].integer.value;
+			break;
+		default:
+			pr_warn("Unsupported object type [%d]\n", enum_obj[elem].type);
+			continue;
+		}
+
+		/* stop if extra counter is greater than total number
+		 * of elements for enumeration type
+		 */
+		if (eloc == hp_wmi_elements_count[type])
+			goto exit_enumeration_package;
+
+		/* Assign appropriate element value to corresponding field*/
+		switch (eloc) {
+		case VALUE:
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].path, str_value,
+				sizeof(bioscfg_drv.enumeration_data[instance_id].path));
+			break;
+		case IS_READONLY:
+			bioscfg_drv.enumeration_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.enumeration_data[instance_id].display_in_ui = int_value;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.enumeration_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.enumeration_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].prerequisitesize = int_value;
+			if (int_value > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+			/*
+			 * prerequisites element is omitted when
+			 * prerequisitesSize value is zero.
+			 */
+			if (int_value == 0)
+				eloc++;
+			break;
+		case PREREQUISITES:
+			size = bioscfg_drv.enumeration_data[instance_id].prerequisitesize;
+
+			for (reqs = 0; reqs < size; reqs++) {
+				status = convert_hexstr_to_str(&enum_obj[elem].string.pointer,
+							       enum_obj[elem].string.length,
+							       &str_value, &value_len);
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites,
+					str_value,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.enumeration_data[instance_id].security_level = int_value;
+			break;
+
+		case ENUM_CURRENT_VALUE:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+				str_value, sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));
+			break;
+		case ENUM_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].size = int_value;
+			break;
+		case ENUM_POSSIBLE_VALUES:
+			size = bioscfg_drv.enumeration_data[instance_id].size;
+			for (pos_values = 0; pos_values < size; pos_values++) {
+				status = convert_hexstr_to_str(&enum_obj[elem + pos_values].string.pointer,
+							       enum_obj[elem  + pos_values].string.length,
+							       &str_value, &value_len);
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values,
+					str_value,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				if (pos_values < (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+
+		kfree(str_value);
+		str_value = NULL;
+	}
+
+exit_enumeration_package:
+		kfree(str_value);
+		str_value = NULL;
+	return 0;
+}
+
+/*
+ * populate_enumeration_buffer_data() -
+ * Populate all properties of an instance under enumeration attribute
+ *
+ * @buffer_ptr: Buffer pointer
+ * @buffer_size: Buffer size
+ * @enum_obj: ACPI object with enumeration data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ * @enumeration_property_count: Total properties count under enumeration type
+ */
+int populate_enumeration_buffer_data(u8 *buffer_ptr, int *buffer_size,
+				     int instance_id,
+				     struct kobject *attr_name_kobj)
+{
+
+	bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;
+	bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	/* Populate enumeration elements */
+	populate_enumeration_elements_from_buffer(buffer_ptr, buffer_size,
+						  instance_id,
+						  HPWMI_ENUMERATION_TYPE);
+
+	update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+				    &enumeration_current_val);
+	/*
+	 * Several attributes have names such "MONDAY". A Friendlier
+	 * user nane is generated to make the name more descriptive
+	 */
+	friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.enumeration_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+	return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
+}
+
+int populate_enumeration_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					      int instance_id,
+					      enum hp_wmi_data_type type)
+{
+	int status;
+	char *str = NULL;
+	int elem;
+	int reqs;
+	int integer;
+	int size = 0;
+	int values;
+
+	elem = 0;
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name_language_code));
+
+	for (elem = 1; elem < 3; elem++) {
+
+		status = get_string_from_buffer((u16 **)&buffer_ptr,
+						buffer_size, &str);
+		if (status < 0)
+			continue;
+
+		switch (elem) {
+		case VALUE:
+			/* Skip 'Value' since 'CurrentValue' is reported. */
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].path,
+				str, sizeof(bioscfg_drv.enumeration_data[instance_id].path));
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+
+		kfree(str);
+		str = NULL;
+	}
+
+	for (elem = 3; elem < hp_wmi_elements_count[type]; elem++) {
+		if (PREREQUISITES != elem && ENUM_CURRENT_VALUE != elem && ENUM_POSSIBLE_VALUES != elem) {
+			status = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer);
+			if (status < 0)
+				continue;
+		}
+
+		switch (elem) {
+		case IS_READONLY:
+			bioscfg_drv.enumeration_data[instance_id].is_readonly = integer;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.enumeration_data[instance_id].display_in_ui = integer;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.enumeration_data[instance_id].requires_physical_presence = integer;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.enumeration_data[instance_id].sequence = integer;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].prerequisitesize = integer;
+			if (integer > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+			break;
+		case PREREQUISITES:
+			size = bioscfg_drv.enumeration_data[instance_id].prerequisitesize;
+			for (reqs = 0; reqs < size; reqs++) {
+				status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+				if (status < 0)
+					continue;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites,
+					str,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		case SECURITY_LEVEL:
+			bioscfg_drv.enumeration_data[instance_id].security_level = integer;
+			break;
+		case ENUM_CURRENT_VALUE:
+			status = get_string_from_buffer((u16 **)&buffer_ptr,
+							buffer_size, &str);
+			if (status < 0)
+				continue;
+
+			strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+				str,
+				sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));
+			break;
+		case ENUM_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].size = integer;
+			break;
+		case ENUM_POSSIBLE_VALUES:
+			size = bioscfg_drv.enumeration_data[instance_id].size;
+			for (values = 0; values < size; values++) {
+				status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+				if (status < 0)
+					continue;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values,
+					str,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				if (values != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+	kfree(str);
+
+	return 0;
+}
+
+/**
+ * exit_enumeration_attributes() - Clear all attribute data
+ *
+ * Clears all data allocated for this group of attributes
+ */
+void exit_enumeration_attributes(void)
+{
+	int instance_id;
+
+	for (instance_id = 0; instance_id < bioscfg_drv.enumeration_instances_count; instance_id++) {
+		if (bioscfg_drv.enumeration_data[instance_id].attr_name_kobj)
+			sysfs_remove_group(bioscfg_drv.enumeration_data[instance_id].attr_name_kobj,
+					   &enumeration_attr_group);
+	}
+	bioscfg_drv.enumeration_instances_count = 0;
+
+	kfree(bioscfg_drv.enumeration_data);
+	bioscfg_drv.enumeration_data = NULL;
+}
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c new file +450 -0

450 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c new file +549 -0

549 lines not on this page · raw message

Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v5 3/5] Introduction of HP-BIOSCFG driver (3)

Hi,

Detailed review inline.

Quoted 204 lines · Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 499 ++++++++++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        | 450 ++++++++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    | 549 ++++++++++++++++++
 3 files changed, 1498 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +141 -0
new file mode 100644
index 000000000000..5ef81daf0099
@@ -0,0 +1,499 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to enumeration type attributes under
+ * BIOS Enumeration GUID for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include "bioscfg.h"
+
+get_instance_id(enumeration);
+
+static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+	int instance_id = get_enumeration_instance_id(kobj);
+	ssize_t ret;
+
+	if (instance_id < 0)
+		return -EIO;
+
+	ret = sysfs_emit(buf, "%s\n",
+			    bioscfg_drv.enumeration_data[instance_id].current_value);
+
+	return ret;
+}
+
+/*
+ * validate_enumeration_input() -
+ * Validate input of current_value against possible values
+ *
+ * @instance_id: The instance on which input is validated
+ * @buf: Input value
+ */
+static int validate_enumeration_input(int instance_id, const char *buf)
+{
+	char *options = NULL;
+	char *p;
+	int ret = 0;
+	int found = 0;
+
+	/* Is it a read only attribute */
+	if (bioscfg_drv.enumeration_data[instance_id].is_readonly)
+		return -EIO;
+
+	options = kstrdup(bioscfg_drv.enumeration_data[instance_id].possible_values,
+			  GFP_KERNEL);
+
+	if (!options) {
+		ret = -ENOMEM;
+		goto exit_validate_enum_input;
+	}
+
+
+	while ((p = strsep(&options, ";")) != NULL) {
+		if (!*p)
+			continue;
+
+		if (!strcasecmp(p, buf)) {
+			found = 1;
+			break;
+		}
+	}
+
+	if (!found) {
+		ret = -EINVAL;
+		goto exit_validate_enum_input;
+	}
+
+	/*
+	 * set pending reboot flag depending on
+	 * "RequiresPhysicalPresence" value
+	 */
+	if (bioscfg_drv.enumeration_data[instance_id].requires_physical_presence)
+		bioscfg_drv.pending_reboot = TRUE;
+
+exit_validate_enum_input:
+	kfree(options);
+	return ret;
+}
+
+static void update_enumeration_value(int instance_id, char *attr_value)
+{
+	strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+		attr_value,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));
+}
+
+
+attribute_s_property_show(display_name_language_code, enumeration);
+static struct kobj_attribute enumeration_display_langcode =
+		__ATTR_RO(display_name_language_code);
+
+attribute_s_property_show(display_name, enumeration);
+static struct kobj_attribute  enumeration_display_name =
+		__ATTR_RO(display_name);
+
+attribute_property_store(current_value, enumeration);
+static struct kobj_attribute enumeration_current_val =
+	__ATTR_RW_MODE(current_value, 0644);
+
+attribute_s_property_show(possible_values, enumeration);
+static struct kobj_attribute  enumeration_poss_val =
+		__ATTR_RO(possible_values);
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sysfs_emit(buf, "enumeration\n");
+}
+static struct kobj_attribute enumeration_type =
+		__ATTR_RO(type);
+
+static struct attribute *enumeration_attrs[] = {
+	&enumeration_display_langcode.attr,
+	&enumeration_display_name.attr,
+	&enumeration_current_val.attr,
+	&enumeration_poss_val.attr,
+	&enumeration_type.attr,
+	NULL,
+};
+
+static const struct attribute_group enumeration_attr_group = {
+	.attrs = enumeration_attrs,
+};
+
+int alloc_enumeration_data(void)
+{
+	int ret = 0;
+
+	bioscfg_drv.enumeration_instances_count =
+		get_instance_count(HP_WMI_BIOS_ENUMERATION_GUID);
+
+	bioscfg_drv.enumeration_data = kcalloc(bioscfg_drv.enumeration_instances_count,
+					sizeof(struct enumeration_data), GFP_KERNEL);
+	if (!bioscfg_drv.enumeration_data) {
+		bioscfg_drv.enumeration_instances_count = 0;
+		ret = -ENOMEM;
+	}
+	return ret;
+}
+

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 151

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+/*
+ * populate_enumeration_package_data() -
+ * Populate all properties of an instance under enumeration attribute
+ *
+ * @enum_obj: ACPI object with enumeration data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_enumeration_package_data(union acpi_object *enum_obj, int instance_id,
+			struct kobject *attr_name_kobj)

Please indent this so that the s of struct is aligned directly after the ( of (union.

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 153

Quoted 2 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +2 -0
+{
+	bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;

The type member of struct enumeration_data is only ever set and never read, please drop the type member of struct enumeration_data.

*And also do the same for the type member of all the other foo_data structs*

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +7 -0
+	bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	populate_enumeration_elements_from_package(enum_obj, instance_id, HPWMI_ENUMERATION_TYPE);
+	update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+				     &enumeration_current_val);
+	/*
+	 * Several attributes have names such "MONDAY".  Friendly

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 170

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	 * user nane is generated to make the name more descriptive
+	 */
+	friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.enumeration_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+	return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
+}
+
+int populate_enumeration_elements_from_package(union acpi_object *enum_obj,

This needs to be passed the obj->package.count value from hp_init_bios_attributes() so that it can verify that it does not go out of bounds when getting the possible values, so this needs:

int enum_obj_count,

as extra parameter.

Quoted 8 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +8 -0
+					   int instance_id,
+					   enum hp_wmi_data_type type)
+{
+	char *str_value = NULL;
+	int value_len;
+	int status = 0;
+	u32 size = 0;
+	u32 int_value;

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 188

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	int elem = 0;
+	int reqs;
+	int eloc;
+	int pos_values;
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name_language_code));
+
+	for (elem = 1, eloc = 1; elem < hp_wmi_elements_count[type]; elem++, eloc++) {

You should use " < enum_obj_count" here.

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 198

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+
+		switch (enum_obj[elem].type) {
+		case ACPI_TYPE_STRING:
+
+			if (PREREQUISITES != elem && ENUM_POSSIBLE_VALUES != elem) {
+				status = convert_hexstr_to_str(&enum_obj[elem].string.pointer,
+							       enum_obj[elem].string.length,
+							       &str_value, &value_len);
+				if (ACPI_FAILURE(status))
+					continue;

convert_hexstr_to_str() returns a regular errno value, e.g. -EINVAL. So:

1. The value to store the result should not be named status since this is not an ACPI status, please use "err" or "ret" instead.

2. Since this is not an ACPI status you must NOT use ACPI_FAILURE(status), instead use e.g.:

				if (err)
					continue;

3. Why continue? Continuing will leave some elements of enumeration_data[instance_id] unset which will later on give problems. Why not return the error to abort the probe (since this should never happen) ?

*And also do the same for all the other convert_hexstr_to_str() callers*

Quoted 15 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +15 -0
+
+			}
+			break;
+		case ACPI_TYPE_INTEGER:
+			int_value = (u32)enum_obj[elem].integer.value;
+			break;
+		default:
+			pr_warn("Unsupported object type [%d]\n", enum_obj[elem].type);
+			continue;
+		}
+
+		/* stop if extra counter is greater than total number
+		 * of elements for enumeration type
+		 */
+		if (eloc == hp_wmi_elements_count[type])

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 223

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+			goto exit_enumeration_package;
+
+		/* Assign appropriate element value to corresponding field*/
+		switch (eloc) {
+		case VALUE:
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].path, str_value,
+				sizeof(bioscfg_drv.enumeration_data[instance_id].path));
+			break;

Over here you are assuming that str_value is set, but there is no verification that the type you did the switch-case on above is actually the type you are expecting for this eloc value.

So you need to add an array with types for each eloc and then even before doing the switch (enum_obj[elem].type) check things match.

E.g. something like this:

	acpi_object_type expected_types[] = {
		[PATH]		= ACPI_TYPE_STRING,
		[IS_READONLY]	= ACPI_TYPE_INTEGER,
		...
	};

and then in the loop, before even trying to get the string / int :

		if (enum_obj[elem].type != expected_types[eloc]) {
			pr_err("Error expected type %d for eloc %d, but got type %d instead\n",
			       expected_types[eloc], eloc, enum_obj[elem].type);
			return -EINVAL; /* or maybe -EIO ? */
		}
Quoted 6 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +6 -0
+		case IS_READONLY:
+			bioscfg_drv.enumeration_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.enumeration_data[instance_id].display_in_ui = int_value;
+			break;

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 239

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.enumeration_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.enumeration_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].prerequisitesize = int_value;
+			if (int_value > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");

I see this 20 in a bunch of places, please add a #define for this.

Quoted 4 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +4 -0
+			/*
+			 * prerequisites element is omitted when
+			 * prerequisitesSize value is zero.
+			 */

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 253

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+			if (int_value == 0)
+				eloc++;
+			break;
+		case PREREQUISITES:
+			size = bioscfg_drv.enumeration_data[instance_id].prerequisitesize;
+
+			for (reqs = 0; reqs < size; reqs++) {
+				status = convert_hexstr_to_str(&enum_obj[elem].string.pointer,
+							       enum_obj[elem].string.length,
+							       &str_value, &value_len);

Looking at the use of convert_hexstr_to_str() it gives the impression that it is intended to move the string.pointer pointer to the start of the next string. But looking at how ENUM_POSSIBLE_VALUES is handled I believe that instead the [elem] used above should be [elem + reqs] and I presume that at the end this should do elem += (reqs - 1).

Looking at this together with the:

			if (int_value == 0)
				eloc++;

Bit I believe that the right thing to do would be to completely drop PREREQUISITES as a separate value inside enum hp_wmi_data_elements and make the PREREQUISITES_SIZE handling look like this:

		case PREREQUISITE_SIZE:
			bioscfg_drv.enumeration_data[instance_id].prerequisitesize = int_value;
			if (int_value > 20)
				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");

			size = bioscfg_drv.enumeration_data[instance_id].prerequisitesize;
			for (reqs = 0; reqs < size; reqs++) {
				elem++;
				if (elem >= enum_obj_count) {
					pr_err("Error enum-objects package is too small\n");
					return -EINVAL;
				}

				if (enum_obj[elem].type != ACPI_TYPE_STRING) {
					
				}

				err = convert_hexstr_to_str(&enum_obj[elem].string.pointer,
							    enum_obj[elem].string.length,
							    &str_value, &value_len);
				if (err)
					return -EINVAL;

				strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites,
					str_value,
					sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
				if (reqs != (size - 1))
					strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites, ";",
						sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));

				kfree(str_value);
				str_value = NULL;
			}
			break;

This handles both reading the size as well as reading the pre-reqs in one go incrementing the elem index for each pre-req as I think should be done, while also bound-checking elem when increasing it.

And it removes the need for the if (int_value == 0) eloc++ hack.

###

Semi related to this, please also change the prototype of convert_hexstr_to_str() ideally replace the hex + input_len parameters with a single "union acpi_object *" parameter and then move the type != ACPI_TYPE_STRING error check to inside convert_hexstr_to_str().

If that for some reason does not work (I think it should work) then please use "const char *hex" instead of "char **hex", as first parameter since the input pointer is not changed, there is no need to pass it by reference and the function should also not change its input, hence the adding of the const.

Quoted 22 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +22 -0
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites,
+					str_value,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.enumeration_data[instance_id].security_level = int_value;
+			break;
+
+		case ENUM_CURRENT_VALUE:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+				str_value, sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 285

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+			break;
+		case ENUM_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].size = int_value;
+			break;
+		case ENUM_POSSIBLE_VALUES:
+			size = bioscfg_drv.enumeration_data[instance_id].size;
+			for (pos_values = 0; pos_values < size; pos_values++) {
+				status = convert_hexstr_to_str(&enum_obj[elem + pos_values].string.pointer,
+							       enum_obj[elem  + pos_values].string.length,
+							       &str_value, &value_len);

Please fold this together with ENUM_SIZE, like how it is done for the pre-requisites.

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 296

Quoted 11 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +11 -0
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values,
+					str_value,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				if (pos_values < (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				kfree(str_value);
+				str_value = NULL;

Hmm, you are storing all the possible values in a ';' separated string here; and then later parse that string inside validate_enumeration_input() can you please use a (fixed size, say 16 entries?) array for possible values and store the possible values in separate array entries?

This will greatly simplify validate_enumeration_input() and then replace

attribute_s_property_show(possible_values, enumeration);

with an actual show function which prints all the entries separated by ';' using sysfs_emit_at() (see thinkpad.c for an example of how to use sysfs_emit_at()).

Quoted 113 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +113 -0
+			}
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+
+		kfree(str_value);
+		str_value = NULL;
+	}
+
+exit_enumeration_package:
+		kfree(str_value);
+		str_value = NULL;
+	return 0;
+}
+
+/*
+ * populate_enumeration_buffer_data() -
+ * Populate all properties of an instance under enumeration attribute
+ *
+ * @buffer_ptr: Buffer pointer
+ * @buffer_size: Buffer size
+ * @enum_obj: ACPI object with enumeration data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ * @enumeration_property_count: Total properties count under enumeration type
+ */
+int populate_enumeration_buffer_data(u8 *buffer_ptr, int *buffer_size,
+				     int instance_id,
+				     struct kobject *attr_name_kobj)
+{
+
+	bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;
+	bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	/* Populate enumeration elements */
+	populate_enumeration_elements_from_buffer(buffer_ptr, buffer_size,
+						  instance_id,
+						  HPWMI_ENUMERATION_TYPE);
+
+	update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+				    &enumeration_current_val);
+	/*
+	 * Several attributes have names such "MONDAY". A Friendlier
+	 * user nane is generated to make the name more descriptive
+	 */
+	friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.enumeration_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+	return sysfs_create_group(attr_name_kobj, &enumeration_attr_group);
+}
+
+int populate_enumeration_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					      int instance_id,
+					      enum hp_wmi_data_type type)
+{
+	int status;
+	char *str = NULL;
+	int elem;
+	int reqs;
+	int integer;
+	int size = 0;
+	int values;
+
+	elem = 0;
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name_language_code));
+
+	for (elem = 1; elem < 3; elem++) {
+
+		status = get_string_from_buffer((u16 **)&buffer_ptr,
+						buffer_size, &str);
+		if (status < 0)
+			continue;
+
+		switch (elem) {
+		case VALUE:
+			/* Skip 'Value' since 'CurrentValue' is reported. */
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.enumeration_data[instance_id].path,
+				str, sizeof(bioscfg_drv.enumeration_data[instance_id].path));
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+
+		kfree(str);
+		str = NULL;
+	}
+
+	for (elem = 3; elem < hp_wmi_elements_count[type]; elem++) {
+		if (PREREQUISITES != elem && ENUM_CURRENT_VALUE != elem && ENUM_POSSIBLE_VALUES != elem) {
+			status = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer);
+			if (status < 0)
+				continue;
+		}
+
+		switch (elem) {
+		case IS_READONLY:
+			bioscfg_drv.enumeration_data[instance_id].is_readonly = integer;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.enumeration_data[instance_id].display_in_ui = integer;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.enumeration_data[instance_id].requires_physical_presence = integer;

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 419

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+			break;
+		case SEQUENCE:
+			bioscfg_drv.enumeration_data[instance_id].sequence = integer;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].prerequisitesize = integer;
+			if (integer > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+			break;
+		case PREREQUISITES:

If you make the changes suggested above you will need to drop the 2:

			break;
		case PREREQUISITES:

lines here.

Quoted 23 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +23 -0
+			size = bioscfg_drv.enumeration_data[instance_id].prerequisitesize;
+			for (reqs = 0; reqs < size; reqs++) {
+				status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+				if (status < 0)
+					continue;
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites,
+					str,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].prerequisites));
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		case SECURITY_LEVEL:
+			bioscfg_drv.enumeration_data[instance_id].security_level = integer;
+			break;
+		case ENUM_CURRENT_VALUE:
+			status = get_string_from_buffer((u16 **)&buffer_ptr,
+							buffer_size, &str);
+			if (status < 0)

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 452

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+				continue;
+
+			strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+				str,
+				sizeof(bioscfg_drv.enumeration_data[instance_id].current_value));
+			break;
+		case ENUM_SIZE:
+			bioscfg_drv.enumeration_data[instance_id].size = integer;
+			break;
+		case ENUM_POSSIBLE_VALUES:

If you make the changes suggested above you will need to drop the 2:

			break;
		case ENUM_POSSIBLE_VALUES:

lines here.

Quoted 5 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +5 -0
+			size = bioscfg_drv.enumeration_data[instance_id].size;
+			for (values = 0; values < size; values++) {
+				status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+				if (status < 0)
+					continue;

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 467

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+
+				strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values,
+					str,
+					sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				if (values != (size - 1))
+					strlcat(bioscfg_drv.enumeration_data[instance_id].possible_values, ";",
+						sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values));
+				kfree(str);
+				str = NULL;
+			}

Again it would be better to store the possible values in an array.

Quoted 22 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +22 -0
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+	kfree(str);
+
+	return 0;
+}
+
+/**
+ * exit_enumeration_attributes() - Clear all attribute data
+ *
+ * Clears all data allocated for this group of attributes
+ */
+void exit_enumeration_attributes(void)
+{
+	int instance_id;
+

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c line 499

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	for (instance_id = 0; instance_id < bioscfg_drv.enumeration_instances_count; instance_id++) {
+		if (bioscfg_drv.enumeration_data[instance_id].attr_name_kobj)
+			sysfs_remove_group(bioscfg_drv.enumeration_data[instance_id].attr_name_kobj,
+					   &enumeration_attr_group);
+	}
+	bioscfg_drv.enumeration_instances_count = 0;
+
+	kfree(bioscfg_drv.enumeration_data);
+	bioscfg_drv.enumeration_data = NULL;
+}

Please also apply all the above remarks (+ all previous remarks) to all the other *-attributes.c files (as applicable) and then post a v6 with these changes and the already discussed sureadmin / surestart changes.

Then I'll do another review of v6 once that is available. I expect that we will still need a v7 after v6 and I hope to be able to merge that v7 then (but no promises).

Regards,

Hans

#14 lore raw

PATCH v5 4/5 Introduction of HP-BIOSCFG driver (4)

In reply to Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |  51 ++
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  | 631 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     | 419 ++++++++++++
 3 files changed, 1101 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c new file +51 -0
new file mode 100644
index 000000000000..02fc766eb3cf
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to SET password methods under
+ * HP_WMI_SET_BIOS_SETTING_GUID for use with hp-bioscfg driver.
+ *
+ * Copyright (c) 2022 Hewlett-Packard Inc.
+ */
+
+#include <linux/wmi.h>
+#include "bioscfg.h"
+
+static int bios_attr_pass_interface_probe(struct wmi_device *wdev,
+					  const void *context)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.password_attr_wdev = wdev;
+	mutex_unlock(&bioscfg_drv.mutex);
+	return 0;
+}
+
+static void bios_attr_pass_interface_remove(struct wmi_device *wdev)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	bioscfg_drv.password_attr_wdev = NULL;
+	mutex_unlock(&bioscfg_drv.mutex);
+}
+
+static const struct wmi_device_id bios_attr_pass_interface_id_table[] = {
+	{ .guid_string = HP_WMI_SET_BIOS_SETTING_GUID },
+	{ },
+};
+static struct wmi_driver bios_attr_pass_interface_driver = {
+	.driver = {
+		.name = DRIVER_NAME"-password"
+	},
+	.probe = bios_attr_pass_interface_probe,
+	.remove = bios_attr_pass_interface_remove,
+	.id_table = bios_attr_pass_interface_id_table,
+};
+
+int init_bios_attr_pass_interface(void)
+{
+	return wmi_driver_register(&bios_attr_pass_interface_driver);
+}
+
+void exit_bios_attr_pass_interface(void)
+{
+	wmi_driver_unregister(&bios_attr_pass_interface_driver);
+}
+
+MODULE_DEVICE_TABLE(wmi, bios_attr_pass_interface_id_table);
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c new file +631 -0

631 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c new file +419 -0

419 lines not on this page · raw message

Signature · 1 line
2.34.1
#15 lore raw

PATCH v5 5/5 Introduction of HP-BIOSCFG driver (5)

In reply to Jorge Lopez

The purpose for this patch is submit HP BIOSCFG driver to be list of HP Linux kernel drivers. The driver include a total of 12 files broken in several patches. This is set 1 of 4.

HP BIOS Configuration driver purpose is to provide a driver supporting the latest sysfs class firmware attributes framework allowing the user to change BIOS settings and security solutions on HP Inc.’s commercial notebooks.

Many features of HP Commercial PC’s can be managed using Windows Management Instrumentation (WMI). WMI is an implementation of Web-Based Enterprise Management (WBEM) that provides a standards-based interface for changing and monitoring system settings. HP BISOCFG driver provides a native Linux solution and the exposed features facilitates the migration to Linux environments.

The Linux security features to be provided in hp-bioscfg driver enables managing the BIOS settings and security solutions via sysfs, a virtual
filesystem that can be used by user-mode applications. The new
documentation cover features such Secure Platform Management, Sure Admin, and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver.

Many HP Commercial PC’s include a feature called Secure Platform Management (SPM), which replaces older password-based BIOS settings management with public key cryptography. PC secure product management begins when a target system is provisioned with cryptographic keys that are used to ensure the integrity of communications between system management utilities and the BIOS.

HP Commercial PC’s have several BIOS settings that control its behaviour and capabilities, many of which are related to security. To prevent unauthorized changes to these settings, the system can be configured to use a Sure Admin cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting.

---
Based on the latest platform-drivers-x86.git/for-next

History

Version 5
Remove version 4 patch 1
Address review changes proposed in Version 4 Reorganize all patches number and file order

---
 .../x86/hp/hp-bioscfg/string-attributes.c     |  425 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 +++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  149 +++
 3 files changed, 1588 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/sureadmin-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c new file +425 -0
new file mode 100644
index 000000000000..ad20e8af3844
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to string type attributes under
+ * HP_WMI_BIOS_STRING_GUID for use with hp-bioscfg driver.
+ *
+ * Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include "bioscfg.h"
+
+#define WMI_STRING_TYPE "HPBIOS_BIOSString"
+
+get_instance_id(string);
+
+static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+	int instance_id = get_string_instance_id(kobj);
+	union acpi_object *obj = NULL;
+	ssize_t ret;
+
+	if (instance_id < 0)
+		return -EIO;
+
+	/* need to use specific instance_id and guid combination to get right data */
+	obj = get_wmiobj_pointer(instance_id, HP_WMI_BIOS_STRING_GUID);
+	if (!obj)
+		return -EIO;
+
+	ret = sysfs_emit(buf, "%s\n",
+		       bioscfg_drv.string_data[instance_id].current_value);
+
+	kfree(obj);
+	return ret;
+}
+
+/*
+ * validate_string_input() -
+ * Validate input of current_value against min and max lengths
+ *
+ * @instance_id: The instance on which input is validated
+ * @buf: Input value
+ */
+static int validate_string_input(int instance_id, const char *buf)
+{
+	int in_len = strlen(buf);
+
+	/* BIOS treats it as a read only attribute */
+	if (bioscfg_drv.string_data[instance_id].is_readonly)
+		return -EIO;
+
+	if ((in_len < bioscfg_drv.string_data[instance_id].min_length) ||
+	    (in_len > bioscfg_drv.string_data[instance_id].max_length))
+		return -EINVAL;
+
+	return 0;
+}
+
+static void update_string_value(int instance_id, char *attr_value)
+{
+	/* Write settings to BIOS */
+	strscpy(bioscfg_drv.string_data[instance_id].current_value,
+		attr_value,
+		sizeof(bioscfg_drv.string_data[instance_id].current_value));
+}
+
+attribute_s_property_show(display_name_language_code, string);
+static struct kobj_attribute string_display_langcode =
+		__ATTR_RO(display_name_language_code);
+
+attribute_s_property_show(display_name, string);
+static struct kobj_attribute string_display_name =
+		__ATTR_RO(display_name);
+
+attribute_property_store(current_value, string);
+static struct kobj_attribute string_current_val =
+		__ATTR_RW_MODE(current_value, 0644);
+
+attribute_n_property_show(min_length, string);
+static struct kobj_attribute string_min_length =
+		__ATTR_RO(min_length);
+
+attribute_n_property_show(max_length, string);
+static struct kobj_attribute string_max_length =
+		__ATTR_RO(max_length);
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sysfs_emit(buf, "string\n");
+}
+
+static struct kobj_attribute string_type =
+	__ATTR_RO(type);
+
+static struct attribute *string_attrs[] = {
+	&string_display_langcode.attr,
+	&string_display_name.attr,
+	&string_current_val.attr,
+	&string_min_length.attr,
+	&string_max_length.attr,
+	&string_type.attr,
+	NULL
+};
+
+static const struct attribute_group string_attr_group = {
+	.attrs = string_attrs,
+};
+
+int alloc_string_data(void)
+{
+	int ret = 0;
+
+	bioscfg_drv.string_instances_count = get_instance_count(HP_WMI_BIOS_STRING_GUID);
+	bioscfg_drv.string_data = kcalloc(bioscfg_drv.string_instances_count,
+					sizeof(struct string_data), GFP_KERNEL);
+	if (!bioscfg_drv.string_data) {
+		bioscfg_drv.string_instances_count = 0;
+		ret = -ENOMEM;
+	}
+	return ret;
+}
+
+/*
+ * populate_string_package_data() -
+ * Populate all properties of an instance under string attribute
+ *
+ * @elements: ACPI object with string data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_string_package_data(union acpi_object *elements, int instance_id,
+			struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.string_data[instance_id].type = HPWMI_STRING_TYPE;
+	bioscfg_drv.string_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	populate_string_elements_from_package(elements, instance_id, HPWMI_STRING_TYPE);
+	update_attribute_permissions(bioscfg_drv.string_data[instance_id].is_readonly,
+				    &string_current_val);
+	friendly_user_name_update(bioscfg_drv.string_data[instance_id].path,
+				  attr_name_kobj->name,
+				  bioscfg_drv.string_data[instance_id].display_name,
+				  sizeof(bioscfg_drv.string_data[instance_id].display_name));
+	return sysfs_create_group(attr_name_kobj, &string_attr_group);
+}
+
+int populate_string_elements_from_package(union acpi_object *elements,
+					   int instance_id,
+					   enum hp_wmi_data_type type)
+{
+	char *str_value = NULL;
+	int value_len;
+	int status = 0;
+	u32 size = 0;
+	u32 int_value;
+	int elem = 0;
+	int reqs;
+	int eloc;
+
+	if (!elements)
+		return -EINVAL;
+
+	strscpy(bioscfg_drv.string_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.string_data[instance_id].display_name_language_code));
+
+	for (elem = 1, eloc = 1; elem < hp_wmi_elements_count[type]; elem++, eloc++) {
+
+		switch (elements[elem].type) {
+		case ACPI_TYPE_STRING:
+
+			if (elem != PREREQUISITES) {
+				status = convert_hexstr_to_str(&elements[elem].string.pointer,
+							       elements[elem].string.length,
+							       &str_value, &value_len);
+
+				if (ACPI_FAILURE(status))
+					continue;
+			}
+			break;
+		case ACPI_TYPE_INTEGER:
+			int_value = (u32)elements[elem].integer.value;
+			break;
+		default:
+			pr_warn("Unsupported object type [%d]\n", elements[elem].type);
+			continue;
+		}
+
+		/*
+		 * Stop if extra counter is greater than total number
+		 * of elements for string type
+		 */
+		if (eloc == hp_wmi_elements_count[type])
+			goto exit_string_package;
+
+		/* Assign appropriate element value to corresponding field*/
+		switch (eloc) {
+		case VALUE:
+			strscpy(bioscfg_drv.string_data[instance_id].current_value,
+				str_value, sizeof(bioscfg_drv.string_data[instance_id].current_value));
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.string_data[instance_id].path, str_value,
+				sizeof(bioscfg_drv.string_data[instance_id].path));
+			break;
+		case IS_READONLY:
+			bioscfg_drv.string_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.string_data[instance_id].display_in_ui = int_value;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.string_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.string_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.string_data[instance_id].prerequisitesize = int_value;
+			if (size > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+
+			/*
+			 * prerequisites element is omitted when
+			 * prerequisitesSize value is zero.
+			 */
+			if (int_value == 0)
+				eloc++;
+			break;
+		case PREREQUISITES:
+			size = bioscfg_drv.string_data[instance_id].prerequisitesize;
+
+			for (reqs = 0; reqs < size; reqs++) {
+				status = convert_hexstr_to_str(&elements[elem].string.pointer,
+							       elements[elem].string.length,
+							       &str_value, &value_len);
+
+				if (ACPI_FAILURE(status))
+					continue;
+
+				strlcat(bioscfg_drv.string_data[instance_id].prerequisites,
+					str_value,
+					sizeof(bioscfg_drv.string_data[instance_id].prerequisites));
+
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.string_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.string_data[instance_id].prerequisites));
+
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.string_data[instance_id].security_level = int_value;
+			break;
+		case STR_MIN_LENGTH:
+			bioscfg_drv.string_data[instance_id].min_length = int_value;
+			break;
+		case STR_MAX_LENGTH:
+			bioscfg_drv.string_data[instance_id].max_length = int_value;
+			break;
+		default:
+			pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str_value);
+		str_value = NULL;
+	}
+exit_string_package:
+	kfree(str_value);
+	str_value = NULL;
+
+	return 0;
+}
+
+/*
+ * populate_string_data() -
+ * Populate all properties of an instance under string attribute
+ *
+ * @buffer_ptr: Buffer pointer
+ * @buffer_size: Buffer size
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_string_buffer_data(u8 *buffer_ptr, int *buffer_size, int instance_id, struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.string_data[instance_id].type = HPWMI_STRING_TYPE;
+	bioscfg_drv.string_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	populate_string_elements_from_buffer(buffer_ptr, buffer_size,
+					     instance_id, HPWMI_STRING_TYPE);
+	update_attribute_permissions(bioscfg_drv.string_data[instance_id].is_readonly,
+				    &string_current_val);
+	friendly_user_name_update(bioscfg_drv.string_data[instance_id].path,
+				  attr_name_kobj->name,
+				  bioscfg_drv.string_data[instance_id].display_name,
+				  sizeof(bioscfg_drv.string_data[instance_id].display_name));
+	return sysfs_create_group(attr_name_kobj, &string_attr_group);
+}
+
+int populate_string_elements_from_buffer(u8 *buffer_ptr, int *buffer_size,
+					 int instance_id, enum hp_wmi_data_type type)
+{
+	int status;
+	char *str = NULL;
+	int elem;
+	int reqs;
+	int int_value;
+	int size = 0;
+
+	strscpy(bioscfg_drv.string_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.string_data[instance_id].display_name_language_code));
+
+	for (elem = 1; elem < 3; elem++) {
+		status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+		if (status < 0)
+			continue;
+
+		switch (elem) {
+		case VALUE:
+			strscpy(bioscfg_drv.string_data[instance_id].current_value,
+				str, sizeof(bioscfg_drv.string_data[instance_id].current_value));
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.string_data[instance_id].path, str,
+				sizeof(bioscfg_drv.string_data[instance_id].path));
+			break;
+		default:
+			pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+
+	for (elem = 3; elem < hp_wmi_elements_count[type]; elem++) {
+
+		if (elem != PREREQUISITES) {
+			status = get_integer_from_buffer((int **)&buffer_ptr,
+							 buffer_size,
+							 (int *)&int_value);
+			if (status < 0)
+				continue;
+		}
+
+		switch (elem) {
+		case IS_READONLY:
+			bioscfg_drv.string_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.string_data[instance_id].display_in_ui = int_value;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.string_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.string_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.string_data[instance_id].prerequisitesize = int_value;
+			if (int_value > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+			break;
+		case PREREQUISITES:
+			size = bioscfg_drv.string_data[instance_id].prerequisitesize;
+			for (reqs = 0; reqs < size; reqs++) {
+				status = get_string_from_buffer((u16 **)&buffer_ptr, buffer_size, &str);
+				if (status < 0)
+					continue;
+
+				strlcat(bioscfg_drv.string_data[instance_id].prerequisites,
+					str,
+					sizeof(bioscfg_drv.string_data[instance_id].prerequisites));
+
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.string_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.string_data[instance_id].prerequisites));
+
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		case SECURITY_LEVEL:
+			bioscfg_drv.string_data[instance_id].security_level = int_value;
+			break;
+		case STR_MIN_LENGTH:
+			bioscfg_drv.string_data[instance_id].min_length = int_value;
+			break;
+		case STR_MAX_LENGTH:
+			bioscfg_drv.string_data[instance_id].max_length = int_value;
+			break;
+		default:
+			pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+	kfree(str);
+	str = NULL;
+
+	return 0;
+}
+
+/*
+ * exit_string_attributes() - Clear all attribute data
+ *
+ * Clears all data allocated for this group of attributes
+ */
+void exit_string_attributes(void)
+{
+	int instance_id;
+
+	for (instance_id = 0; instance_id < bioscfg_drv.string_instances_count; instance_id++) {
+		if (bioscfg_drv.string_data[instance_id].attr_name_kobj)
+			sysfs_remove_group(bioscfg_drv.string_data[instance_id].attr_name_kobj,
+					   &string_attr_group);
+	}
+	bioscfg_drv.string_instances_count = 0;
+
+	kfree(bioscfg_drv.string_data);
+	bioscfg_drv.string_data = NULL;
+}
drivers/platform/x86/hp/hp-bioscfg/sureadmin-attributes.c new file +1014 -0

1,014 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.34.1
#16 lore raw
In reply to Jorge Lopez

Hi Jorge,

Quoted 9 lines · Jorge Lopez

Version 5 restructures the patches submitted in previous versions. Earlier hp-bioscfg patches were squashed together before creating the new split.

Version 5.0 breaks down the changes into 5 patches

The driver files were broken down in 5 patches of 3 files each with exception of patch 1/5

Quoted 6 lines

Jorge Lopez (5):
Introduction of HP-BIOSCFG driver (1)
Introduction of HP-BIOSCFG driver (2)
Introduction of HP-BIOSCFG driver (3)
Introduction of HP-BIOSCFG driver (4)
Introduction of HP-BIOSCFG driver (5)

Thank you for the new version. Unfortunately I don't have time atm to review this.

And the next 2 weeks are the merge window,
followed by 2 weeks of christmas vacation.

So I'm afraid that I likely won't get around to reviewing this until the week of January 9th.

Regards,

Hans

Quoted 33 lines
 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |    6 +
 drivers/platform/x86/hp/Kconfig               |   16 +
 drivers/platform/x86/hp/Makefile              |    1 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  283 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1066 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  673 +++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       |  499 ++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        |  450 +++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    |  549 +++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |   51 +
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  |  631 ++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     |  419 +++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     |  425 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 ++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  149 +++
 17 files changed, 6430 insertions(+), 2 deletions(-)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/string-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/sureadmin-attributes.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c
#17 lore raw
Quoted 26 lines · Hans de Goede

Hi Jorge,

Quoted 9 lines · Jorge Lopez

Version 5 restructures the patches submitted in previous versions. Earlier hp-bioscfg patches were squashed together before creating the new split.

Version 5.0 breaks down the changes into 5 patches

The driver files were broken down in 5 patches of 3 files each with exception of patch 1/5

Quoted 6 lines

Jorge Lopez (5):
Introduction of HP-BIOSCFG driver (1)
Introduction of HP-BIOSCFG driver (2)
Introduction of HP-BIOSCFG driver (3)
Introduction of HP-BIOSCFG driver (4)
Introduction of HP-BIOSCFG driver (5)

Thank you for the new version. Unfortunately I don't have time atm to review this.

And the next 2 weeks are the merge window,
followed by 2 weeks of christmas vacation.

Quoted 7 lines

So I'm afraid that I likely won't get around to reviewing this until the week of January 9th.

Regards,

Hans

Completely understandable. Wishing you and your loved ones a happy and healthy Merry Christmas. May the new year bring you lots of health, happiness, and prosperity.

Regards,

Jorge