Skip to contentSkip to conversation

Introduction of HP-BIOSCFG driver

PATCH Superseded Jorge Lopez 2 participants 24 messages Oct 20, 2022 – Nov 14, 2022

Subsystems (6)

v4 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v4 cover Introduction of HP-BIOSCFG driver

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

Version 4.0 breaks down the changes as follows:

1. Moving existing HP drivers to a central location

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

2. Introduction of HP-BIOSCFG driver - Set 1
3. HP BIOSCFG driver - set 2
4. HP BIOSCFG driver - set 3
5. HP BIOSCFG driver - set 4
6. HP BIOSCFG driver - remaining components

--

Jorge Lopez (6):
Moving existing HP drivers to a central location Introduction of HP-BIOSCFG driver
HP BIOSCFG driver - set 2
HP BIOSCFG driver - set 3
HP BIOSCFG driver - set 4
HP BIOSCFG driver - remaining components

 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |   15 +-
 drivers/platform/x86/Kconfig                  |   80 +-
 drivers/platform/x86/Makefile                 |    4 +-
 drivers/platform/x86/hp/Kconfig               |   81 ++
 drivers/platform/x86/hp/Makefile              |   11 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  285 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1064 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  671 +++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       |  521 ++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        |  478 ++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    |  586 +++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |   50 +
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  |  647 ++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     |  408 +++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     |  457 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 ++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  145 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c        |    0
 drivers/platform/x86/{ => hp}/hp_accel.c      |    0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c    |    0
 22 files changed, 6647 insertions(+), 70 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 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
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)

--
2.34.1

#1 lore raw

PATCH v4 1/6 Moving existing HP drivers to a central location

The purpose of this patch is to provide a central location where all HP related drivers are found. HP drivers will recide under drivers/platform/x86/hp directory.

Introduce changes to Kconfig file to list all HP driver under "HP X86 Platform Specific Device Drivers" menu option. Additional changes include update MAINTAINERS file to indicate hp related drivers new path.

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

---
 MAINTAINERS                                |  4 +-
 drivers/platform/x86/Kconfig               | 80 ++++++----------------
 drivers/platform/x86/Makefile              |  4 +-
 drivers/platform/x86/hp/Kconfig            | 65 ++++++++++++++++++
 drivers/platform/x86/hp/Makefile           | 10 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c     |  0
 drivers/platform/x86/{ => hp}/hp_accel.c   |  0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c |  0
 8 files changed, 98 insertions(+), 65 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)
MAINTAINERS +2 -2
index 5a918c703b63..48f6705c19f8 100644
@@ -9289,7 +9289,7 @@ F:	drivers/net/wireless/intersil/hostap/
 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
 L:	[email protected]
 S:	Orphan
-F:	drivers/platform/x86/tc1100-wmi.c
+F:	drivers/platform/x86/hp/tc1100-wmi.c
 
 HPET:	High Precision Event Timers driver
 M:	Clemens Ladisch <[email protected]>
@@ -11747,7 +11747,7 @@ M:	Eric Piel <[email protected]>
 S:	Maintained
 F:	Documentation/misc-devices/lis3lv02d.rst
 F:	drivers/misc/lis3lv02d/
-F:	drivers/platform/x86/hp_accel.c
+F:	drivers/platform/x86/hp/hp_accel.c
 
 LIST KUNIT TEST
 M:	David Gow <[email protected]>
drivers/platform/x86/Kconfig +20 -60

119 lines not on this page · raw message

drivers/platform/x86/Makefile +1 -3
index 5a428caa654a..415dc5576396 100644
@@ -55,9 +55,7 @@ obj-$(CONFIG_FUJITSU_TABLET)	+= fujitsu-tablet.o
 obj-$(CONFIG_GPD_POCKET_FAN)	+= gpd-pocket-fan.o
 
 # Hewlett Packard
-obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
-obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
-obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
+obj-y				+= hp/
 
 # Hewlett Packard Enterprise
 obj-$(CONFIG_UV_SYSFS)       += uv_sysfs.o
drivers/platform/x86/hp/Kconfig new file +65 -0

65 lines not on this page · raw message

drivers/platform/x86/hp/Makefile new file +10 -0
new file mode 100644
index 000000000000..f651a405e876
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/x86/hp
+# x86 Platform-Specific Drivers
+#
+
+# Hewlett Packard
+obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
+obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
+obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
drivers/platform/x86/hp/hp-wmi.c renamed from drivers/platform/x86/hp-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp-wmi.c
rename to drivers/platform/x86/hp/hp-wmi.c
drivers/platform/x86/hp/hp_accel.c renamed from drivers/platform/x86/hp_accel.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp_accel.c
rename to drivers/platform/x86/hp/hp_accel.c
drivers/platform/x86/hp/tc1100-wmi.c renamed from drivers/platform/x86/tc1100-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/tc1100-wmi.c
rename to drivers/platform/x86/hp/tc1100-wmi.c
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 1/6] Moving existing HP drivers to a central location

Hi Jorge,

Sorry for the long silence, I have not done any pdx86 patch review the last 2 weeks due to personal circumstances.

Quoted 10 lines · Jorge Lopez

The purpose of this patch is to provide a central location where all HP related drivers are found. HP drivers will recide under drivers/platform/x86/hp directory.

Introduce changes to Kconfig file to list all HP driver under "HP X86 Platform Specific Device Drivers" menu option. Additional changes include update MAINTAINERS file to indicate hp related drivers new path.

Thank you for this patch. I've applied this to my review-hans branch now, since it is good to get the move done to avoid conflicts if any changes get submitted to the moved drivers later.

I will try to review the rest of this series later this week (likely coming Wednesday).

Note I've done a bunch of cleanups while applying this, see inline comments.

Quoted 46 lines

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

---
 MAINTAINERS                                |  4 +-
 drivers/platform/x86/Kconfig               | 80 ++++++----------------
 drivers/platform/x86/Makefile              |  4 +-
 drivers/platform/x86/hp/Kconfig            | 65 ++++++++++++++++++
 drivers/platform/x86/hp/Makefile           | 10 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c     |  0
 drivers/platform/x86/{ => hp}/hp_accel.c   |  0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c |  0
 8 files changed, 98 insertions(+), 65 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)
MAINTAINERS +2 -2
index 5a918c703b63..48f6705c19f8 100644
@@ -9289,7 +9289,7 @@ F:	drivers/net/wireless/intersil/hostap/
 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
 L:	[email protected]
 S:	Orphan
-F:	drivers/platform/x86/tc1100-wmi.c
+F:	drivers/platform/x86/hp/tc1100-wmi.c
 
 HPET:	High Precision Event Timers driver
 M:	Clemens Ladisch <[email protected]>
@@ -11747,7 +11747,7 @@ M:	Eric Piel <[email protected]>
 S:	Maintained
 F:	Documentation/misc-devices/lis3lv02d.rst
 F:	drivers/misc/lis3lv02d/
-F:	drivers/platform/x86/hp_accel.c
+F:	drivers/platform/x86/hp/hp_accel.c
 
 LIST KUNIT TEST
 M:	David Gow <[email protected]>
drivers/platform/x86/Kconfig +0 -0
index f5312f51de19..731cf9945df5 100644

drivers/platform/x86/Kconfig config MXM_WMI · line 87

Quoted 8 lines
drivers/platform/x86/Kconfig +1 -1
@@ -81,7 +81,7 @@ config MXM_WMI
        tristate "WMI support for MXM Laptop Graphics"
        depends on ACPI_WMI
 	help
-          MXM is a standard for laptop graphics cards, the WMI interface
+	  MXM is a standard for laptop graphics cards, the WMI interface
 	  is required for switchable nvidia graphics machines
 
 config PEAQ_WMI

This...

Quoted 18 lines
drivers/platform/x86/Kconfig +5 -7
@@ -163,18 +163,18 @@ config ACERHDF
 	  here.
 
 config ACER_WIRELESS
-        tristate "Acer Wireless Radio Control Driver"
-        depends on ACPI
-        depends on INPUT
+	tristate "Acer Wireless Radio Control Driver"
+	depends on ACPI
+	depends on INPUT
 	help
-          The Acer Wireless Radio Control handles the airplane mode hotkey
-          present on new Acer laptops.
+	  The Acer Wireless Radio Control handles the airplane mode hotkey
+	  present on new Acer laptops.
 
-          Say Y or M here if you have an Acer notebook with an airplane mode
-          hotkey.

drivers/platform/x86/Kconfig config ACERHDF · line 180

Quoted 10 lines
drivers/platform/x86/Kconfig +4 -2
+	  Say Y or M here if you have an Acer notebook with an airplane mode
+	  hotkey.
 
-          If you choose to compile this driver as a module the module will be
-          called acer-wireless.
+	  If you choose to compile this driver as a module the module will be
+	  called acer-wireless.
 
 config ACER_WMI
 	tristate "Acer WMI Laptop Extras"

And this ...

Quoted 16 lines
drivers/platform/x86/Kconfig +4 -6
@@ -400,17 +400,17 @@ config FUJITSU_TABLET
        depends on ACPI
        depends on INPUT
 	help
-         This is a driver for tablets built by Fujitsu:
+	 This is a driver for tablets built by Fujitsu:
 
-           * Lifebook P1510/P1610/P1620/Txxxx
-           * Stylistic ST5xxx
-           * Possibly other Fujitsu tablet models
+	   * Lifebook P1510/P1610/P1620/Txxxx
+	   * Stylistic ST5xxx
+	   * Possibly other Fujitsu tablet models
 
-         It adds support for the panel buttons, docking station detection,
-         tablet/notebook mode detection for convertible and

drivers/platform/x86/Kconfig config FUJITSU_TABLET · line 416

Quoted 10 lines
drivers/platform/x86/Kconfig +4 -2
-         orientation detection for docked slates.
+	 It adds support for the panel buttons, docking station detection,
+	 tablet/notebook mode detection for convertible and
+	 orientation detection for docked slates.
 
-         If you have a Fujitsu convertible or slate, say Y or M here.
+	 If you have a Fujitsu convertible or slate, say Y or M here.
 
 config GPD_POCKET_FAN
 	tristate "GPD Pocket Fan Controller support"

And this, are all unrelated whitespace changes which I have dropped.

Quoted 58 lines
drivers/platform/x86/Kconfig +1 -42
@@ -424,24 +424,7 @@ config GPD_POCKET_FAN
 	  of the CPU temperature. Say Y or M if the kernel may be used on a
 	  GPD pocket.
 
-config HP_ACCEL
-	tristate "HP laptop accelerometer"
-	depends on INPUT && ACPI
-	depends on SERIO_I8042
-	select SENSORS_LIS3LV02D
-	select NEW_LEDS
-	select LEDS_CLASS
-	help
-	  This driver provides support for the "Mobile Data Protection System 3D"
-	  or "3D DriveGuard" feature of HP laptops. On such systems the driver
-	  should load automatically (via ACPI alias).
-
-	  Support for a led indicating disk protection will be provided as
-	  hp::hddprotect. For more information on the feature, refer to
-	  Documentation/misc-devices/lis3lv02d.rst.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called hp_accel.
+source "drivers/platform/x86/hp/Kconfig"
 
 config WIRELESS_HOTKEY
 	tristate "Wireless hotkey button"
@@ -455,30 +438,6 @@ config WIRELESS_HOTKEY
 	 To compile this driver as a module, choose M here: the module will
 	 be called wireless-hotkey.
 
-config HP_WMI
-	tristate "HP WMI extras"
-	depends on ACPI_WMI
-	depends on INPUT
-	depends on RFKILL || RFKILL = n
-	select INPUT_SPARSEKMAP
-	select ACPI_PLATFORM_PROFILE
-	select HWMON
-	help
-	 Say Y here if you want to support WMI-based hotkeys on HP laptops and
-	 to read data from WMI such as docking or ambient light sensor state.
-
-	 To compile this driver as a module, choose M here: the module will
-	 be called hp-wmi.
-
-config TC1100_WMI
-	tristate "HP Compaq TC1100 Tablet WMI Extras"
-	depends on !X86_64
-	depends on ACPI
-	depends on ACPI_WMI
-	help
-	  This is a driver for the WMI extensions (wireless and bluetooth power
-	  control) of the HP Compaq TC1100 tablet.
-
 config IBM_RTL
 	tristate "Device driver to enable PRTL support"
 	depends on PCI

drivers/platform/x86/Kconfig config P2SB · line 1115

Quoted 4 lines
drivers/platform/x86/Kconfig +1 -0
@@ -1153,3 +1112,4 @@ config P2SB
 	  The main purpose of this library is to unhide P2SB device in case
 	  firmware kept it hidden on some platforms in order to access devices
 	  behind it.
+

Another unrelated whitespace change, also dropped.

drivers/platform/x86/Makefile obj-$(CONFIG_FUJITSU_TABLET) += fujitsu-tablet.o · line 58

Quoted 12 lines
drivers/platform/x86/Makefile +1 -3
index 5a428caa654a..415dc5576396 100644
@@ -55,9 +55,7 @@ obj-$(CONFIG_FUJITSU_TABLET)	+= fujitsu-tablet.o
 obj-$(CONFIG_GPD_POCKET_FAN)	+= gpd-pocket-fan.o
 
 # Hewlett Packard
-obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
-obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
-obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
+obj-y				+= hp/

This should be:

obj-$(CONFIG_X86_PLATFORM_DRIVERS_HP) += hp/

Fixed while applying

Quoted 9 lines
drivers/platform/x86/Makefile +0 -0
 # Hewlett Packard Enterprise
 obj-$(CONFIG_UV_SYSFS)       += uv_sysfs.o
drivers/platform/x86/hp/Kconfig new file +0 -0
new file mode 100644
index 000000000000..426e3575ddc3

drivers/platform/x86/hp/Kconfig line 7

Quoted 7 lines
drivers/platform/x86/hp/Kconfig new file +7 -0
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# X86 Platform Specific Drivers
+#
+menuconfig X86_PLATFORM_DRIVERS_HP
+	bool "HP X86 Platform Specific Device Drivers"
+	default y

This default y should not be here, drivers should normally not be enabled by default and since you have added default m to the other entries below (which is good), we need this one to not have a default so we don't end up unconditionally enabling the drivers.

I've dropped the "default y" while applying this.

drivers/platform/x86/hp/tc1100-wmi.c

Quoted 86 lines
drivers/platform/x86/hp/Kconfig new file +58 -0
+	depends on X86_PLATFORM_DEVICES
+	help
+	  Say Y here to get to see options for device drivers for various
+	  HP x86 platforms, including vendor-specific laptop extension drivers.
+	  This option alone does not add any kernel code.
+
+	  If you say N, all options in this submenu will be skipped and disabled.
+
+if X86_PLATFORM_DRIVERS_HP
+
+config HP_ACCEL
+	tristate "HP laptop accelerometer"
+	default m
+	depends on INPUT && ACPI
+	depends on SERIO_I8042
+	select SENSORS_LIS3LV02D
+	select NEW_LEDS
+	select LEDS_CLASS
+	help
+	  This driver provides support for the "Mobile Data Protection System 3D"
+	  or "3D DriveGuard" feature of HP laptops. On such systems the driver
+	  should load automatically (via ACPI alias).
+
+	  Support for a led indicating disk protection will be provided as
+	  hp::hddprotect. For more information on the feature, refer to
+	  Documentation/misc-devices/lis3lv02d.rst.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called hp_accel.
+
+config HP_WMI
+	tristate "HP WMI extras"
+	default m
+	depends on ACPI_WMI
+	depends on INPUT
+	depends on RFKILL || RFKILL = n
+	select INPUT_SPARSEKMAP
+	select ACPI_PLATFORM_PROFILE
+	select HWMON
+	help
+	 Say Y here if you want to support WMI-based hotkeys on HP laptops and
+	 to read data from WMI such as docking or ambient light sensor state.
+
+	 To compile this driver as a module, choose M here: the module will
+	 be called hp-wmi.
+
+config TC1100_WMI
+	tristate "HP Compaq TC1100 Tablet WMI Extras"
+	default m
+	depends on !X86_64
+	depends on ACPI
+	depends on ACPI_WMI
+	help
+	  This is a driver for the WMI extensions (wireless and bluetooth power
+	  control) of the HP Compaq TC1100 tablet.
+
+
+ endif # X86_PLATFORM_DRIVERS_HP
drivers/platform/x86/hp/Makefile new file +10 -0
new file mode 100644
index 000000000000..f651a405e876
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/x86/hp
+# x86 Platform-Specific Drivers
+#
+
+# Hewlett Packard
+obj-$(CONFIG_HP_ACCEL)		+= hp_accel.o
+obj-$(CONFIG_HP_WMI)		+= hp-wmi.o
+obj-$(CONFIG_TC1100_WMI)	+= tc1100-wmi.o
drivers/platform/x86/hp/hp-wmi.c renamed from drivers/platform/x86/hp-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp-wmi.c
rename to drivers/platform/x86/hp/hp-wmi.c
drivers/platform/x86/hp/hp_accel.c renamed from drivers/platform/x86/hp_accel.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp_accel.c
rename to drivers/platform/x86/hp/hp_accel.c
drivers/platform/x86/hp/tc1100-wmi.c renamed from drivers/platform/x86/tc1100-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/tc1100-wmi.c
rename to drivers/platform/x86/hp/tc1100-wmi.c

Regards,

Hans

#3 lore raw

Re: [PATCH v4 1/6] Moving existing HP drivers to a central location

Hi Hans,

Thank you. No worries. Family and health comes first. The review
can wait a few more days.

Jorge

Quoted 346 lines · Hans de Goede

Hi Jorge,

Sorry for the long silence, I have not done any pdx86 patch review the last 2 weeks due to personal circumstances.

Quoted 10 lines · Jorge Lopez

The purpose of this patch is to provide a central location where all HP related drivers are found. HP drivers will recide under drivers/platform/x86/hp directory.

Introduce changes to Kconfig file to list all HP driver under "HP X86 Platform Specific Device Drivers" menu option. Additional changes include update MAINTAINERS file to indicate hp related drivers new path.

Thank you for this patch. I've applied this to my review-hans branch now, since it is good to get the move done to avoid conflicts if any changes get submitted to the moved drivers later.

I will try to review the rest of this series later this week (likely coming Wednesday).

Note I've done a bunch of cleanups while applying this, see inline comments.

Quoted 46 lines

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

---
 MAINTAINERS                                |  4 +-
 drivers/platform/x86/Kconfig               | 80 ++++++----------------
 drivers/platform/x86/Makefile              |  4 +-
 drivers/platform/x86/hp/Kconfig            | 65 ++++++++++++++++++
 drivers/platform/x86/hp/Makefile           | 10 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c     |  0
 drivers/platform/x86/{ => hp}/hp_accel.c   |  0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c |  0
 8 files changed, 98 insertions(+), 65 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)
MAINTAINERS +2 -2
index 5a918c703b63..48f6705c19f8 100644
@@ -9289,7 +9289,7 @@ F:      drivers/net/wireless/intersil/hostap/
 HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER
 L:   [email protected]
 S:   Orphan
-F:   drivers/platform/x86/tc1100-wmi.c
+F:   drivers/platform/x86/hp/tc1100-wmi.c
 
 HPET:        High Precision Event Timers driver
 M:   Clemens Ladisch <[email protected]>
@@ -11747,7 +11747,7 @@ M:    Eric Piel <[email protected]>
 S:   Maintained
 F:   Documentation/misc-devices/lis3lv02d.rst
 F:   drivers/misc/lis3lv02d/
-F:   drivers/platform/x86/hp_accel.c
+F:   drivers/platform/x86/hp/hp_accel.c
 
 LIST KUNIT TEST
 M:   David Gow <[email protected]>
drivers/platform/x86/Kconfig +0 -0
index f5312f51de19..731cf9945df5 100644

drivers/platform/x86/Kconfig config MXM_WMI · line 87

Quoted 8 lines
drivers/platform/x86/Kconfig +1 -1
@@ -81,7 +81,7 @@ config MXM_WMI
        tristate "WMI support for MXM Laptop Graphics"
        depends on ACPI_WMI
      help
-          MXM is a standard for laptop graphics cards, the WMI interface
+       MXM is a standard for laptop graphics cards, the WMI interface
        is required for switchable nvidia graphics machines
 
 config PEAQ_WMI

This...

Quoted 18 lines
drivers/platform/x86/Kconfig +5 -7
@@ -163,18 +163,18 @@ config ACERHDF
        here.
 
 config ACER_WIRELESS
-        tristate "Acer Wireless Radio Control Driver"
-        depends on ACPI
-        depends on INPUT
+     tristate "Acer Wireless Radio Control Driver"
+     depends on ACPI
+     depends on INPUT
      help
-          The Acer Wireless Radio Control handles the airplane mode hotkey
-          present on new Acer laptops.
+       The Acer Wireless Radio Control handles the airplane mode hotkey
+       present on new Acer laptops.
 
-          Say Y or M here if you have an Acer notebook with an airplane mode
-          hotkey.

drivers/platform/x86/Kconfig config ACERHDF · line 180

Quoted 10 lines
drivers/platform/x86/Kconfig +4 -2
+       Say Y or M here if you have an Acer notebook with an airplane mode
+       hotkey.
 
-          If you choose to compile this driver as a module the module will be
-          called acer-wireless.
+       If you choose to compile this driver as a module the module will be
+       called acer-wireless.
 
 config ACER_WMI
      tristate "Acer WMI Laptop Extras"

And this ...

Quoted 16 lines
drivers/platform/x86/Kconfig +4 -6
@@ -400,17 +400,17 @@ config FUJITSU_TABLET
        depends on ACPI
        depends on INPUT
      help
-         This is a driver for tablets built by Fujitsu:
+      This is a driver for tablets built by Fujitsu:
 
-           * Lifebook P1510/P1610/P1620/Txxxx
-           * Stylistic ST5xxx
-           * Possibly other Fujitsu tablet models
+        * Lifebook P1510/P1610/P1620/Txxxx
+        * Stylistic ST5xxx
+        * Possibly other Fujitsu tablet models
 
-         It adds support for the panel buttons, docking station detection,
-         tablet/notebook mode detection for convertible and

drivers/platform/x86/Kconfig config FUJITSU_TABLET · line 416

Quoted 10 lines
drivers/platform/x86/Kconfig +4 -2
-         orientation detection for docked slates.
+      It adds support for the panel buttons, docking station detection,
+      tablet/notebook mode detection for convertible and
+      orientation detection for docked slates.
 
-         If you have a Fujitsu convertible or slate, say Y or M here.
+      If you have a Fujitsu convertible or slate, say Y or M here.
 
 config GPD_POCKET_FAN
      tristate "GPD Pocket Fan Controller support"

And this, are all unrelated whitespace changes which I have dropped.

Quoted 58 lines
drivers/platform/x86/Kconfig +1 -42
@@ -424,24 +424,7 @@ config GPD_POCKET_FAN
        of the CPU temperature. Say Y or M if the kernel may be used on a
        GPD pocket.
 
-config HP_ACCEL
-     tristate "HP laptop accelerometer"
-     depends on INPUT && ACPI
-     depends on SERIO_I8042
-     select SENSORS_LIS3LV02D
-     select NEW_LEDS
-     select LEDS_CLASS
-     help
-       This driver provides support for the "Mobile Data Protection System 3D"
-       or "3D DriveGuard" feature of HP laptops. On such systems the driver
-       should load automatically (via ACPI alias).
-
-       Support for a led indicating disk protection will be provided as
-       hp::hddprotect. For more information on the feature, refer to
-       Documentation/misc-devices/lis3lv02d.rst.
-
-       To compile this driver as a module, choose M here: the module will
-       be called hp_accel.
+source "drivers/platform/x86/hp/Kconfig"
 
 config WIRELESS_HOTKEY
      tristate "Wireless hotkey button"
@@ -455,30 +438,6 @@ config WIRELESS_HOTKEY
       To compile this driver as a module, choose M here: the module will
       be called wireless-hotkey.
 
-config HP_WMI
-     tristate "HP WMI extras"
-     depends on ACPI_WMI
-     depends on INPUT
-     depends on RFKILL || RFKILL = n
-     select INPUT_SPARSEKMAP
-     select ACPI_PLATFORM_PROFILE
-     select HWMON
-     help
-      Say Y here if you want to support WMI-based hotkeys on HP laptops and
-      to read data from WMI such as docking or ambient light sensor state.
-
-      To compile this driver as a module, choose M here: the module will
-      be called hp-wmi.
-
-config TC1100_WMI
-     tristate "HP Compaq TC1100 Tablet WMI Extras"
-     depends on !X86_64
-     depends on ACPI
-     depends on ACPI_WMI
-     help
-       This is a driver for the WMI extensions (wireless and bluetooth power
-       control) of the HP Compaq TC1100 tablet.
-
 config IBM_RTL
      tristate "Device driver to enable PRTL support"
      depends on PCI

drivers/platform/x86/Kconfig config P2SB · line 1115

Quoted 4 lines
drivers/platform/x86/Kconfig +1 -0
@@ -1153,3 +1112,4 @@ config P2SB
        The main purpose of this library is to unhide P2SB device in case
        firmware kept it hidden on some platforms in order to access devices
        behind it.
+

Another unrelated whitespace change, also dropped.

drivers/platform/x86/Makefile obj-$(CONFIG_FUJITSU_TABLET) += fujitsu-tablet.o · line 58

Quoted 12 lines
drivers/platform/x86/Makefile +1 -3
index 5a428caa654a..415dc5576396 100644
@@ -55,9 +55,7 @@ obj-$(CONFIG_FUJITSU_TABLET)        += fujitsu-tablet.o
 obj-$(CONFIG_GPD_POCKET_FAN) += gpd-pocket-fan.o
 
 # Hewlett Packard
-obj-$(CONFIG_HP_ACCEL)               += hp_accel.o
-obj-$(CONFIG_HP_WMI)         += hp-wmi.o
-obj-$(CONFIG_TC1100_WMI)     += tc1100-wmi.o
+obj-y                                += hp/

This should be:

obj-$(CONFIG_X86_PLATFORM_DRIVERS_HP) += hp/

Fixed while applying

Quoted 9 lines
drivers/platform/x86/Makefile +0 -0
 # Hewlett Packard Enterprise
 obj-$(CONFIG_UV_SYSFS)       += uv_sysfs.o
drivers/platform/x86/hp/Kconfig new file +0 -0
new file mode 100644
index 000000000000..426e3575ddc3

drivers/platform/x86/hp/Kconfig line 7

Quoted 7 lines
drivers/platform/x86/hp/Kconfig new file +7 -0
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# X86 Platform Specific Drivers
+#
+menuconfig X86_PLATFORM_DRIVERS_HP
+     bool "HP X86 Platform Specific Device Drivers"
+     default y

This default y should not be here, drivers should normally not be enabled by default and since you have added default m to the other entries below (which is good), we need this one to not have a default so we don't end up unconditionally enabling the drivers.

I've dropped the "default y" while applying this.

drivers/platform/x86/hp/tc1100-wmi.c

Quoted 86 lines
drivers/platform/x86/hp/Kconfig new file +58 -0
+     depends on X86_PLATFORM_DEVICES
+     help
+       Say Y here to get to see options for device drivers for various
+       HP x86 platforms, including vendor-specific laptop extension drivers.
+       This option alone does not add any kernel code.
+
+       If you say N, all options in this submenu will be skipped and disabled.
+
+if X86_PLATFORM_DRIVERS_HP
+
+config HP_ACCEL
+     tristate "HP laptop accelerometer"
+     default m
+     depends on INPUT && ACPI
+     depends on SERIO_I8042
+     select SENSORS_LIS3LV02D
+     select NEW_LEDS
+     select LEDS_CLASS
+     help
+       This driver provides support for the "Mobile Data Protection System 3D"
+       or "3D DriveGuard" feature of HP laptops. On such systems the driver
+       should load automatically (via ACPI alias).
+
+       Support for a led indicating disk protection will be provided as
+       hp::hddprotect. For more information on the feature, refer to
+       Documentation/misc-devices/lis3lv02d.rst.
+
+       To compile this driver as a module, choose M here: the module will
+       be called hp_accel.
+
+config HP_WMI
+     tristate "HP WMI extras"
+     default m
+     depends on ACPI_WMI
+     depends on INPUT
+     depends on RFKILL || RFKILL = n
+     select INPUT_SPARSEKMAP
+     select ACPI_PLATFORM_PROFILE
+     select HWMON
+     help
+      Say Y here if you want to support WMI-based hotkeys on HP laptops and
+      to read data from WMI such as docking or ambient light sensor state.
+
+      To compile this driver as a module, choose M here: the module will
+      be called hp-wmi.
+
+config TC1100_WMI
+     tristate "HP Compaq TC1100 Tablet WMI Extras"
+     default m
+     depends on !X86_64
+     depends on ACPI
+     depends on ACPI_WMI
+     help
+       This is a driver for the WMI extensions (wireless and bluetooth power
+       control) of the HP Compaq TC1100 tablet.
+
+
+ endif # X86_PLATFORM_DRIVERS_HP
drivers/platform/x86/hp/Makefile new file +10 -0
new file mode 100644
index 000000000000..f651a405e876
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/x86/hp
+# x86 Platform-Specific Drivers
+#
+
+# Hewlett Packard
+obj-$(CONFIG_HP_ACCEL)               += hp_accel.o
+obj-$(CONFIG_HP_WMI)         += hp-wmi.o
+obj-$(CONFIG_TC1100_WMI)     += tc1100-wmi.o
drivers/platform/x86/hp/hp-wmi.c renamed from drivers/platform/x86/hp-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp-wmi.c
rename to drivers/platform/x86/hp/hp-wmi.c
drivers/platform/x86/hp/hp_accel.c renamed from drivers/platform/x86/hp_accel.c +0 -0
similarity index 100%
rename from drivers/platform/x86/hp_accel.c
rename to drivers/platform/x86/hp/hp_accel.c
drivers/platform/x86/hp/tc1100-wmi.c renamed from drivers/platform/x86/tc1100-wmi.c +0 -0
similarity index 100%
rename from drivers/platform/x86/tc1100-wmi.c
rename to drivers/platform/x86/hp/tc1100-wmi.c

Regards,

Hans

#4 lore raw

PATCH v4 2/6 Introduction of HP-BIOSCFG driver

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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +285 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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)
+		strncpy(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;
+	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(void *input_buffer, int 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;
+
+	kfree(obj);
+	return ret;
+}
+
+/*
+ * set_bios_defaults() - Resets BIOS defaults
+ *
+ * @deftype: the type of BIOS value reset to issue.
+ *
+ * Resets BIOS defaults
+ */
+int set_bios_defaults(u8 deftype)
+{
+	return -EOPNOTSUPP;
+}
+
+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.h new file +671 -0

671 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +521 -0

521 lines not on this page · raw message

Signature · 1 line
2.34.1
#5 lore raw

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+		strncpy(bioscfg_drv.password_data[instance].current_password,
+			auth_empty_value,
+			sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+	ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+	bios_return = (struct bios_return *)obj->buffer.pointer;
+	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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

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

Quoted 7 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +7 -0
+	}
+	*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;

You have an error here, but you don't return an error at the end of this function.

Please for version 5 do the following:

1. Add a preparation patch which moves populate_string_buffer() and calculate_string_buffer() from drivers/platform/x86/dell/dell-wmi-sysman/sysman.c to drivers/platform/x86/wmi.c

Renaming them to:

size_t wmi_utf16_str_size(const char *str);
ssize_t wmi_str_to_utf16_str(u16 *buffer, size_t buffer_len, const char *str);

(adding these prototypes to include/linux/wmi.h)

and make the dell-wmi-sysman code use these new helpers

2. Also use these new helpers in your own code instead of your own ascii_to_utf16_unicode() function

Quoted 45 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +45 -0
+	}
+
+	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(void *input_buffer, int 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;
+
+	kfree(obj);
+	return ret;
+}
+
+/*

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+ * set_bios_defaults() - Resets BIOS defaults
+ *
+ * @deftype: the type of BIOS value reset to issue.
+ *
+ * Resets BIOS defaults
+ */
+int set_bios_defaults(u8 deftype)
+{
+	return -EOPNOTSUPP;
+}

This function is not used anywhere, please drop it.

Quoted 460 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +40 -0
+
+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.h new file +414 -0
new file mode 100644
index 000000000000..4409481f84f2
@@ -0,0 +1,671 @@
+/* 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;
+	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()
+
+
+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].attribute_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].attribute_name, attr_name) == 0)						\
+			return i;						\
+	}									\

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+	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 sprintf(buf, "%s\n", bioscfg_drv.type##_data[i].name);	\

Please use sysfs_emit instead of sprintf for this and all the other _show() functions.

Quoted 40 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +40 -0
+	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 sprintf(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 sprintf(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 sprintf(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 474

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);					\
+										\
+	clear_all_passwords();							\

Why ?

At a minimum add a comment explaining this.

Quoted 167 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +167 -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 sprintf(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 sprintf(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(union acpi_object *str_obj,
+			 int instance_id,
+			 struct kobject *attr_name_kobj);
+int populate_string_elements_from_buffer(union acpi_object *string_obj,
+					 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(union acpi_object *integer_obj,
+			  int instance_id,
+			  struct kobject *attr_name_kobj);
+int populate_integer_elements_from_buffer(union acpi_object *integer_obj,
+					  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(union acpi_object *enum_obj,
+			      int instance_id,
+			      struct kobject *attr_name_kobj);
+int populate_enumeration_elements_from_buffer(union acpi_object *enum_obj,
+					      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(union acpi_object *order_obj, int instance_id,
+				      struct kobject *attr_name_kobj);
+int populate_ordered_list_elements_from_buffer(union acpi_object *order_obj,
+					       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(union acpi_object *password_obj,
+			   int instance_id,
+			   struct kobject *attr_name_kobj);
+int populate_password_elements_from_buffer(union acpi_object *password_obj,
+					   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(void *input_buffer, int 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 669

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 *integer);
+int get_string_from_buffer(u16 **buffer, 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, since this is just a function prototype it cannot be inlined.

And please also drop the inline from the actual implementation, since that is only used in other .c files.

Quoted 23 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +2 -0
+
+#endif
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +15 -0
new file mode 100644
index 000000000000..e67e7c397c12
@@ -0,0 +1,521 @@
+// 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);

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	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_ENUMERATION_GUID);
+	if (!obj)
+		return -EIO;

Why get this obj if you are not using it at all ? The attribute_property_store() macro updates bioscfg_drv.enumeration_data[instance_id].current_value on success, so I believe this function can just

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

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +3 -0
+
+	ret = snprintf(buf, PAGE_SIZE, "%s\n",
+		       bioscfg_drv.enumeration_data[instance_id].current_value);

please use sysfs_emit for this

Quoted 23 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +23 -0
+
+	kfree(obj);
+	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;
+
+	options = kstrdup(bioscfg_drv.enumeration_data[instance_id].possible_values,
+			  GFP_KERNEL);
+

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	if (!options) {
+		ret = -ENOMEM;
+		goto exit_validate_enum_input;
+	}
+
+	/* Is it a read only attribute */
+	if (bioscfg_drv.enumeration_data[instance_id].is_readonly) {
+		ret = -EIO;
+		goto exit_validate_enum_input;
+	}

Please move this check to before the kstrdup and just directly return -EIO; instead of doing the goto.

Quoted 9 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +9 -0
+
+	while ((p = strsep(&options, ";")) != NULL) {
+		if (!*p)
+			continue;
+
+		if (!strcasecmp(p, buf)) {
+			found = 1;
+			break;
+		}

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	}
+
+	if (!found) {
+		ret = -EINVAL;
+		goto exit_validate_enum_input;
+	}
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].new_value,
+		buf,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].new_value));

Why store a copy of buf in new_value? This function is only called from the attribute_property_store() with attr_value as buf parameter.

You can just also pass attr_value to update_##type##_value() and then have update_enumeration_value() directly store attr_value in current_value.

Doing things this way allows removing new_value from struct enumeration_data all together resulting in a nice reduction in memory usage.

Quoted 89 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +89 -0
+	/*
+	 * 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)
+{
+	strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+		bioscfg_drv.enumeration_data[instance_id].new_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, 0600);
+
+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 sprintf(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)
+{
+	char *str_value = NULL;
+	int str_len;
+	int ret = 0;
+
+	bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+	bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	ret = convert_hexstr_to_str(&(enum_obj[NAME].string.pointer),
+				    enum_obj[NAME].string.length,
+				    &str_value, &str_len);
+	if (ACPI_FAILURE(ret)) {
+		pr_warn("Failed to populate enumeration package data. Error [0%0x]\n", ret);
+		kfree(str_value);
+		return ret;
+	}

You have already done this convert_hexstr_to_str call in hp_init_bios_attributes() and used it for the name of the passed in struct kobject *attr_name_kobj, so you can just use attr_name_kobj->name here, as you already do in the friendly_user_name_update() call below?

Also you use kobj->name in the get_##type##_instance_id() macro, and the only reason why the enumeration_data[instance_id].attribute_name field is necessary is for that function.

So dropping the above call and using kobj->name to intialize attribute_name and display_name seems to make sense here ?

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

Quoted 11 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +11 -0
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].attribute_name,
+		str_value,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].attribute_name));
+
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name,
+		str_value,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+	kfree(str_value);
+	str_value = NULL;

And then you can also drop this. Note there is no need to set str_value to NULL here regardless since it is a local variable which will disappear when the function ends.

Quoted 155 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +155 -0
+
+	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);
+	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;
+}
+

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+/*
+ * populate_enumeration_buffer_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
+ * @enumeration_property_count: Total properties count under enumeration type
+ */
+int populate_enumeration_buffer_data(union acpi_object *enum_obj, int instance_id,

Please replace:

union acpi_object *enum_obj

with:

u16 *buffer_ptr, size_t buffer_size,

for better readability, but also because actually walking obj->buffer.pointer feels wrong. What if some other code later wants to also check the buffer, but now obj->buffer.pointer is all of a sudden pointing to the end ?

Also you should pass in the (remaining) size and also pass this into get_string_from_buffer() and into get_integer_from_buffer() and have them check that they do not run pass the end of the buffer.

Also please adjust hp_init_bios_attributes() for it to have local:

u16 *buffer_ptr;
size_t buffer_size;

variables and for it to pass them into it's get_string_from_buffer() call before it passes them to populate_enumeration_buffer_data()

These changes have 2 goals:

1. don't modify the contents of the acpi_object. In general for things like walking pointers you should use a local variable not change the members of a passed-by-reference struct, to avoid surprising the caller

2. add bounds check everywhere to ensure that you don't run past the end of the buffer while parsing it.

Quoted 156 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +156 -0
+			      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;
+	strscpy(bioscfg_drv.enumeration_data[instance_id].attribute_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].attribute_name));
+	strscpy(bioscfg_drv.enumeration_data[instance_id].display_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+	/* Populate enumeration elements */
+	populate_enumeration_elements_from_buffer(enum_obj, instance_id, HPWMI_ENUMERATION_TYPE);
+	update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+				    &enumeration_current_val);
+	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(union acpi_object *enum_obj,
+					      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 **)&enum_obj->buffer.pointer, &str);
+		if (ACPI_FAILURE(status))
+			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 **)&enum_obj->buffer.pointer, (int *)&integer);
+
+		if (ACPI_FAILURE(status))
+			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 **)&enum_obj->buffer.pointer, &str);
+				if (ACPI_FAILURE(status))
+					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 **)&enum_obj->buffer.pointer, &str);
+			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 **)&enum_obj->buffer.pointer, &str);
+				if (ACPI_FAILURE(status))
+					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);
+	str = NULL;
+
+	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 521

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;
+}

Regards,

Hans

#6 lore raw

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Quoted 12 lines

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

Quoted 8 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +7 -0
+     }
+     *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;

You have an error here, but you don't return an error at the end of this function.

Quoted 7 lines

Please for version 5 do the following:

1. Add a preparation patch which moves populate_string_buffer() and calculate_string_buffer() from drivers/platform/x86/dell/dell-wmi-sysman/sysman.c to drivers/platform/x86/wmi.c

Are you asking to change sysman.c which is a DELL specific driver? I don't have a DELL platform to validate the changes and I will be
doing the work on HP workday. Sorry but I cannot do that.

Quoted 7 lines

Renaming them to:

size_t wmi_utf16_str_size(const char *str);
ssize_t wmi_str_to_utf16_str(u16 *buffer, size_t buffer_len, const char *str);

(adding these prototypes to include/linux/wmi.h)

I will make the changes requested but I'll wait for your response to the previous comments regarding calculate_string_buffer()

Quoted 1,412 lines

and make the dell-wmi-sysman code use these new helpers

2. Also use these new helpers in your own code instead of your own ascii_to_utf16_unicode() function

Quoted 45 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +45 -0
+     }
+
+     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(void *input_buffer, int 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;
+
+     kfree(obj);
+     return ret;
+}
+
+/*

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +10 -0
+ * set_bios_defaults() - Resets BIOS defaults
+ *
+ * @deftype: the type of BIOS value reset to issue.
+ *
+ * Resets BIOS defaults
+ */
+int set_bios_defaults(u8 deftype)
+{
+     return -EOPNOTSUPP;
+}

This function is not used anywhere, please drop it.

Quoted 460 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +40 -0
+
+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.h new file +414 -0
new file mode 100644
index 000000000000..4409481f84f2
@@ -0,0 +1,671 @@
+/* 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;
+     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()
+
+
+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].attribute_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].attribute_name, attr_name) == 0)                                          \
+                     return i;                                               \
+     }                                                                       \

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +10 -0
+     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 sprintf(buf, "%s\n", bioscfg_drv.type##_data[i].name);   \

Please use sysfs_emit instead of sprintf for this and all the other _show() functions.

Quoted 40 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +40 -0
+     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 sprintf(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 sprintf(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 sprintf(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 474

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);                                       \
+                                                                             \
+     clear_all_passwords();                                                  \

Why ?

At a minimum add a comment explaining this.

Quoted 167 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +167 -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 sprintf(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 sprintf(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(union acpi_object *str_obj,
+                      int instance_id,
+                      struct kobject *attr_name_kobj);
+int populate_string_elements_from_buffer(union acpi_object *string_obj,
+                                      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(union acpi_object *integer_obj,
+                       int instance_id,
+                       struct kobject *attr_name_kobj);
+int populate_integer_elements_from_buffer(union acpi_object *integer_obj,
+                                       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(union acpi_object *enum_obj,
+                           int instance_id,
+                           struct kobject *attr_name_kobj);
+int populate_enumeration_elements_from_buffer(union acpi_object *enum_obj,
+                                           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(union acpi_object *order_obj, int instance_id,
+                                   struct kobject *attr_name_kobj);
+int populate_ordered_list_elements_from_buffer(union acpi_object *order_obj,
+                                            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(union acpi_object *password_obj,
+                        int instance_id,
+                        struct kobject *attr_name_kobj);
+int populate_password_elements_from_buffer(union acpi_object *password_obj,
+                                        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(void *input_buffer, int 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 669

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 *integer);
+int get_string_from_buffer(u16 **buffer, 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, since this is just a function prototype it cannot be inlined.

And please also drop the inline from the actual implementation, since that is only used in other .c files.

Quoted 23 lines
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h new file +2 -0
+
+#endif
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +15 -0
new file mode 100644
index 000000000000..e67e7c397c12
@@ -0,0 +1,521 @@
+// 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);

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+     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_ENUMERATION_GUID);
+     if (!obj)
+             return -EIO;

Why get this obj if you are not using it at all ? The attribute_property_store() macro updates bioscfg_drv.enumeration_data[instance_id].current_value on success, so I believe this function can just

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

Quoted 3 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +3 -0
+
+     ret = snprintf(buf, PAGE_SIZE, "%s\n",
+                    bioscfg_drv.enumeration_data[instance_id].current_value);

please use sysfs_emit for this

Quoted 23 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +23 -0
+
+     kfree(obj);
+     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;
+
+     options = kstrdup(bioscfg_drv.enumeration_data[instance_id].possible_values,
+                       GFP_KERNEL);
+

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+     if (!options) {
+             ret = -ENOMEM;
+             goto exit_validate_enum_input;
+     }
+
+     /* Is it a read only attribute */
+     if (bioscfg_drv.enumeration_data[instance_id].is_readonly) {
+             ret = -EIO;
+             goto exit_validate_enum_input;
+     }

Please move this check to before the kstrdup and just directly return -EIO; instead of doing the goto.

Quoted 9 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +9 -0
+
+     while ((p = strsep(&options, ";")) != NULL) {
+             if (!*p)
+                     continue;
+
+             if (!strcasecmp(p, buf)) {
+                     found = 1;
+                     break;
+             }

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+     }
+
+     if (!found) {
+             ret = -EINVAL;
+             goto exit_validate_enum_input;
+     }
+
+     strscpy(bioscfg_drv.enumeration_data[instance_id].new_value,
+             buf,
+             sizeof(bioscfg_drv.enumeration_data[instance_id].new_value));

Why store a copy of buf in new_value? This function is only called from the attribute_property_store() with attr_value as buf parameter.

You can just also pass attr_value to update_##type##_value() and then have update_enumeration_value() directly store attr_value in current_value.

Doing things this way allows removing new_value from struct enumeration_data all together resulting in a nice reduction in memory usage.

Quoted 89 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +89 -0
+     /*
+      * 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)
+{
+     strscpy(bioscfg_drv.enumeration_data[instance_id].current_value,
+             bioscfg_drv.enumeration_data[instance_id].new_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, 0600);
+
+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 sprintf(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)
+{
+     char *str_value = NULL;
+     int str_len;
+     int ret = 0;
+
+     bioscfg_drv.enumeration_data[instance_id].type = HPWMI_ENUMERATION_TYPE;

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+     bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+     ret = convert_hexstr_to_str(&(enum_obj[NAME].string.pointer),
+                                 enum_obj[NAME].string.length,
+                                 &str_value, &str_len);
+     if (ACPI_FAILURE(ret)) {
+             pr_warn("Failed to populate enumeration package data. Error [0%0x]\n", ret);
+             kfree(str_value);
+             return ret;
+     }

You have already done this convert_hexstr_to_str call in hp_init_bios_attributes() and used it for the name of the passed in struct kobject *attr_name_kobj, so you can just use attr_name_kobj->name here, as you already do in the friendly_user_name_update() call below?

Also you use kobj->name in the get_##type##_instance_id() macro, and the only reason why the enumeration_data[instance_id].attribute_name field is necessary is for that function.

So dropping the above call and using kobj->name to intialize attribute_name and display_name seems to make sense here ?

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

Quoted 11 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +11 -0
+
+     strscpy(bioscfg_drv.enumeration_data[instance_id].attribute_name,
+             str_value,
+             sizeof(bioscfg_drv.enumeration_data[instance_id].attribute_name));
+
+     strscpy(bioscfg_drv.enumeration_data[instance_id].display_name,
+             str_value,
+             sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+     kfree(str_value);
+     str_value = NULL;

And then you can also drop this. Note there is no need to set str_value to NULL here regardless since it is a local variable which will disappear when the function ends.

Quoted 155 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +155 -0
+
+     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);
+     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;
+}
+

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

Quoted 10 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +10 -0
+/*
+ * populate_enumeration_buffer_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
+ * @enumeration_property_count: Total properties count under enumeration type
+ */
+int populate_enumeration_buffer_data(union acpi_object *enum_obj, int instance_id,

Please replace:

union acpi_object *enum_obj

with:

u16 *buffer_ptr, size_t buffer_size,

for better readability, but also because actually walking obj->buffer.pointer feels wrong. What if some other code later wants to also check the buffer, but now obj->buffer.pointer is all of a sudden pointing to the end ?

Also you should pass in the (remaining) size and also pass this into get_string_from_buffer() and into get_integer_from_buffer() and have them check that they do not run pass the end of the buffer.

Also please adjust hp_init_bios_attributes() for it to have local:

u16 *buffer_ptr;
size_t buffer_size;

variables and for it to pass them into it's get_string_from_buffer() call before it passes them to populate_enumeration_buffer_data()

These changes have 2 goals:

1. don't modify the contents of the acpi_object. In general for things like walking pointers you should use a local variable not change the members of a passed-by-reference struct, to avoid surprising the caller

2. add bounds check everywhere to ensure that you don't run past the end of the buffer while parsing it.

Quoted 156 lines
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c new file +156 -0
+                           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;
+     strscpy(bioscfg_drv.enumeration_data[instance_id].attribute_name,
+             attr_name_kobj->name,
+             sizeof(bioscfg_drv.enumeration_data[instance_id].attribute_name));
+     strscpy(bioscfg_drv.enumeration_data[instance_id].display_name,
+             attr_name_kobj->name,
+             sizeof(bioscfg_drv.enumeration_data[instance_id].display_name));
+
+     /* Populate enumeration elements */
+     populate_enumeration_elements_from_buffer(enum_obj, instance_id, HPWMI_ENUMERATION_TYPE);
+     update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].is_readonly,
+                                 &enumeration_current_val);
+     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(union acpi_object *enum_obj,
+                                           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 **)&enum_obj->buffer.pointer, &str);
+             if (ACPI_FAILURE(status))
+                     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 **)&enum_obj->buffer.pointer, (int *)&integer);
+
+             if (ACPI_FAILURE(status))
+                     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 **)&enum_obj->buffer.pointer, &str);
+                             if (ACPI_FAILURE(status))
+                                     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 **)&enum_obj->buffer.pointer, &str);
+                     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 **)&enum_obj->buffer.pointer, &str);
+                             if (ACPI_FAILURE(status))
+                                     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);
+     str = NULL;
+
+     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 521

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;
+}

Regards,

Hans

#7 lore raw

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

Quoted 15 lines
Quoted 15 lines

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

Quoted 9 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +7 -0
+     }
+     *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;

You have an error here, but you don't return an error at the end of this function.

Please for version 5 do the following:

Quoted 8 lines
Quoted 5 lines

1. Add a preparation patch which moves populate_string_buffer() and calculate_string_buffer() from drivers/platform/x86/dell/dell-wmi-sysman/sysman.c to drivers/platform/x86/wmi.c

Are you asking to change sysman.c which is a DELL specific driver? I don't have a DELL platform to validate the changes and I will be
doing the work on HP workday. Sorry but I cannot do that.

I'm asking you to move the functions to drivers/platform/x86/wmi.c, rename them and check they still compile. So that these functions can be shared. You won't be changing the code at all, just the function names.

And I have a Dell Latitude laptop where I can verify that dell-wmi-sysman still works.

Quoted 11 lines
Quoted 8 lines

Renaming them to:

size_t wmi_utf16_str_size(const char *str);
ssize_t wmi_str_to_utf16_str(u16 *buffer, size_t buffer_len, const char *str);

(adding these prototypes to include/linux/wmi.h)

I will make the changes requested but I'll wait for your response to the previous comments regarding calculate_string_buffer()

Ok.

Regards,

Hans

p.s.

Next time if you are replying to a really long email like my previous one, please remove any not relevant quoted text from the reply, to make it easier to find the parts where you actually reply.

#8 lore raw

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

All strings return include the string size in bytes followed by the u16 string

Quoted 51 lines
Quoted 15 lines
Quoted 15 lines

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

Quoted 9 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +7 -0
+     }
+     *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;

You have an error here, but you don't return an error at the end of this function.

Please for version 5 do the following:

Quoted 8 lines
Quoted 5 lines

1. Add a preparation patch which moves populate_string_buffer() and calculate_string_buffer() from drivers/platform/x86/dell/dell-wmi-sysman/sysman.c to drivers/platform/x86/wmi.c

Are you asking to change sysman.c which is a DELL specific driver? I don't have a DELL platform to validate the changes and I will be
doing the work on HP workday. Sorry but I cannot do that.

I'm asking you to move the functions to drivers/platform/x86/wmi.c, rename them and check they still compile. So that these functions can be shared. You won't be changing the code at all, just the function names.

And I have a Dell Latitude laptop where I can verify that dell-wmi-sysman still works.

Quoted 11 lines
Quoted 8 lines

Renaming them to:

size_t wmi_utf16_str_size(const char *str);
ssize_t wmi_str_to_utf16_str(u16 *buffer, size_t buffer_len, const char *str);

(adding these prototypes to include/linux/wmi.h)

I will make the changes requested but I'll wait for your response to the previous comments regarding calculate_string_buffer()

Ok.

Regards,

Quoted 9 lines

Hans

p.s.

Next time if you are replying to a really long email like my previous one, please remove any not relevant quoted text from the reply, to make it easier to find the parts where you actually reply.

ok.

Quoted 1 line
#9 lore raw

Hi,

Quoted 303 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

Quoted 7 lines

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

###

Also you did not answer this separate question:

I'm wondering why the empty auth string is " " and not "" ?

Regards,

Hans

#10 lore raw
Quoted 313 lines · Hans de Goede

Hi,

Quoted 309 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

Quoted 7 lines
Quoted 1 line

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

It is a specific format required by BIOS for any zero-length strings. I don't know the reason why BIOS wants that format.

Quoted 3 lines

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

I tried during the development process and each time the data is rejected by BIOS.

Quoted 6 lines

###

Also you did not answer this separate question:

I'm wondering why the empty auth string is " " and not "" ?

That was an oversight. It should be '""'. I will make the change

Quoted 6 lines

Regards,

Hans

#11 lore raw

Hi,

Quoted 325 lines · Jorge Lopez
Quoted 313 lines · Hans de Goede

Hi,

Quoted 309 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

Quoted 7 lines
Quoted 1 line

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

It is a specific format required by BIOS for any zero-length strings. I don't know the reason why BIOS wants that format.

Quoted 6 lines
Quoted 3 lines

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

I tried during the development process and each time the data is rejected by BIOS.

Ok, well in that case you are going to need your own ascii_to_utf16_unicode() to handle the weird case for the 0 sized string, so no need to move the dell-wmi-sysman versions to the shared wmi code.

But please do start with a copy of the Dell function and then add the special case for the 0 len string, since the original version above does not properly handle errors.

Also this means you need to update the hp calculate_string_buffer() copy to properly return 4 rather then 2 for the bufsize for a 0 length string.

Regards,

Hans

#12 lore raw
Quoted 341 lines · Hans de Goede

Hi,

Quoted 325 lines · Jorge Lopez
Quoted 313 lines · Hans de Goede

Hi,

Quoted 309 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

Quoted 7 lines
Quoted 1 line

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

It is a specific format required by BIOS for any zero-length strings. I don't know the reason why BIOS wants that format.

Quoted 6 lines
Quoted 3 lines

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

I tried during the development process and each time the data is rejected by BIOS.

Ok, well in that case you are going to need your own ascii_to_utf16_unicode() to handle the weird case for the 0 sized string, so no need to move the dell-wmi-sysman versions to the shared wmi code.

Quoted 8 lines

But please do start with a copy of the Dell function and then add the special case for the 0 len string, since the original version above does not properly handle errors.

Also this means you need to update the hp calculate_string_buffer() copy to properly return 4 rather then 2 for the bufsize for a 0 length string.

I will do so. Thanks.
BTW, changes requested for sysman.c will require changes to two other DELL source files;
biosattr-interface.c and passwordattr-interface.c.
All I can do is to verify it compiles ok.

Quoted 5 lines

Regards,

Hans

#13 lore raw

Hi,

Quoted 351 lines · Jorge Lopez
Quoted 341 lines · Hans de Goede

Hi,

Quoted 325 lines · Jorge Lopez
Quoted 313 lines · Hans de Goede

Hi,

Quoted 309 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

Quoted 7 lines
Quoted 1 line

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

It is a specific format required by BIOS for any zero-length strings. I don't know the reason why BIOS wants that format.

Quoted 6 lines
Quoted 3 lines

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

I tried during the development process and each time the data is rejected by BIOS.

Ok, well in that case you are going to need your own ascii_to_utf16_unicode() to handle the weird case for the 0 sized string, so no need to move the dell-wmi-sysman versions to the shared wmi code.

Quoted 8 lines

But please do start with a copy of the Dell function and then add the special case for the 0 len string, since the original version above does not properly handle errors.

Also this means you need to update the hp calculate_string_buffer() copy to properly return 4 rather then 2 for the bufsize for a 0 length string.

Quoted 5 lines

I will do so. Thanks.
BTW, changes requested for sysman.c will require changes to two other DELL source files;
biosattr-interface.c and passwordattr-interface.c.
All I can do is to verify it compiles ok.

Note that since you now need a special version to deal with the 0 length string weirdness, you can just make a private copy of the dell functions into the hp code and then modify that to add the special case for the 0 length strings.

So there is no longer a need to move the dell versions out into wmi.c since the hp code will need a modified version anyways (so the code cannot be shared).

Regards,

Hans

#14 lore raw
Quoted 367 lines · Hans de Goede

Hi,

Quoted 351 lines · Jorge Lopez
Quoted 341 lines · Hans de Goede

Hi,

Quoted 325 lines · Jorge Lopez
Quoted 313 lines · Hans de Goede

Hi,

Quoted 309 lines · Jorge Lopez

Hi Hans,

Quoted 290 lines · Hans de Goede

Hi,

Quoted 267 lines · Jorge Lopez

HI Hans,

Please see questions and comments below.

Quoted 262 lines · Hans de Goede

Hi Jorge,

Review comments inline.

Quoted 75 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

---
 .../x86/hp/hp-bioscfg/biosattr-interface.c    | 285 ++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  | 671 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       | 521 ++++++++++++++
 3 files changed, 1477 insertions(+)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +19 -0
new file mode 100644
index 000000000000..f0c919bf3ab0
@@ -0,0 +1,285 @@
+// 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 between int and buffer_size here, please drop one.

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)
+             strncpy(bioscfg_drv.password_data[instance].current_password,
+                     auth_empty_value,
+                     sizeof(bioscfg_drv.password_data[instance].current_password));

strncpy does not guarantee 0 termination of the destination buffer, please use strscpy.

Quoted 82 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +82 -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));
+
+     ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output);

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

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

You need to check the type of obj here before dereferencing obj as if it is a buffer.

Quoted 34 lines
drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file +34 -0
+     bios_return = (struct bios_return *)obj->buffer.pointer;
+     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)
+{

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

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

This does not match with calculate_string_buffer() which will return 2 for a 0 length string while you are using 4 bytes here.

Quoted 7 lines
Quoted 3 lines

I guess this may also be why you need to use " " for auth_empty_value above, so as to avoid this bug.

HP BIOS expects 2 characters when an empty string is being converted to u16 hence the reason for returning 2 instead of zero. This is an intended behavior and needed when allocating a buffer and writing to BIOS.

Right I understand that, it wants 2 characters for the 16 bit length word, but why not write 0 to that 16 bit length word. Why actually say the string-buffer length is 2 bytes long / and then write a 16-bit word with value 0?

What you are doing now creates a 4 byte buffer like this:

u8 buf[4] = { 0x02, 0x00, 0x00, 0x00 }

Why not just create a 2 byte buffer like this:

Quoted 9 lines

u8 buf[2] = { 0x00, 0x00 }

?

Also I'm wondering why the empty auth string is " " and not "" ?

The string returned for an empty string is 4 bytes. The returned string includes two bytes for the string size in bytes and the remaining bytes are the string.
Size = 0x02, 0x00
String = 0x00, 0x00

Quoted 7 lines
Quoted 1 line

All strings return include the string size in bytes followed by the u16 string

Right I understand that, but why is the "String = 0x00, 0x00" there ? All the non-0-length strings are not 0 terminated, why does the zero length string needs to be specified as length 2 (1 u16) and then have that u16 be a 0 terminator ?

It is a specific format required by BIOS for any zero-length strings. I don't know the reason why BIOS wants that format.

Quoted 6 lines
Quoted 3 lines

Have you tried just using Size[2] = 0x00, 0x00 and String[0] for an empty string?

I tried during the development process and each time the data is rejected by BIOS.

Ok, well in that case you are going to need your own ascii_to_utf16_unicode() to handle the weird case for the 0 sized string, so no need to move the dell-wmi-sysman versions to the shared wmi code.

Quoted 8 lines

But please do start with a copy of the Dell function and then add the special case for the 0 len string, since the original version above does not properly handle errors.

Also this means you need to update the hp calculate_string_buffer() copy to properly return 4 rather then 2 for the bufsize for a 0 length string.

Quoted 5 lines

I will do so. Thanks.
BTW, changes requested for sysman.c will require changes to two other DELL source files;
biosattr-interface.c and passwordattr-interface.c.
All I can do is to verify it compiles ok.

Note that since you now need a special version to deal with the 0 length string weirdness, you can just make a private copy of the dell functions into the hp code and then modify that to add the special case for the 0 length strings.

Quoted 4 lines

So there is no longer a need to move the dell versions out into wmi.c since the hp code will need a modified version anyways (so the code cannot be shared).

Understood. I just wanted to make sure.
Thanks

Quoted 4 lines

Regards,

Hans

#15 lore raw
In reply to Hans de Goede

Hi Hans,

A quick note to check the next step. The changes requested for
enum-attributes,c and several supporting functions will impact other source files. To save reviewing time, I am planning to introduce the same changes across all source files and then proceed to submit the
review. Is this option acceptable?.

Regards,

#16 lore raw

Hi,

Quoted 7 lines · Jorge Lopez

Hi Hans,

A quick note to check the next step. The changes requested for
enum-attributes,c and several supporting functions will impact other source files. To save reviewing time, I am planning to introduce the same changes across all source files and then proceed to submit the
review. Is this option acceptable?.

Yes applying the same changes to all the source files is the *intention*. This is why I stopped reviewing after reviewing the first set of files.

Regards,

Hans

#17 lore raw
Quoted 12 lines · Hans de Goede

Hi,

Quoted 7 lines · Jorge Lopez

Hi Hans,

A quick note to check the next step. The changes requested for
enum-attributes,c and several supporting functions will impact other source files. To save reviewing time, I am planning to introduce the same changes across all source files and then proceed to submit the
review. Is this option acceptable?.

Quoted 4 lines

Yes applying the same changes to all the source files is the *intention*. This is why I stopped reviewing after reviewing the first set of files.

That was understanding but I wanted to make sure.
Thanks for the confirmation.

Quoted 5 lines

Regards,

Hans

#18 lore raw

PATCH v4 3/6 HP BIOSCFG driver - set 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 2 of 4.

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

---
 .../x86/hp/hp-bioscfg/int-attributes.c        | 478 ++++++++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    | 586 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |  50 ++
 3 files changed, 1114 insertions(+)
 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
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c new file +478 -0
new file mode 100644
index 000000000000..dc295ac4f83a
@@ -0,0 +1,478 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to integer type attributes under
+ * BIOS Enumeration GUID for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 Hewlett-Packard Inc.
+ */
+
+#include "bioscfg.h"
+
+get_instance_id(integer);
+
+static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+	int instance_id = get_integer_instance_id(kobj);
+	union acpi_object *obj = NULL;
+	ssize_t ret;
+
+	if (instance_id < 0)
+		return instance_id;
+
+	/* need to use specific instance_id and guid combination to get right data */
+	obj = get_wmiobj_pointer(instance_id, HP_WMI_BIOS_INTEGER_GUID);
+	if (!obj) {
+		ret = -EIO;
+		goto current_value_show_out;
+	}
+
+	ret = snprintf(buf, PAGE_SIZE, "%d\n",  bioscfg_drv.integer_data[instance_id].current_value);
+
+current_value_show_out:
+	kfree(obj);
+	return ret;
+}
+
+/*
+ * validate_integer_input() -
+ * Validate input of current_value against lower and upper bound
+ *
+ * @instance_id: The instance on which input is validated
+ * @buf: Input value
+ */
+static int validate_integer_input(int instance_id, char *buf)
+{
+	int in_val;
+	int ret;
+
+	ret = kstrtoint(buf, 10, &in_val);
+
+	/* BIOS treats it as a read only attribute */
+	if (bioscfg_drv.integer_data[instance_id].is_readonly)
+		return -EIO;
+
+	if (in_val < bioscfg_drv.integer_data[instance_id].lower_bound ||
+			in_val > bioscfg_drv.integer_data[instance_id].upper_bound)
+		return -EINVAL;
+
+	bioscfg_drv.integer_data[instance_id].new_value = in_val;
+	/*
+	 * set pending reboot flag depending on
+	 * "RequiresPhysicalPresence" value
+	 */
+	if (bioscfg_drv.integer_data[instance_id].requires_physical_presence)
+		bioscfg_drv.pending_reboot = TRUE;
+	return 0;
+}
+
+static void update_integer_value(int instance_id)
+{
+	bioscfg_drv.integer_data[instance_id].current_value =
+		bioscfg_drv.integer_data[instance_id].new_value;
+}
+
+attribute_s_property_show(display_name_language_code, integer);
+static struct kobj_attribute integer_display_langcode =
+	__ATTR_RO(display_name_language_code);
+
+attribute_s_property_show(display_name, integer);
+static struct kobj_attribute integer_display_name =
+	__ATTR_RO(display_name);
+
+attribute_property_store(current_value, integer);
+static struct kobj_attribute integer_current_val =
+	__ATTR_RW_MODE(current_value, 0600);
+
+attribute_n_property_show(lower_bound, integer);
+static struct kobj_attribute integer_lower_bound =
+	__ATTR_RO(lower_bound);
+
+attribute_n_property_show(upper_bound, integer);
+static struct kobj_attribute integer_upper_bound =
+	__ATTR_RO(upper_bound);
+
+attribute_n_property_show(scalar_increment, integer);
+static struct kobj_attribute integer_scalar_increment =
+	__ATTR_RO(scalar_increment);
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sprintf(buf, "integer\n");
+}
+static struct kobj_attribute integer_type =
+	__ATTR_RO(type);
+
+static struct attribute *integer_attrs[] = {
+	&integer_display_langcode.attr,
+	&integer_display_name.attr,
+	&integer_current_val.attr,
+	&integer_lower_bound.attr,
+	&integer_upper_bound.attr,
+	&integer_scalar_increment.attr,
+	&integer_type.attr,
+	NULL,
+};
+
+static const struct attribute_group integer_attr_group = {
+	.attrs = integer_attrs,
+};
+
+int alloc_integer_data(void)
+{
+	int ret = 0;
+
+	bioscfg_drv.integer_instances_count = get_instance_count(HP_WMI_BIOS_INTEGER_GUID);
+	bioscfg_drv.integer_data = kcalloc(bioscfg_drv.integer_instances_count,
+					sizeof(struct integer_data), GFP_KERNEL);
+	if (!bioscfg_drv.integer_data) {
+		bioscfg_drv.integer_instances_count = 0;
+		ret = -ENOMEM;
+	}
+	return ret;
+}
+
+/*
+ * populate_int_data() -
+ * Populate all properties of an instance under integer attribute
+ *
+ * @elements: ACPI object with integer data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_integer_package_data(union acpi_object *elements, int instance_id,
+			struct kobject *attr_name_kobj)
+{
+	char *str_value = NULL;
+	int str_len;
+	int ret = 0;
+
+	bioscfg_drv.integer_data[instance_id].type = HPWMI_INTEGER_TYPE;
+	bioscfg_drv.integer_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	ret = convert_hexstr_to_str(&(elements[NAME].string.pointer),
+				       elements[NAME].string.length,
+				       &str_value, &str_len);
+	if (ACPI_FAILURE(ret)) {
+		kfree(str_value);
+		return ret;
+	}
+
+	strscpy(bioscfg_drv.integer_data[instance_id].attribute_name,
+		str_value,
+		sizeof(bioscfg_drv.integer_data[instance_id].attribute_name));
+	strscpy(bioscfg_drv.integer_data[instance_id].display_name,
+		str_value,
+		sizeof(bioscfg_drv.integer_data[instance_id].display_name));
+	kfree(str_value);
+	str_value = NULL;
+
+	populate_integer_elements_from_package(elements, instance_id, HPWMI_INTEGER_TYPE);
+	update_attribute_permissions(bioscfg_drv.integer_data[instance_id].is_readonly,
+				    &integer_current_val);
+	friendly_user_name_update(bioscfg_drv.integer_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.integer_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.integer_data[instance_id].display_name));
+	return sysfs_create_group(attr_name_kobj, &integer_attr_group);
+}
+
+int populate_integer_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.integer_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.integer_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 integer type.
+		 */
+		if (eloc == hp_wmi_elements_count[type])
+			goto exit_integer_package;
+
+		/* Assign appropriate element value to corresponding field*/
+		switch (eloc) {
+		case VALUE:
+			status = kstrtoint(str_value, 10, &int_value);
+			if (status)
+				continue;
+
+			bioscfg_drv.integer_data[instance_id].current_value = int_value;
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.integer_data[instance_id].path, str_value,
+				sizeof(bioscfg_drv.integer_data[instance_id].path));
+			break;
+		case IS_READONLY:
+			bioscfg_drv.integer_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.integer_data[instance_id].display_in_ui = int_value;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.integer_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.integer_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.integer_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.integer_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.integer_data[instance_id].prerequisites,
+					str_value,
+					sizeof(bioscfg_drv.integer_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.integer_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.integer_data[instance_id].prerequisites));
+
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.integer_data[instance_id].security_level = int_value;
+			break;
+		case INT_LOWER_BOUND:
+			bioscfg_drv.integer_data[instance_id].lower_bound = int_value;
+			break;
+		case INT_UPPER_BOUND:
+			bioscfg_drv.integer_data[instance_id].upper_bound = int_value;
+			break;
+		case INT_SCALAR_INCREMENT:
+			bioscfg_drv.integer_data[instance_id].scalar_increment = int_value;
+			break;
+
+		default:
+			pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str_value);
+		str_value = NULL;
+	}
+exit_integer_package:
+	kfree(str_value);
+	str_value = NULL;
+	return 0;
+}
+
+
+/*
+ * populate_integer_buffer_data() -
+ * Populate all properties of an instance under integer attribute
+ *
+ * @integer_obj: ACPI object with integer data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_integer_buffer_data(union acpi_object *integer_obj, int instance_id,
+			struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.integer_data[instance_id].type = HPWMI_INTEGER_TYPE;
+	bioscfg_drv.integer_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	strscpy(bioscfg_drv.integer_data[instance_id].attribute_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.integer_data[instance_id].attribute_name));
+
+	strscpy(bioscfg_drv.integer_data[instance_id].display_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.integer_data[instance_id].display_name));
+
+	/* Populate integer elements */
+	populate_integer_elements_from_buffer(integer_obj, instance_id, HPWMI_INTEGER_TYPE);
+	update_attribute_permissions(bioscfg_drv.integer_data[instance_id].is_readonly,
+				    &integer_current_val);
+	friendly_user_name_update(bioscfg_drv.integer_data[instance_id].path,
+				  attr_name_kobj->name,
+				   bioscfg_drv.integer_data[instance_id].display_name,
+				   sizeof(bioscfg_drv.integer_data[instance_id].display_name));
+
+	return sysfs_create_group(attr_name_kobj, &integer_attr_group);
+}
+
+int populate_integer_elements_from_buffer(union acpi_object *integer_obj,
+					  int instance_id, enum hp_wmi_data_type type)
+{
+	int status;
+	char *str = NULL;
+	int elem;
+	int reqs;
+	int integer;
+	int size = 0;
+	int ret;
+
+	elem = 0;
+	strscpy(bioscfg_drv.integer_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.integer_data[instance_id].display_name_language_code));
+
+	for (elem = 1; elem < 3; elem++) {
+
+		status = get_string_from_buffer((u16 **)&integer_obj->buffer.pointer, &str);
+		if (ACPI_FAILURE(status))
+			continue;
+
+		switch (elem) {
+		case VALUE:
+			ret = kstrtoint(str, 10, &integer);
+			if (ret)
+				continue;
+
+			bioscfg_drv.integer_data[instance_id].current_value = integer;
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.integer_data[instance_id].path, str,
+				sizeof(bioscfg_drv.integer_data[instance_id].path));
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Integer 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 **)&integer_obj->buffer.pointer, (int *)&integer);
+
+		if (ACPI_FAILURE(status))
+			continue;
+
+		switch (elem) {
+
+		case IS_READONLY:
+			bioscfg_drv.integer_data[instance_id].is_readonly = integer;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.integer_data[instance_id].display_in_ui = integer;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.integer_data[instance_id].requires_physical_presence = integer;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.integer_data[instance_id].sequence = integer;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.integer_data[instance_id].prerequisitesize = integer;
+			size = integer;
+			if (size > 20)
+				pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n");
+
+			break;
+		case PREREQUISITES:
+			for (reqs = 0; reqs < size; reqs++) {
+				status = get_string_from_buffer((u16 **)&integer_obj->buffer.pointer, &str);
+				if (ACPI_FAILURE(status))
+					continue;
+
+				strlcat(bioscfg_drv.integer_data[instance_id].prerequisites,
+					str,
+					sizeof(bioscfg_drv.integer_data[instance_id].prerequisites));
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.integer_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.integer_data[instance_id].prerequisites));
+
+				kfree(str);
+				str = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.integer_data[instance_id].security_level = integer;
+			break;
+		case INT_LOWER_BOUND:
+			bioscfg_drv.integer_data[instance_id].lower_bound = integer;
+			break;
+		case INT_UPPER_BOUND:
+			bioscfg_drv.integer_data[instance_id].upper_bound = integer;
+			break;
+		case INT_SCALAR_INCREMENT:
+			bioscfg_drv.integer_data[instance_id].scalar_increment = integer;
+			break;
+
+		default:
+			pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+	return 0;
+}
+
+/*
+ * exit_integer_attributes() - Clear all attribute data
+ *
+ * Clears all data allocated for this group of attributes
+ */
+void exit_integer_attributes(void)
+{
+	int instance_id;
+
+	for (instance_id = 0; instance_id < bioscfg_drv.integer_instances_count; instance_id++) {
+		if (bioscfg_drv.integer_data[instance_id].attr_name_kobj)
+			sysfs_remove_group(bioscfg_drv.integer_data[instance_id].attr_name_kobj,
+								&integer_attr_group);
+	}
+	bioscfg_drv.integer_instances_count = 0;
+
+	kfree(bioscfg_drv.integer_data);
+	bioscfg_drv.integer_data = NULL;
+}
drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c new file +586 -0

586 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.34.1
#19 lore raw

PATCH v4 4/6 HP BIOSCFG driver - set 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 3 of 4.

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

---
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  | 647 ++++++++++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     | 408 +++++++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     | 457 +++++++++++++
 3 files changed, 1512 insertions(+)
 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
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c new file +647 -0
new file mode 100644
index 000000000000..e69688e7d55e
@@ -0,0 +1,647 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to password object type attributes under
+ * BIOS PASSWORD for use with hp-bioscfg driver.
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include "bioscfg.h"
+#include <asm-generic/posix_types.h>
+
+get_instance_id(password);
+
+int clear_passwords(const int instance)
+{
+	if (!bioscfg_drv.password_data[instance].is_enabled)
+		return 0;
+
+	memset(bioscfg_drv.password_data[instance].current_password,
+	       0, sizeof(bioscfg_drv.password_data[instance].current_password));
+	memset(bioscfg_drv.password_data[instance].new_password,
+	       0, sizeof(bioscfg_drv.password_data[instance].new_password));
+
+	return 0;
+}
+
+int clear_all_passwords(void)
+{
+	int instance;
+
+	for (instance = 0; instance < bioscfg_drv.password_instances_count; instance++)
+		clear_passwords(instance);
+
+	return 0;
+}
+
+int get_password_instance_for_type(const char *name)
+{
+	int count = bioscfg_drv.password_instances_count;
+	int instance;
+
+	for (instance = 0; instance < count; instance++) {
+		if (strcmp(bioscfg_drv.password_data[instance].display_name, name) == 0)
+			return instance;
+	}
+	return -EINVAL;
+}
+
+int validate_password_input(int instance_id, const char *buf)
+{
+	int length;
+
+	length = strlen(buf);
+	if (buf[length-1] == '\n')
+		length--;
+
+	if (length > MAX_PASSWD_SIZE)
+		return INVALID_BIOS_AUTH;
+
+	if (bioscfg_drv.password_data[instance_id].min_password_length > length ||
+	    bioscfg_drv.password_data[instance_id].max_password_length < length)
+		return INVALID_BIOS_AUTH;
+	return SUCCESS;
+}
+
+int password_is_set(const char *name)
+{
+	int id;
+
+	id = get_password_instance_for_type(name);
+	if (id < 0)
+		return 0;
+
+	return bioscfg_drv.password_data[id].is_enabled;
+}
+
+attribute_n_property_show(is_enabled, password);
+static struct kobj_attribute password_is_password_set = __ATTR_RO(is_enabled);
+
+static ssize_t current_password_store(struct kobject *kobj,
+				      struct kobj_attribute *attr,
+				      const char *buf, size_t count)
+{
+	char *p, *buf_cp;
+	int id, ret = 0;
+
+	buf_cp = kstrdup(buf, GFP_KERNEL);
+	if (!buf_cp) {
+		ret = -ENOMEM;
+		goto exit_current_password;
+	}
+
+	p = memchr(buf_cp, '\n', count);
+
+	if (p != NULL)
+		*p = '\0';
+
+	id = get_password_instance_id(kobj);
+
+	if (id >= 0)
+		ret = validate_password_input(id, buf_cp);
+
+	if (!ret) {
+		strscpy(bioscfg_drv.password_data[id].current_password,
+			buf_cp,
+			sizeof(bioscfg_drv.password_data[id].current_password));
+		/*
+		 * set pending reboot flag depending on
+		 * "RequiresPhysicalPresence" value
+		 */
+		if (bioscfg_drv.password_data[id].requires_physical_presence)
+			bioscfg_drv.pending_reboot = TRUE;
+	}
+
+exit_current_password:
+	kfree(buf_cp);
+	return ret ? ret : count;
+}
+static struct kobj_attribute password_current_password = __ATTR_WO(current_password);
+
+static ssize_t new_password_store(struct kobject *kobj,
+				  struct kobj_attribute *attr,
+				  const char *buf, size_t count)
+{
+	char *p, *buf_cp = NULL;
+	int id, ret = -EIO;
+
+	buf_cp = kstrdup(buf, GFP_KERNEL);
+	if (!buf_cp) {
+		ret = -ENOMEM;
+		goto exit_new_password;
+	}
+
+	p = memchr(buf_cp, '\n', count);
+
+	if (p != NULL)
+		*p = '\0';
+
+	id = get_password_instance_id(kobj);
+
+	if (id >= 0)
+		ret = validate_password_input(id, buf_cp);
+
+	if (!ret)
+		strscpy(bioscfg_drv.password_data[id].new_password,
+			buf_cp,
+			sizeof(bioscfg_drv.password_data[id].new_password));
+
+	if (!ret)
+		ret = hp_set_attribute(kobj->name, buf_cp);
+
+exit_new_password:
+	/*
+	 * Regardless of the results both new and current passwords
+	 * will be set to zero and avoid security issues
+	 */
+	clear_passwords(id);
+
+	kfree(buf_cp);
+	return ret ? ret : count;
+}
+
+static struct kobj_attribute password_new_password = __ATTR_WO(new_password);
+
+
+attribute_n_property_show(min_password_length, password);
+static struct kobj_attribute password_min_password_length = __ATTR_RO(min_password_length);
+
+attribute_n_property_show(max_password_length, password);
+static struct kobj_attribute password_max_password_length = __ATTR_RO(max_password_length);
+
+static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	if (strcmp(kobj->name, SETUP_PASSWD) == 0)
+		return sprintf(buf, "%s\n", role_type[BIOS_ADMIN]);
+
+	if (strcmp(kobj->name, POWER_ON_PASSWD) == 0)
+		return sprintf(buf,  "%s\n", role_type[POWER_ON]);
+
+	return -EIO;
+}
+static struct kobj_attribute password_role = __ATTR_RO(role);
+
+static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
+			   char *buf)
+{
+	int i = get_password_instance_id(kobj);
+
+	if (i < 0)
+		return i;
+
+	if (bioscfg_drv.password_data[i].mechanism != PASSWORD)
+		return -EINVAL;
+
+	return sprintf(buf, "%s\n",
+		       passwd_mechanism_types[bioscfg_drv.password_data[i].mechanism]);
+}
+static struct kobj_attribute password_mechanism = __ATTR_RO(mechanism);
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sprintf(buf, "password\n");
+}
+static struct kobj_attribute password_type = __ATTR_RO(type);
+
+attribute_s_property_show(display_name, password);
+static struct kobj_attribute password_display_name =
+		__ATTR_RO(display_name);
+
+attribute_s_property_show(display_name_language_code, password);
+static struct kobj_attribute password_display_langcode =
+		__ATTR_RO(display_name_language_code);
+
+attribute_s_property_show(supported_encoding,  password);
+static struct kobj_attribute password_encoding =
+		__ATTR_RO(supported_encoding);
+
+attribute_n_property_show(encoding_size,  password);
+static struct kobj_attribute password_encoding_size =
+		__ATTR_RO(encoding_size);
+
+static struct attribute *password_attrs[] = {
+	&password_is_password_set.attr,
+	&password_min_password_length.attr,
+	&password_max_password_length.attr,
+	&password_current_password.attr,
+	&password_new_password.attr,
+	&password_role.attr,
+	&password_mechanism.attr,
+	&password_type.attr,
+	&password_display_name.attr,
+	&password_display_langcode.attr,
+	&password_encoding.attr,
+	&password_encoding_size.attr,
+	NULL,
+};
+
+static const struct attribute_group bios_password_attr_group = {
+	.attrs = password_attrs,
+};
+
+static const struct attribute_group system_password_attr_group = {
+	.attrs = password_attrs,
+};
+
+int alloc_password_data(void)
+{
+	int ret = 0;
+
+	bioscfg_drv.password_instances_count = get_instance_count(HP_WMI_BIOS_PASSWORD_GUID);
+	bioscfg_drv.password_data = kcalloc(bioscfg_drv.password_instances_count,
+					    sizeof(struct password_data), GFP_KERNEL);
+	if (!bioscfg_drv.password_data) {
+		bioscfg_drv.password_instances_count = 0;
+		ret = -ENOMEM;
+	}
+
+	return ret;
+}
+
+/*
+ * populate_password_package_data -
+ *	Populate all properties for an instance under password attribute
+ *
+ * @password_obj: ACPI object with password data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_password_package_data(union acpi_object *password_obj, int instance_id,
+				   struct kobject *attr_name_kobj)
+{
+	char *str_value = NULL;
+	int str_len;
+	int ret = 0;
+
+	bioscfg_drv.password_data[instance_id].type = HPWMI_PASSWORD_TYPE;
+	bioscfg_drv.password_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	ret = convert_hexstr_to_str(&(password_obj[NAME].string.pointer),
+				    password_obj[NAME].string.length,
+				    &str_value, &str_len);
+
+	if (ACPI_FAILURE(ret)) {
+		kfree(str_value);
+		return ret;
+	}
+
+	strscpy(bioscfg_drv.password_data[instance_id].attribute_name,
+		str_value,
+		sizeof(bioscfg_drv.password_data[instance_id].attribute_name));
+	strscpy(bioscfg_drv.password_data[instance_id].display_name,
+		str_value,
+		sizeof(bioscfg_drv.password_data[instance_id].display_name));
+
+	kfree(str_value);
+	str_value = NULL;
+
+	populate_password_elements_from_package(password_obj, instance_id, HPWMI_PASSWORD_TYPE);
+
+	if (strcmp(attr_name_kobj->name, "Setup Password") == 0) {
+		/* Save  system authentication instance for easy access */
+		return sysfs_create_group(attr_name_kobj, &bios_password_attr_group);
+	}
+
+	return sysfs_create_group(attr_name_kobj, &system_password_attr_group);
+}
+
+int populate_password_elements_from_package(union acpi_object *password_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.password_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.password_data[instance_id].display_name_language_code));
+
+	for (elem = 1, eloc = 1; elem < hp_wmi_elements_count[type]; elem++, eloc++) {
+
+		switch (password_obj[elem].type) {
+		case ACPI_TYPE_STRING:
+
+			if (PREREQUISITES != elem && ENUM_POSSIBLE_VALUES != elem) {
+				status = convert_hexstr_to_str(&password_obj[elem].string.pointer,
+							       password_obj[elem].string.length,
+							       &str_value, &value_len);
+
+				if (ACPI_FAILURE(status))
+					continue;
+
+			}
+			break;
+		case ACPI_TYPE_INTEGER:
+			int_value = (u32)password_obj[elem].integer.value;
+			break;
+		default:
+			pr_warn("Unsupported object type [%d]\n", password_obj[elem].type);
+			continue;
+		}
+
+		/* stop if extra counter is greater than total number
+		 * of elements for password type
+		 */
+		if (eloc == hp_wmi_elements_count[type])
+			goto exit_password_package;
+
+		/* Assign appropriate element value to corresponding field*/
+		switch (eloc) {
+		case VALUE:
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.password_data[instance_id].path, str_value,
+				sizeof(bioscfg_drv.password_data[instance_id].path));
+			break;
+		case IS_READONLY:
+			bioscfg_drv.password_data[instance_id].is_readonly = int_value;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.password_data[instance_id].display_in_ui = int_value;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.password_data[instance_id].requires_physical_presence = int_value;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.password_data[instance_id].sequence = int_value;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.password_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.password_data[instance_id].prerequisitesize;
+
+			for (reqs = 0; reqs < size; reqs++) {
+				status = convert_hexstr_to_str(&password_obj[elem].string.pointer,
+							       password_obj[elem].string.length,
+							       &str_value, &value_len);
+
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.password_data[instance_id].prerequisites,
+					str_value,
+					sizeof(bioscfg_drv.password_data[instance_id].prerequisites));
+
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.password_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.password_data[instance_id].prerequisites));
+
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+
+		case SECURITY_LEVEL:
+			bioscfg_drv.password_data[instance_id].security_level = int_value;
+			break;
+
+		case PSWD_MIN_LENGTH:
+			bioscfg_drv.password_data[instance_id].min_password_length = int_value;
+			break;
+		case PSWD_MAX_LENGTH:
+			bioscfg_drv.password_data[instance_id].max_password_length = int_value;
+			break;
+		case PSWD_SIZE:
+			bioscfg_drv.password_data[instance_id].encoding_size = int_value;
+			break;
+		case PSWD_SUPPORTED_ENCODING:
+			size = bioscfg_drv.password_data[instance_id].encoding_size;
+			for (pos_values = 0; pos_values < size; pos_values++) {
+				status = convert_hexstr_to_str(&password_obj[elem + pos_values].string.pointer,
+							       password_obj[elem  + pos_values].string.length,
+							       &str_value, &value_len);
+				if (ACPI_FAILURE(status))
+					break;
+
+				strlcat(bioscfg_drv.password_data[instance_id].supported_encoding,
+					str_value,
+					sizeof(bioscfg_drv.password_data[instance_id].supported_encoding));
+
+				if (pos_values < (size - 1))
+					strlcat(bioscfg_drv.password_data[instance_id].supported_encoding, ";",
+						sizeof(bioscfg_drv.password_data[instance_id].supported_encoding));
+				kfree(str_value);
+				str_value = NULL;
+			}
+			break;
+		case PSWD_IS_SET:
+			bioscfg_drv.password_data[instance_id].is_enabled = int_value;
+			break;
+
+		default:
+			pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str_value);
+		str_value = NULL;
+	}
+
+exit_password_package:
+	kfree(str_value);
+	str_value = NULL;
+	return 0;
+}
+
+/*
+ * populate_password_buffer_data -
+ * Populate all properties for an instance under password object attribute
+ *
+ * @password_obj: ACPI object with password object data
+ * @instance_id: The instance to enumerate
+ * @attr_name_kobj: The parent kernel object
+ */
+int populate_password_buffer_data(union acpi_object *password_obj, int instance_id,
+			   struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.password_data[instance_id].type = HPWMI_PASSWORD_TYPE;
+	bioscfg_drv.password_data[instance_id].attr_name_kobj = attr_name_kobj;
+
+	strscpy(bioscfg_drv.password_data[instance_id].attribute_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.password_data[instance_id].attribute_name));
+	strscpy(bioscfg_drv.password_data[instance_id].display_name,
+		attr_name_kobj->name,
+		sizeof(bioscfg_drv.password_data[instance_id].display_name));
+
+	/* Populate Password attributes */
+	populate_password_elements_from_buffer(password_obj, instance_id, HPWMI_PASSWORD_TYPE);
+	if (strcmp(attr_name_kobj->name, "Setup Password") == 0)
+		return sysfs_create_group(attr_name_kobj, &bios_password_attr_group);
+
+	return sysfs_create_group(attr_name_kobj, &system_password_attr_group);
+}
+
+int populate_password_elements_from_buffer(union acpi_object *password_obj,
+					   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.password_data[instance_id].display_name_language_code,
+		LANG_CODE_STR,
+		sizeof(bioscfg_drv.password_data[instance_id].display_name_language_code));
+
+	for (elem = 1; elem < 3; elem++) {
+
+		status = get_string_from_buffer((u16 **)&password_obj->buffer.pointer, &str);
+		if (ACPI_FAILURE(status))
+			continue;
+
+		switch (elem) {
+		case VALUE:
+			strscpy(bioscfg_drv.password_data[instance_id].current_password,
+				str, sizeof(bioscfg_drv.password_data[instance_id].current_password));
+			break;
+		case PATH:
+			strscpy(bioscfg_drv.password_data[instance_id].path, str,
+				sizeof(bioscfg_drv.password_data[instance_id].path));
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Password  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  && elem != PSWD_SUPPORTED_ENCODING)
+			status = get_integer_from_buffer((int **)&password_obj->buffer.pointer, (int *)&integer);
+
+		if (ACPI_FAILURE(status))
+			continue;
+
+		switch (elem) {
+		case IS_READONLY:
+			bioscfg_drv.password_data[instance_id].is_readonly = integer;
+			break;
+		case DISPLAY_IN_UI:
+			bioscfg_drv.password_data[instance_id].display_in_ui = integer;
+			break;
+		case REQUIRES_PHYSICAL_PRESENCE:
+			bioscfg_drv.password_data[instance_id].requires_physical_presence = integer;
+			break;
+		case SEQUENCE:
+			bioscfg_drv.password_data[instance_id].sequence = integer;
+			break;
+		case PREREQUISITE_SIZE:
+			bioscfg_drv.password_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.password_data[instance_id].prerequisitesize;
+			for (reqs = 0; reqs < size; reqs++) {
+				status = get_string_from_buffer((u16 **)&password_obj->buffer.pointer, &str);
+				if (ACPI_FAILURE(status))
+					continue;
+
+				strlcat(bioscfg_drv.password_data[instance_id].prerequisites,
+					str,
+					sizeof(bioscfg_drv.password_data[instance_id].prerequisites));
+
+				if (reqs != (size - 1))
+					strlcat(bioscfg_drv.password_data[instance_id].prerequisites, ";",
+						sizeof(bioscfg_drv.password_data[instance_id].prerequisites));
+
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		case SECURITY_LEVEL:
+			bioscfg_drv.password_data[instance_id].security_level = integer;
+			break;
+
+		case PSWD_MIN_LENGTH:
+			bioscfg_drv.password_data[instance_id].min_password_length = integer;
+			break;
+		case PSWD_MAX_LENGTH:
+			bioscfg_drv.password_data[instance_id].max_password_length = integer;
+			break;
+		case PSWD_SIZE:
+			bioscfg_drv.password_data[instance_id].encoding_size = integer;
+			break;
+		case PSWD_SUPPORTED_ENCODING:
+			size = bioscfg_drv.password_data[instance_id].encoding_size;
+			for (values = 0; values < size; values++) {
+				status = get_string_from_buffer((u16 **)&password_obj->buffer.pointer, &str);
+				if (ACPI_FAILURE(status))
+					continue;
+
+				strlcat(bioscfg_drv.password_data[instance_id].supported_encoding,
+					str,
+					sizeof(bioscfg_drv.password_data[instance_id].supported_encoding));
+
+				if (values != (size - 1))
+					strlcat(bioscfg_drv.password_data[instance_id].supported_encoding, ";",
+						sizeof(bioscfg_drv.password_data[instance_id].supported_encoding));
+
+				kfree(str);
+				str = NULL;
+			}
+			break;
+		case PSWD_IS_SET:
+			bioscfg_drv.password_data[instance_id].is_enabled = integer;
+			break;
+		default:
+			pr_warn("Invalid element: %d found in Password  attribute or data may be malformed\n", elem);
+			break;
+		}
+		kfree(str);
+		str = NULL;
+	}
+	kfree(str);
+	str = NULL;
+
+	return 0;
+}
+
+/*
+ * exit_password_attributes() - Clear all attribute data
+ *
+ * Clears all data allocated for this group of attributes
+ */
+void exit_password_attributes(void)
+{
+	int instance_id;
+
+	for (instance_id = 0; instance_id < bioscfg_drv.password_instances_count; instance_id++) {
+		if (bioscfg_drv.password_data[instance_id].attr_name_kobj) {
+			if (strcmp(bioscfg_drv.password_data[instance_id].attr_name_kobj->name, SETUP_PASSWD) == 0)
+				sysfs_remove_group(bioscfg_drv.password_data[instance_id].attr_name_kobj,
+								&bios_password_attr_group);
+			else
+				sysfs_remove_group(bioscfg_drv.password_data[instance_id].attr_name_kobj,
+								&system_password_attr_group);
+		}
+	}
+	bioscfg_drv.password_instances_count = 0;
+	kfree(bioscfg_drv.password_data);
+	bioscfg_drv.password_data = NULL;
+}
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c new file +408 -0

408 lines not on this page · raw message

drivers/platform/x86/hp/hp-bioscfg/string-attributes.c new file +457 -0

457 lines not on this page · raw message

Signature · 1 line
2.34.1
#20 lore raw

PATCH v4 5/6 HP BIOSCFG driver - set 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 4 of 4.

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

---
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 +++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  145 +++
 2 files changed, 1159 insertions(+)
 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/sureadmin-attributes.c new file +1014 -0
new file mode 100644
index 000000000000..5ad45cdddad9
@@ -0,0 +1,1014 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Functions corresponding to sure admin object type attributes under
+ * BIOS for use with hp-bioscfg driver
+ *
+ *  Copyright (c) 2022 HP Development Company, L.P.
+ */
+
+#include "bioscfg.h"
+
+static int bios_settings_size;
+static int buf_alloc_size;
+static char *bios_settings_buffer;
+
+const char *hp_wmi_classes[] = {
+	"HPBIOS_BIOSString",
+	"HPBIOS_BIOSInteger",
+	"HPBIOS_BIOSEnumeration",
+	"HPBIOS_BIOSOrderedList",
+	"HPBIOS_BIOSPassword"
+};
+
+get_instance_id_for_attribute(string);
+get_instance_id_for_attribute(integer);
+get_instance_id_for_attribute(enumeration);
+get_instance_id_for_attribute(ordered_list);
+
+static ssize_t sure_admin_settings_write(struct file *filp, struct kobject *kobj,
+					 struct bin_attribute *attr,
+					 char *buf, loff_t off, size_t count)
+{
+	int status = 0;
+	char *part = NULL;
+	char *attr_name = NULL;
+	char *attr_value = NULL;
+	int part_len = 0;
+	unsigned short *buffer = NULL;
+	unsigned short *tmpstr = NULL;
+	int buffer_size = (count + strlen(UTF_PREFIX)) * sizeof(unsigned short);
+
+	buffer = kmalloc(buffer_size, GFP_KERNEL);
+	if (!buffer)
+		return -ENOMEM;
+
+	tmpstr = buffer;
+	part = strsep(&buf, ",");
+	if (!part) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+	// Save attr_name
+	attr_name = kmalloc(strlen(part) + 1, GFP_KERNEL);
+	if (!attr_name) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+	strncpy(attr_name, part, strlen(part));
+
+	tmpstr = ascii_to_utf16_unicode(tmpstr, part);
+	part = strsep(&buf, ",");
+	if (!part) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+
+	part_len = strlen(part);
+
+	/* Add extra buffer space when encountering an empty string */
+	if (!part_len) {
+		buffer_size += sizeof(unsigned short);
+		part_len += sizeof(unsigned short);
+	}
+
+	// Save attr_value
+	attr_value = kmalloc(part_len + 1, GFP_KERNEL);
+	if (!attr_value) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+	strncpy(attr_value, part, part_len);
+
+	tmpstr = ascii_to_utf16_unicode(tmpstr, part);
+	part = strsep(&buf, ",");
+	if (!part) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+	part_len = strlen(part) - 1;
+	part[part_len] = '\0';
+
+	if (strncmp(part, BEAM_PREFIX, strlen(BEAM_PREFIX)) == 0) {
+	       /*
+		* BEAM_PREFIX is append to buffer when a signature
+		* is provided and Sure Admin is enabled in BIOS
+		*/
+		// BEAM_PREFIX found, convert part to unicode
+		tmpstr = ascii_to_utf16_unicode(tmpstr, part);
+		// decrease buffer size allocated initially for UTF_PREFIX
+		buffer_size -= strlen(UTF_PREFIX) * sizeof(unsigned short);
+	} else {
+		/*
+		 * UTF-16 prefix is append to the * buffer when a BIOS
+		 * admin password is configured in BIOS
+		 */
+
+		// append UTF_PREFIX to part and then convert it to unicode
+		part = kasprintf(GFP_KERNEL, "%s%s", UTF_PREFIX, part);
+		if (!part)
+			goto exit_settings;
+
+		tmpstr = ascii_to_utf16_unicode(tmpstr, part);
+		kfree(part);
+	}
+
+	part = strsep(&buf, ",");
+	if (part) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+
+	status = hp_wmi_set_bios_setting(buffer, buffer_size);
+	if (ACPI_FAILURE(status)) {
+		status = -EINVAL;
+		goto exit_settings;
+	}
+
+	if (attr_name == NULL)
+		pr_warn("Name is null\n");
+	if (attr_value == NULL)
+		pr_warn("Value is null\n");
+
+	update_attribute_value(attr_name, attr_value);
+
+
+exit_settings:
+	kfree(buffer);
+	kfree(attr_name);
+	kfree(attr_value);
+
+	if (ACPI_SUCCESS(status))
+		return count;
+
+	return status;
+}
+
+int update_attribute_value(char *attr_name, char *attr_value)
+{
+	int instance = -EIO;
+	int int_val;
+	int ret;
+
+	if (!attr_name || !attr_value)
+		return -EIO;
+
+	/* update value for the attribute */
+	instance = get_instance_id_for_string(attr_name);
+	if (instance >= 0) {
+		strscpy(bioscfg_drv.string_data[instance].current_value,
+			attr_value,
+			sizeof(bioscfg_drv.string_data[instance].current_value));
+
+		/*
+		 * set pending reboot flag depending on
+		 * "RequiresPhysicalPresence" value
+		 */
+		if (bioscfg_drv.string_data[instance].requires_physical_presence)
+			bioscfg_drv.pending_reboot = TRUE;
+		goto exit_update_attribute;
+	}
+
+	instance = get_instance_id_for_integer(attr_name);
+	if (instance >= 0) {
+		ret = kstrtoint(attr_value, 10, &int_val);
+		if (!ret) {
+			bioscfg_drv.integer_data[instance].current_value = int_val;
+			/*
+			 * set pending reboot flag depending on
+			 * "RequiresPhysicalPresence" value
+			 */
+			if (bioscfg_drv.integer_data[instance].requires_physical_presence)
+				bioscfg_drv.pending_reboot = TRUE;
+		}
+
+		goto exit_update_attribute;
+	}
+
+	instance = get_instance_id_for_enumeration(attr_name);
+	if (instance >= 0) {
+		strscpy(bioscfg_drv.enumeration_data[instance].current_value,
+			attr_value,
+			sizeof(bioscfg_drv.enumeration_data[instance].current_value));
+		/*
+		 * set pending reboot flag depending on
+		 * "RequiresPhysicalPresence" value
+		 */
+		if (bioscfg_drv.enumeration_data[instance].requires_physical_presence)
+			bioscfg_drv.pending_reboot = TRUE;
+
+		goto exit_update_attribute;
+	}
+	instance = get_instance_id_for_ordered_list(attr_name);
+	if (instance >= 0) {
+		strscpy(bioscfg_drv.ordered_list_data[instance].current_value,
+			attr_value,
+			sizeof(bioscfg_drv.ordered_list_data[instance].current_value));
+
+		/*
+		 * set pending reboot flag depending on
+		 * "RequiresPhysicalPresence" value
+		 */
+		if (bioscfg_drv.ordered_list_data[instance].requires_physical_presence)
+			bioscfg_drv.pending_reboot = TRUE;
+	}
+
+exit_update_attribute:
+	return instance;
+}
+
+static ssize_t sure_admin_settings_read(struct file *filp, struct kobject *kobj,
+					struct bin_attribute *attr, char *buf,
+					loff_t off, size_t count)
+{
+	ssize_t ret;
+
+	/* clear the buffer when offset is pointing to the last position */
+	if (off >= bios_settings_size && bios_settings_size > 0) {
+		hp_bios_settings_free_buffer();
+		return 0;
+	}
+
+	/* clear the buffer whenever the read starts from the first position */
+	if (off == 0 && bios_settings_size > 0)
+		hp_bios_settings_free_buffer();
+
+	if (bios_settings_size == 0)
+		hp_bios_settings_fill_buffer();
+
+	mutex_lock(&bioscfg_drv.mutex);
+	ret = memory_read_from_buffer(buf, count, &off, bios_settings_buffer,
+				      bios_settings_size);
+	mutex_unlock(&bioscfg_drv.mutex);
+
+	return ret;
+}
+
+HPWMI_BINATTR_RW(sure_admin, settings, 0);
+
+static struct bin_attribute *sure_admin_binattrs[] = {
+	&sure_admin_settings,
+	NULL,
+};
+
+static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+			 char *buf)
+{
+	return sprintf(buf, "sure-admin\n");
+}
+static struct kobj_attribute sure_admin_type = __ATTR_RO(type);
+
+static ssize_t display_name_language_code_show(struct kobject *kobj,
+					       struct kobj_attribute *attr,
+					       char *buf)
+{
+	return sprintf(buf, "%s\n", LANG_CODE_STR);
+}
+
+static struct kobj_attribute sure_admin_display_langcode =
+		__ATTR_RO(display_name_language_code);
+
+
+static ssize_t display_name_show(struct kobject *kobj,
+				 struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%s\n", SURE_ADMIN_DESC);
+}
+static struct kobj_attribute sure_admin_display_name = __ATTR_RO(display_name);
+
+static struct attribute *sure_admin_attrs[] = {
+	&sure_admin_display_name.attr,
+	&sure_admin_display_langcode.attr,
+	&sure_admin_type.attr,
+	NULL,
+};
+
+static const struct attribute_group sure_admin_attr_group = {
+	.attrs = sure_admin_attrs,
+	.bin_attrs = sure_admin_binattrs,
+};
+
+void exit_sure_admin_attributes(void)
+{
+	sysfs_remove_group(bioscfg_drv.sure_admin_attr_kobj, &sure_admin_attr_group);
+}
+
+int populate_sure_admin_data(struct kobject *attr_name_kobj)
+{
+	bioscfg_drv.sure_admin_attr_kobj = attr_name_kobj;
+	return sysfs_create_group(attr_name_kobj, &sure_admin_attr_group);
+}
+
+int hp_bios_settings_fill_buffer(void)
+{
+	int status = 0;
+	int initial_buffer_size = 20 * PAGE_SIZE;
+
+	mutex_lock(&bioscfg_drv.mutex);
+	bios_settings_buffer = kmalloc(initial_buffer_size, GFP_KERNEL);
+	mutex_unlock(&bioscfg_drv.mutex);
+	if (!bios_settings_buffer)
+		return -ENOMEM;
+
+	mutex_lock(&bioscfg_drv.mutex);
+	buf_alloc_size = ksize(bios_settings_buffer);
+	memset(bios_settings_buffer, 0x00, buf_alloc_size);
+	bios_settings_size = snprintf(bios_settings_buffer,
+					buf_alloc_size, "[\n");
+	mutex_unlock(&bioscfg_drv.mutex);
+
+	status = append_read_settings(HPWMI_STRING_TYPE,
+					   &bios_settings_buffer,
+					   &bios_settings_size,
+					   &buf_alloc_size);
+	if (ACPI_FAILURE(status))
+		pr_err("error 0x%x occurred retrieving string instances\n", status);
+
+	status = append_read_settings(HPWMI_INTEGER_TYPE,
+					   &bios_settings_buffer,
+					   &bios_settings_size,
+					   &buf_alloc_size);
+	if (ACPI_FAILURE(status))
+		pr_err("error 0x%x occurred retrieving integer instances\n", status);
+
+	status = append_read_settings(HPWMI_ENUMERATION_TYPE,
+					   &bios_settings_buffer,
+					   &bios_settings_size,
+					   &buf_alloc_size);
+	if (ACPI_FAILURE(status))
+		pr_err("error 0x%x occurred retrieving enumeration instances\n", status);
+
+	status = append_read_settings(HPWMI_ORDERED_LIST_TYPE,
+					   &bios_settings_buffer,
+					   &bios_settings_size,
+					   &buf_alloc_size);
+	if (ACPI_FAILURE(status))
+		pr_err("error 0x%x occurred retrieving ordered list instances\n", status);
+
+	status = append_read_settings(HPWMI_PASSWORD_TYPE,
+					   &bios_settings_buffer,
+					   &bios_settings_size,
+					   &buf_alloc_size);
+	if (ACPI_FAILURE(status))
+		pr_err("error 0x%x occurred retrieving password list instances\n", status);
+
+	mutex_lock(&bioscfg_drv.mutex);
+	/*
+	 * remove trailing comma
+	 */
+	if (bios_settings_size >= 3) {
+		if (bios_settings_buffer[bios_settings_size - 2] == ',')
+			bios_settings_buffer[bios_settings_size - 2] = ' ';
+	}
+	bios_settings_size = snprintf(bios_settings_buffer,
+					buf_alloc_size, "%s]\n",
+					bios_settings_buffer);
+	mutex_unlock(&bioscfg_drv.mutex);
+
+	return bios_settings_size;
+}
+
+int hp_bios_settings_free_buffer(void)
+{
+	mutex_lock(&bioscfg_drv.mutex);
+	kfree(bios_settings_buffer);
+	bios_settings_size = 0;
+	buf_alloc_size = 0;
+	mutex_unlock(&bioscfg_drv.mutex);
+
+	return 0;
+}
+int hp_bios_settings_realloc_buffer(char **buf, int *buf_size, int *alloc_size)
+{
+	int new_buffer_size;
+	char *new_buf = NULL;
+	int ret = 0;
+
+	if (*buf_size + PAGE_SIZE >= *alloc_size) {
+		new_buffer_size = buf_alloc_size + 2 * PAGE_SIZE;
+
+		mutex_lock(&bioscfg_drv.mutex);
+		new_buf = krealloc(*buf, new_buffer_size, GFP_KERNEL);
+		mutex_unlock(&bioscfg_drv.mutex);
+		if (new_buf) {
+			mutex_lock(&bioscfg_drv.mutex);
+			*buf = new_buf;
+			*alloc_size = ksize(new_buf);
+			mutex_unlock(&bioscfg_drv.mutex);
+		} else {
+			hp_bios_settings_free_buffer();
+			ret = -ENOMEM;
+		}
+	}
+
+	return ret;
+}
+
+int append_read_settings(enum hp_wmi_data_type type, char **buf,
+			 int *buf_size, int *alloc_size)
+{
+	int ret = 0;
+	int status = 0;
+	int instance = 0;
+	int instance_count = 0;
+
+	switch (type) {
+	case HPWMI_STRING_TYPE:
+		instance_count = bioscfg_drv.string_instances_count;
+		break;
+	case HPWMI_INTEGER_TYPE:
+		instance_count = bioscfg_drv.integer_instances_count;
+		break;
+	case HPWMI_ENUMERATION_TYPE:
+		instance_count = bioscfg_drv.enumeration_instances_count;
+		break;
+	case HPWMI_ORDERED_LIST_TYPE:
+		instance_count = bioscfg_drv.ordered_list_instances_count;
+		break;
+	case HPWMI_PASSWORD_TYPE:
+		instance_count = bioscfg_drv.password_instances_count;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*
+	 * Query all the instances
+	 */
+	for (instance = 0; instance < instance_count; instance++) {
+		mutex_lock(&bioscfg_drv.mutex);
+		status = append_read_attributes(buf, *alloc_size,
+						     instance, type);
+		if (status > 0)
+			*buf_size = status;
+
+		mutex_unlock(&bioscfg_drv.mutex);
+
+		ret = hp_bios_settings_realloc_buffer(buf, buf_size,
+						      alloc_size);
+	}
+	return ret;
+}
+
+int append_read_attributes(char **buf, int alloc_size,
+			   int instance, enum hp_wmi_data_type type)
+{
+	int status = 0;
+
+	switch (type) {
+	case HPWMI_STRING_TYPE:
+		status = append_read_string_attributes(*buf, alloc_size,
+						       instance, type);
+		break;
+	case HPWMI_INTEGER_TYPE:
+		status = append_read_integer_attributes(*buf, alloc_size,
+							instance, type);
+		break;
+	case HPWMI_ENUMERATION_TYPE:
+		status = append_read_enumeration_attributes(*buf,
+							    alloc_size,
+							    instance, type);
+		break;
+	case HPWMI_ORDERED_LIST_TYPE:
+		status = append_read_ordered_list_attributes(*buf,
+							     alloc_size,
+							     instance, type);
+		break;
+	case HPWMI_PASSWORD_TYPE:
+		status = append_read_password_attributes(*buf,
+							 alloc_size,
+							 instance, type);
+		break;
+	default:
+		status = -EINVAL;
+		break;
+	}
+	return status;
+}
+
+
+int append_read_string_attributes(char *buf, int alloc_size,
+				  int instance,
+				  enum hp_wmi_data_type type)
+{
+	int buf_size;
+	char *part_tmp = NULL;
+	char *part = NULL;
+
+	if (type >= ARRAY_SIZE(hp_wmi_classes) || !buf)
+		return -EINVAL;
+
+	buf_size = snprintf(buf, alloc_size, "%s{\n", buf);
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Class\": \"%s\",\n",
+			    buf, hp_wmi_classes[type]);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Name\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].display_name);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Value\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].current_value);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Path\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].path);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsReadOnly\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].is_readonly);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"DisplayInUI\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].display_in_ui);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"RequiresPhysicalPresence\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].requires_physical_presence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Sequence\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].sequence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"PrerequisiteSize\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].prerequisitesize);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Prerequisites\": [\n", buf);
+
+	if (bioscfg_drv.string_data[instance].prerequisitesize) {
+		part_tmp = kstrdup(bioscfg_drv.string_data[instance].prerequisites,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"SecurityLevel\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].security_level);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"MinLength\": %d,\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].min_length);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"MaxLength\": %d\n",
+			    buf,
+			    bioscfg_drv.string_data[instance].max_length);
+
+	return snprintf(buf, alloc_size, "%s},\n", buf);
+}
+
+
+int append_read_integer_attributes(char *buf, int alloc_size,
+				   int instance,
+				   enum hp_wmi_data_type type)
+{
+	int buf_size;
+	char *part_tmp = NULL;
+	char *part = NULL;
+
+	if (type >= ARRAY_SIZE(hp_wmi_classes) || !buf)
+		return -EINVAL;
+
+	buf_size = snprintf(buf, alloc_size, "%s{\n", buf);
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Class\": \"%s\",\n",
+			    buf, hp_wmi_classes[type]);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Name\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].display_name);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Value\": \"%d\",\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].current_value);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Path\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].path);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsReadOnly\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].is_readonly);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"DisplayInUI\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].display_in_ui);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"RequiresPhysicalPresence\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].requires_physical_presence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Sequence\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].sequence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"PrerequisiteSize\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].prerequisitesize);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Prerequisites\": [\n", buf);
+
+	if (bioscfg_drv.integer_data[instance].prerequisitesize) {
+		part_tmp = kstrdup(bioscfg_drv.integer_data[instance].prerequisites,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"SecurityLevel\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].security_level);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"LowerBound\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].lower_bound);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"UpperBound\": %d,\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].upper_bound);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IntValue\": %d\n",
+			    buf,
+			    bioscfg_drv.integer_data[instance].scalar_increment);
+
+	return snprintf(buf, alloc_size, "%s},\n", buf);
+}
+
+int append_read_enumeration_attributes(char *buf, int alloc_size,
+				       int instance,
+				       enum hp_wmi_data_type type)
+{
+	int buf_size;
+	char *part_tmp = NULL;
+	char *part = NULL;
+
+	if (type >= ARRAY_SIZE(hp_wmi_classes) || !buf)
+		return -EINVAL;
+
+	buf_size = snprintf(buf, alloc_size, "%s{\n", buf);
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Class\": \"%s\",\n",
+			    buf, hp_wmi_classes[type]);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Name\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].display_name);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Path\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].path);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsReadOnly\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].is_readonly);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"DisplayInUI\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].display_in_ui);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"RequiresPhysicalPresence\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].requires_physical_presence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Sequence\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].sequence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"PrerequisiteSize\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].prerequisitesize);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Prerequisites\": [\n", buf);
+
+	if (bioscfg_drv.enumeration_data[instance].prerequisitesize) {
+		part_tmp = kstrdup(bioscfg_drv.enumeration_data[instance].prerequisites,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"SecurityLevel\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].security_level);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Value\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].current_value);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Size\": %d,\n",
+			    buf,
+			    bioscfg_drv.enumeration_data[instance].size);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"PossibleValues\": [\n", buf);
+
+	if (bioscfg_drv.enumeration_data[instance].size) {
+		part_tmp = kstrdup(bioscfg_drv.enumeration_data[instance].possible_values,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t]\n", buf);
+
+	return snprintf(buf, alloc_size, "%s},\n", buf);
+}
+
+int append_read_ordered_list_attributes(char *buf, int alloc_size,
+					int instance,
+					enum hp_wmi_data_type type)
+{
+	int buf_size;
+	char *part_tmp = NULL;
+	char *part = NULL;
+
+	if (type >= ARRAY_SIZE(hp_wmi_classes) || !buf)
+		return -EINVAL;
+
+	buf_size = snprintf(buf, alloc_size, "%s{\n", buf);
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Class\": \"%s\",\n",
+			    buf, hp_wmi_classes[type]);
+
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Name\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].display_name);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Value\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].current_value);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Path\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].path);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsReadOnly\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].is_readonly);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"DisplayInUI\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].display_in_ui);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"RequiresPhysicalPresence\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].requires_physical_presence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Sequence\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].sequence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"PrerequisiteSize\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].prerequisitesize);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Prerequisites\": [\n", buf);
+
+	if (bioscfg_drv.ordered_list_data[instance].prerequisitesize) {
+		part_tmp = kstrdup(bioscfg_drv.ordered_list_data[instance].prerequisites,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"SecurityLevel\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].security_level);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Size\": %d,\n",
+			    buf,
+			    bioscfg_drv.ordered_list_data[instance].size);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Elements\": [\n", buf);
+
+	if (bioscfg_drv.ordered_list_data[instance].size) {
+		part_tmp = kstrdup(bioscfg_drv.ordered_list_data[instance].elements,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t]\n", buf);
+
+	return snprintf(buf, alloc_size, "%s},\n", buf);
+}
+
+
+int append_read_password_attributes(char *buf, int alloc_size,
+				    int instance,
+				    enum hp_wmi_data_type type)
+{
+	int buf_size;
+	char *part_tmp = NULL;
+	char *part = NULL;
+
+	if (type >= ARRAY_SIZE(hp_wmi_classes) || !buf)
+		return -EINVAL;
+
+	buf_size = snprintf(buf, alloc_size, "%s{\n", buf);
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Class\": \"%s\",\n",
+			    buf, hp_wmi_classes[type]);
+
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Name\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].display_name);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Value\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].current_password);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Path\": \"%s\",\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].path);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsReadOnly\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].is_readonly);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"DisplayInUI\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].display_in_ui);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"RequiresPhysicalPresence\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].requires_physical_presence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Sequence\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].sequence);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"PrerequisiteSize\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].prerequisitesize);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"Prerequisites\": [\n", buf);
+
+	if (bioscfg_drv.password_data[instance].prerequisitesize) {
+		part_tmp = kstrdup(bioscfg_drv.password_data[instance].prerequisites,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"SecurityLevel\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].security_level);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"MinLength\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].min_password_length);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"MaxLength\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].max_password_length);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"Size\": %d,\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].encoding_size);
+
+	buf_size = snprintf(buf, alloc_size, "%s\t\"SupportedEncoding\": [\n", buf);
+
+	if (bioscfg_drv.password_data[instance].encoding_size) {
+		part_tmp = kstrdup(bioscfg_drv.password_data[instance].supported_encoding,
+				   GFP_KERNEL);
+		part = strsep(&part_tmp, ";");
+		while (part) {
+			buf_size = snprintf(buf, alloc_size, "%s\t\t\"%s\"", buf, part);
+			part = strsep(&part_tmp, ";");
+			if (part)
+				buf_size = snprintf(buf, alloc_size, "%s,\n", buf);
+			else
+				buf_size = snprintf(buf, alloc_size, "%s\n", buf);
+		}
+		kfree(part_tmp);
+		part_tmp = NULL;
+	}
+	buf_size = snprintf(buf, alloc_size, "%s\t],\n", buf);
+
+	buf_size = snprintf(buf, alloc_size,
+			    "%s\t\"IsSet\": %d\n",
+			    buf,
+			    bioscfg_drv.password_data[instance].is_enabled);
+
+	return snprintf(buf, alloc_size, "%s},\n", buf);
+}
drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.34.1
#21 lore raw

PATCH v4 6/6 HP BIOSCFG driver - remaining components

In reply to Jorge Lopez

The purpose for this patch is to submit the remaining components to build hp-bioscfg driver, Kconfig ,and documentation describing new attributes and extensions provided by the driver. This documentation is found at Documentation/.../sysfs-class-firmware-attributes file.

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

---
 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |   11 +-
 drivers/platform/x86/hp/Kconfig               |   16 +
 drivers/platform/x86/hp/Makefile              |    3 +-
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1064 +++++++++++++++++
 6 files changed, 1288 insertions(+), 6 deletions(-)
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile
 create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
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 +8 -3
index 48f6705c19f8..9ad23364ae69 100644
@@ -120,7 +120,7 @@ Descriptions of section entries and preferred order
 	   matches all files in and below net excluding net/ipv6/
 	N: Files and directories *Regex* patterns.
 	   N:	[^a-z]tegra	all files whose path contains tegra
-	                        (not including files like integrator)
+				(not including files like integrator)
 	   One pattern per line.  Multiple N: lines acceptable.
 	   scripts/get_maintainer.pl has different behavior for files that
 	   match F: pattern and matches of N: patterns.  By default,
@@ -140,8 +140,8 @@ Maintainers List
 ----------------
 
 .. note:: When reading this list, please look for the most precise areas
-          first. When adding to this list, please keep the entries in
-          alphabetical order.
+	  first. When adding to this list, please keep the entries in
+	  alphabetical order.
 
 3C59X NETWORK DRIVER
 M:	Steffen Klassert <[email protected]>
@@ -9286,6 +9286,11 @@ 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
+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 426e3575ddc3..af053370ab2b 100644
@@ -61,5 +61,21 @@ 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
+	depends on DMI
+	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 +2 -1
index f651a405e876..6257b2846660 100644
@@ -1,10 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
 #
 # Makefile for linux/drivers/platform/x86/hp
-# x86 Platform-Specific Drivers
+# HP x86 Platform-Specific Drivers
 #
 
 # Hewlett Packard
 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..e3790e223084
@@ -0,0 +1,19 @@
+obj-m           := 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
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c new file +1064 -0

1,064 lines not on this page · raw message

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

Hi Jorge,

Quoted 7 lines · Jorge Lopez

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

Version 4.0 breaks down the changes as follows:

1. Moving existing HP drivers to a central location

I have merged this patch, so you can drop this for version 5 of the patchset.

Quoted 4 lines

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

2. Introduction of HP-BIOSCFG driver - Set 1

I've done a detailed review of this single patches. This has found quite a few things to improve. Note that many of the remarks and especially the remarks about enum-attributes.c also apply to the other files (to the other *-attributes.c files).

Please prepare a version 5 taking all remarks into account for all files of the driver and then I will continue the review from there.

One thing which I did already notice for the last patch in the series, please drop the "depends on DMI" from the Kconfig bits and drop "include/dmi.h", you are not using any DMI functions so these are not necessary.

And please add a:

L: [email protected]

line to the MAINTAINERS entry.

Regards,

Hans

Quoted 61 lines

3. HP BIOSCFG driver - set 2
4. HP BIOSCFG driver - set 3
5. HP BIOSCFG driver - set 4
6. HP BIOSCFG driver - remaining components

--

Jorge Lopez (6):
Moving existing HP drivers to a central location Introduction of HP-BIOSCFG driver
HP BIOSCFG driver - set 2
HP BIOSCFG driver - set 3
HP BIOSCFG driver - set 4
HP BIOSCFG driver - remaining components

 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |   15 +-
 drivers/platform/x86/Kconfig                  |   80 +-
 drivers/platform/x86/Makefile                 |    4 +-
 drivers/platform/x86/hp/Kconfig               |   81 ++
 drivers/platform/x86/hp/Makefile              |   11 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  285 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1064 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  671 +++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       |  521 ++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        |  478 ++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    |  586 +++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |   50 +
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  |  647 ++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     |  408 +++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     |  457 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 ++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  145 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c        |    0
 drivers/platform/x86/{ => hp}/hp_accel.c      |    0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c    |    0
 22 files changed, 6647 insertions(+), 70 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 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
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)

--
2.34.1

#23 lore raw

Ok, I will do that.

Quoted 111 lines · Hans de Goede

Hi Jorge,

Quoted 7 lines · Jorge Lopez

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

Version 4.0 breaks down the changes as follows:

1. Moving existing HP drivers to a central location

I have merged this patch, so you can drop this for version 5 of the patchset.

Quoted 4 lines

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

2. Introduction of HP-BIOSCFG driver - Set 1

I've done a detailed review of this single patches. This has found quite a few things to improve. Note that many of the remarks and especially the remarks about enum-attributes.c also apply to the other files (to the other *-attributes.c files).

Please prepare a version 5 taking all remarks into account for all files of the driver and then I will continue the review from there.

One thing which I did already notice for the last patch in the series, please drop the "depends on DMI" from the Kconfig bits and drop "include/dmi.h", you are not using any DMI functions so these are not necessary.

And please add a:

L: [email protected]

line to the MAINTAINERS entry.

Regards,

Hans

Quoted 61 lines

3. HP BIOSCFG driver - set 2
4. HP BIOSCFG driver - set 3
5. HP BIOSCFG driver - set 4
6. HP BIOSCFG driver - remaining components

--

Jorge Lopez (6):
Moving existing HP drivers to a central location Introduction of HP-BIOSCFG driver
HP BIOSCFG driver - set 2
HP BIOSCFG driver - set 3
HP BIOSCFG driver - set 4
HP BIOSCFG driver - remaining components

 .../testing/sysfs-class-firmware-attributes   |  181 ++-
 MAINTAINERS                                   |   15 +-
 drivers/platform/x86/Kconfig                  |   80 +-
 drivers/platform/x86/Makefile                 |    4 +-
 drivers/platform/x86/hp/Kconfig               |   81 ++
 drivers/platform/x86/hp/Makefile              |   11 +
 drivers/platform/x86/hp/hp-bioscfg/Makefile   |   19 +
 .../x86/hp/hp-bioscfg/biosattr-interface.c    |  285 +++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c  | 1064 +++++++++++++++++
 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h  |  671 +++++++++++
 .../x86/hp/hp-bioscfg/enum-attributes.c       |  521 ++++++++
 .../x86/hp/hp-bioscfg/int-attributes.c        |  478 ++++++++
 .../x86/hp/hp-bioscfg/ordered-attributes.c    |  586 +++++++++
 .../x86/hp/hp-bioscfg/passwdattr-interface.c  |   50 +
 .../x86/hp/hp-bioscfg/passwdobj-attributes.c  |  647 ++++++++++
 .../x86/hp/hp-bioscfg/spmobj-attributes.c     |  408 +++++++
 .../x86/hp/hp-bioscfg/string-attributes.c     |  457 +++++++
 .../x86/hp/hp-bioscfg/sureadmin-attributes.c  | 1014 ++++++++++++++++
 .../x86/hp/hp-bioscfg/surestart-attributes.c  |  145 +++
 drivers/platform/x86/{ => hp}/hp-wmi.c        |    0
 drivers/platform/x86/{ => hp}/hp_accel.c      |    0
 drivers/platform/x86/{ => hp}/tc1100-wmi.c    |    0
 22 files changed, 6647 insertions(+), 70 deletions(-)
 create mode 100644 drivers/platform/x86/hp/Kconfig
 create mode 100644 drivers/platform/x86/hp/Makefile
 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
 rename drivers/platform/x86/{ => hp}/hp-wmi.c (100%)
 rename drivers/platform/x86/{ => hp}/hp_accel.c (100%)
 rename drivers/platform/x86/{ => hp}/tc1100-wmi.c (100%)

--
2.34.1