From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D58C7EE29 for ; Fri, 2 Jun 2023 13:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235974AbjFBNKw (ORCPT ); Fri, 2 Jun 2023 09:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235883AbjFBNKt (ORCPT ); Fri, 2 Jun 2023 09:10:49 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058321AB; Fri, 2 Jun 2023 06:10:48 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-390723f815fso1312617b6e.3; Fri, 02 Jun 2023 06:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711447; x=1688303447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=j7Y0i4GvrbFVwsVHtX/Gx93Fyr8XKJyIAD1SuH1o0io=; b=Y0DWvAS9APfaoImZKrp1rJXklhYsAAiAAPHjUK4GDniRPFBRbrjc2U1ATVNZrj1LDN NG6sD+FP4N/bubyJ0K648zT25k1uDEorurgFY/eVSAhpEssLJvyHHiULsodgJ+TEiDAS jU6kMSpbWIcRwoDsirFAP1a4CrRNQp03RaSCdTjXumPgjEgRCzWjFWFUyEOfbnohzASo zYRN9VsLwpOe3cYWgCHuNtKsOKRutY5N7stkbMia6lC8wJ2UOaQnVVXH+2bpAQVbYNrx DEVTPi9EM0yZerjash5UdsQEfwgCQq/kTbCIb6ITayfqS8zwbAQp8YyizAGTcfK4gBOc vnmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711447; x=1688303447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j7Y0i4GvrbFVwsVHtX/Gx93Fyr8XKJyIAD1SuH1o0io=; b=Pd7SNu66Pk+RSpbwSK2ivECOJeGTrpRAVimr8+A/GVCKUCHuFN2gHBpmLXPSA4dDov be+zb8Kt3wn5b6354Rr8agXEDk2eJg7e4ZH9B4hlFAjsE24MAdK2kOayYoIW+vYIyWqB H6mYcNjgW/feGTKQo2HbICUBY1yCOxX24LhmNv3lu+MTM7/sB9fW9ZeMY+1qcMXQKqLR RdABkIOJwKQb4IbQl8gNhwr7jU1KN/tKQ/dOlwuZs+KffFdwusT2gw9iWclsICPk5kmu X87JIDPQ7oPW46lzZBeddHHWwZjL9gvQBMt19pxQj74v4YhfUJz0dA7ZRY8IpNBUDySa TkTQ== X-Gm-Message-State: AC+VfDx23VZ/pYHeq31jpOt6MDo+NkdGTFjLnf8Orpw9dGgOE/gAT4tA N1K7cn5jf3xteJjj6nj4aiQ= X-Google-Smtp-Source: ACHHUZ4gaJMtdrpxFrWMzvQxr7UeXxGyNrR3oBDU3FujBqFeFpVlFyDOZzTcT+cLOEh96DeGmP9Ysg== X-Received: by 2002:a05:6808:293:b0:397:fb60:4d51 with SMTP id z19-20020a056808029300b00397fb604d51mr1929103oic.39.1685711447195; Fri, 02 Jun 2023 06:10:47 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:46 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 01/13] hp-bioscfg: Documentation Date: Fri, 2 Jun 2023 08:10:32 -0500 Message-Id: <20230602131044.3297-2-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../testing/sysfs-class-firmware-attributes | 101 +++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-firmware-attributes b/Do= cumentation/ABI/testing/sysfs-class-firmware-attributes index 4cdba3477176..df9904b9f39c 100644 --- a/Documentation/ABI/testing/sysfs-class-firmware-attributes +++ b/Documentation/ABI/testing/sysfs-class-firmware-attributes @@ -22,6 +22,11 @@ Description: - integer: a range of numerical values - string =20 + HP specific types + ----------------- + - ordered-list - a set of ordered list valid values + + All attribute types support the following values: =20 current_value: @@ -126,6 +131,21 @@ Description: value will not be effective through sysfs until this rule is met. =20 + 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 . Values are separated using + semi-colon (``;``) and listed according to their priority. + An element listed first has the highest priority. Writing + the list in a different order to current_value alters + the priority order for the particular attribute. + What: /sys/class/firmware-attributes/*/authentication/ Date: February 2021 KernelVersion: 5.11 @@ -206,7 +226,7 @@ Description: Drivers may emit a CHANGE uevent when a password is set or unset userspace may check it again. =20 - On Dell and Lenovo systems, if Admin password is set, then all BIOS attr= ibutes + 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 n= ot active until the next boot. @@ -296,6 +316,15 @@ Description: echo "signature" > authentication/Admin/signature echo "password" > authentication/Admin/certificate_to_password =20 + 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). + =20 What: /sys/class/firmware-attributes/*/attributes/pending_reboot Date: February 2021 @@ -311,7 +340,7 @@ Description: =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 0 All BIOS attributes setting are current 1 A reboot is necessary to get pending BIOS - attribute changes applied + attribute changes applied =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Note, userspace applications need to follow below steps for efficient @@ -364,3 +393,71 @@ Description: use it to enable extra debug attributes or BIOS features for testing pur= poses. =20 Note that any changes to this attribute requires a reboot for changes to= take effect. + + + HP specific class extensions - Secure Platform Manager (SPM) + -------------------------------- + +What: /sys/class/firmware-attributes/*/authentication/SPM/kek +Date: March 2023 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: + 'kek' Key-Encryption-Key is a write-only file that can be used to config= ure 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 2023 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: + 'sk' Signature Key is a write-only file that can be used to configure th= e 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 2023 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: + 'status' is a read-only file that returns ASCII text in JSON format repo= rting + the status information. + + "State": "not provisioned | provisioned | provisioning in progress ", + "Version": " Major. Minor ", + "Nonce": <16-bit unsigned number display in base 10>, + "FeaturesInUse": <16-bit unsigned number display in base 10>, + "EndorsementKeyMod": "<256 bytes in base64>", + "SigningKeyMod": "<256 bytes in base64>" + +What: /sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_en= tries +Date: March 2023 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: + 'audit_log_entries' is a read-only file that returns the events in the l= og. + + Audit log entry format + + Byte 0-15: Requested Audit Log entry (Each Audit log is 16 bytes) + Byte 16-127: Unused + +What: /sys/class/firmware-attributes/*/attributes/Sure_Start/audit_log_en= try_count +Date: March 2023 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: + 'audit_log_entry_count' is a read-only file that returns the number of e= xisting + audit log events available to be read. Values are separated using comma = (``,``) + + [No of entries],[log entry size],[Max number of entries supported] + + log entry size identifies audit log size for the current BIOS version. + The current size is 16 bytes but it can be up to 128 bytes long in futur= e BIOS + versions. --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E749C7EE2C for ; Fri, 2 Jun 2023 13:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235989AbjFBNK4 (ORCPT ); Fri, 2 Jun 2023 09:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235962AbjFBNKv (ORCPT ); Fri, 2 Jun 2023 09:10:51 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A7381B3; Fri, 2 Jun 2023 06:10:49 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-39a55e706deso891232b6e.3; Fri, 02 Jun 2023 06:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711449; x=1688303449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=duuyoJ/GEXEUqSIwJW306JhE5pk504xLhQOMnERAeoE=; b=ejFqwyd3fRI7sfiuC/6fnGnh3HKvO7xg8D6j6w66tbLhIRmbcm35b6EkRqIupzNa4G OHB/BT+CCQpPLHlPt4mlYqGsDfGDscCXE5XQbxuWJHGW1/JaVSGHh9WLr8ndkoCbaLTT OX4pHvB5BrAMyyV2IQwtAdhoPvWFS0Hc/xm77nTMtvYsuPa8DFHWp+NnCvMMt2mJJVbo C3wVsH1xb7xqeOQ/CtXdUhF3wZRBM17261+dp8Kt4JLFsx1BMHJ8uFRU8KigcWLKCR5n mCRywBt2YYa3yd0VrWOquc9uIRTtSX5m4wzav4w3QvyejH66VfIj3WeKwE4M63IFqGHd ED2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711449; x=1688303449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=duuyoJ/GEXEUqSIwJW306JhE5pk504xLhQOMnERAeoE=; b=cQcYQnpRnNq8IvgzlOJsdFX45uXnwBwNoo9RP+AhZJYTYNxe/poImvXdoAy7IfA6TA j8OcmQjeUmTWuGPg6X0pS2V0rC891XB1y3SpNmG1awDe8WpwYk7DvDConvQihwYTKpKp +2wLvd9LXL0sA3rRzNoyVsH2d0rOk6MscEjJ4hyhScEga98ZTc9sM/i/FxOnBD1ui/Ex NdkWPFCElXTvMTD2/8NdwwjgA5u7UKLwgjoeNu9hLL/KLl0ZdnVjLZVNvWqdwu+q3Bxr h0YR2aaLuqIlKLhZ36LBLI1PAp9xGfJtRZyHPKGQMgpLyNRhpmv+++9LB/UDeNk4dnv3 Mtug== X-Gm-Message-State: AC+VfDxELtbjc7N39z4Fhjt3WZb7fsa62Jrj07Fi7e4GvR+8+ClujZFC 094N8k9JyxA+hiyplKFUVsgmJeh6xvk= X-Google-Smtp-Source: ACHHUZ5A4DFni5aRJ/K93n6H77ZRIRVGn089XW3wNnIJ1uT4UWmz7dP03KHPBqKsERdPweeXc74L8w== X-Received: by 2002:aca:f18:0:b0:389:4f86:205e with SMTP id 24-20020aca0f18000000b003894f86205emr1407161oip.9.1685711448572; Fri, 02 Jun 2023 06:10:48 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:48 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 02/13] hp-bioscfg: bioscfg-h Date: Fri, 2 Jun 2023 08:10:33 -0500 Message-Id: <20230602131044.3297-3-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp/hp-bioscfg/bioscfg.h | 486 +++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.h diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.h b/drivers/platfor= m/x86/hp/hp-bioscfg/bioscfg.h new file mode 100644 index 000000000000..0ce0b749806d --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.h @@ -0,0 +1,486 @@ +/* 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 +#include +#include +#include +#include +#include + +#define DRIVER_NAME "hp-bioscfg" + +#define MAX_BUFF_SIZE 512 +#define MAX_KEY_MOD_SIZE 256 +#define MAX_PASSWD_SIZE 64 +#define MAX_PREREQUISITES_SIZE 20 +#define MAX_REQ_ELEM_SIZE 128 +#define MAX_VALUES_SIZE 16 +#define MAX_ENCODINGS_SIZE 16 +#define MAX_ELEMENTS_SIZE 16 + +#define SPM_STR_DESC "Secure Platform Management" +#define SPM_STR "SPM" +#define SURE_START_DESC "Sure Start" +#define SURE_START_STR "Sure_Start" +#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" + +#define COMMA_SEP "," +#define SEMICOLON_SEP ";" + +/* Sure Admin Functions */ + +#define UTF_PREFIX "" +#define BEAM_PREFIX "" + +enum mechanism_values { + PASSWORD =3D 0x00, + SIGNING_KEY =3D 0x01, + ENDORSEMENT_KEY =3D 0x02, +}; + +#define BIOS_ADMIN "bios-admin" +#define POWER_ON "power-on" +#define BIOS_SPM "enhanced-bios-auth" + +#define PASSWD_MECHANISM_TYPES "password" + +#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-7045CB4DA74= 5" +#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 =3D 0x10, + HPWMI_SECUREPLATFORM_SET_KEK =3D 0x11, + HPWMI_SECUREPLATFORM_SET_SK =3D 0x12, +}; + +enum hp_wmi_surestart_commandtype { + HPWMI_SURESTART_GET_LOG_COUNT =3D 0x01, + HPWMI_SURESTART_GET_LOG =3D 0x02, +}; + +enum hp_wmi_command { + HPWMI_READ =3D 0x01, + HPWMI_WRITE =3D 0x02, + HPWMI_ODM =3D 0x03, + HPWMI_SURESTART =3D 0x20006, + HPWMI_GM =3D 0x20008, + HPWMI_SECUREPLATFORM =3D 0x20010, +}; + +struct bios_return { + u32 sigpass; + u32 return_code; +}; + +enum wmi_error_values { + SUCCESS =3D 0x00, + CMD_FAILED =3D 0x01, + INVALID_SIGN =3D 0x02, + INVALID_CMD_VALUE =3D 0x03, + INVALID_CMD_TYPE =3D 0x04, + INVALID_DATA_SIZE =3D 0x05, + INVALID_CMD_PARAM =3D 0x06, + ENCRYP_CMD_REQUIRED =3D 0x07, + NO_SECURE_SESSION =3D 0x08, + SECURE_SESSION_FOUND =3D 0x09, + SECURE_SESSION_FAILED =3D 0x0A, + AUTH_FAILED =3D 0x0B, + INVALID_BIOS_AUTH =3D 0x0E, + NONCE_DID_NOT_MATCH =3D 0x18, + GENERIC_ERROR =3D 0x1C, + BIOS_ADMIN_POLICY_NOT_MET =3D 0x28, + BIOS_ADMIN_NOT_SET =3D 0x38, + P21_NO_PROVISIONED =3D 0x1000, + P21_PROVISION_IN_PROGRESS =3D 0x1001, + P21_IN_USE =3D 0x1002, + HEP_NOT_ACTIVE =3D 0x1004, + HEP_ALREADY_SET =3D 0x1006, + HEP_CHECK_STATE =3D 0x1007, +}; + +struct common_data { + u8 display_name[MAX_BUFF_SIZE]; + u8 path[MAX_BUFF_SIZE]; + u32 is_readonly; + u32 display_in_ui; + u32 requires_physical_presence; + u32 sequence; + u32 prerequisites_size; + u8 prerequisites[MAX_PREREQUISITES_SIZE][MAX_BUFF_SIZE]; + u32 security_level; +}; + +struct string_data { + struct common_data common; + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF_SIZE]; + u8 new_value[MAX_BUFF_SIZE]; + u32 min_length; + u32 max_length; +}; + +struct integer_data { + struct common_data common; + struct kobject *attr_name_kobj; + u32 current_value; + u32 new_value; + u32 lower_bound; + u32 upper_bound; + u32 scalar_increment; +}; + +struct enumeration_data { + struct common_data common; + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF_SIZE]; + u8 new_value[MAX_BUFF_SIZE]; + u32 possible_values_size; + u8 possible_values[MAX_VALUES_SIZE][MAX_BUFF_SIZE]; +}; + +struct ordered_list_data { + struct common_data common; + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF_SIZE]; + u8 new_value[MAX_BUFF_SIZE]; + u32 elements_size; + u8 elements[MAX_ELEMENTS_SIZE][MAX_BUFF_SIZE]; +}; + +struct password_data { + struct common_data common; + struct kobject *attr_name_kobj; + u8 current_password[MAX_PASSWD_SIZE]; + u8 new_password[MAX_PASSWD_SIZE]; + u32 min_password_length; + u32 max_password_length; + u32 encodings_size; + u8 encodings[MAX_ENCODINGS_SIZE][MAX_BUFF_SIZE]; + bool is_enabled; + + /* + * 'role' identifies the type of authentication. + * Two known types are bios-admin and power-on. + * 'bios-admin' represents BIOS administrator password + * 'power-on' represents a password required to use the system + */ + u32 role; + + /* + * 'mechanism' represents the means of authentication. + * Only supported type currently is "password" + */ + u32 mechanism; +}; + +struct secure_platform_data { + struct kobject *attr_name_kobj; + u8 attribute_name[MAX_BUFF_SIZE]; + u8 *endorsement_key; + u8 *signing_key; + u8 *auth_token; + bool is_enabled; + u32 mechanism; +}; + +struct bioscfg_priv { + 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 secure_platform_data spm_data; + u8 display_name_language_code[MAX_BUFF_SIZE]; + 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, + HPWMI_INTEGER_TYPE, + HPWMI_ENUMERATION_TYPE, + HPWMI_ORDERED_LIST_TYPE, + HPWMI_PASSWORD_TYPE, + HPWMI_SECURE_PLATFORM_TYPE, + HPWMI_SURE_START_TYPE, +}; + +enum hp_wmi_data_elements { + /* Common elements */ + NAME =3D 0, + VALUE =3D 1, + PATH =3D 2, + IS_READONLY =3D 3, + DISPLAY_IN_UI =3D 4, + REQUIRES_PHYSICAL_PRESENCE =3D 5, + SEQUENCE =3D 6, + PREREQUISITES_SIZE =3D 7, + PREREQUISITES =3D 8, + SECURITY_LEVEL =3D 9, + + /* String elements */ + STR_MIN_LENGTH =3D 10, + STR_MAX_LENGTH =3D 11, + STR_ELEM_CNT =3D 12, + + /* Integer elements */ + INT_LOWER_BOUND =3D 10, + INT_UPPER_BOUND =3D 11, + INT_SCALAR_INCREMENT =3D 12, + INT_ELEM_CNT =3D 13, + + /* Enumeration elements */ + ENUM_CURRENT_VALUE =3D 10, + ENUM_SIZE =3D 11, + ENUM_POSSIBLE_VALUES =3D 12, + ENUM_ELEM_CNT =3D 13, + + /* Ordered list elements */ + ORD_LIST_SIZE =3D 10, + ORD_LIST_ELEMENTS =3D 11, + ORD_ELEM_CNT =3D 12, + + /* Password elements */ + PSWD_MIN_LENGTH =3D 10, + PSWD_MAX_LENGTH =3D 11, + PSWD_SIZE =3D 12, + PSWD_ENCODINGS =3D 13, + PSWD_IS_SET =3D 14, + PSWD_ELEM_CNT =3D 15, +}; + +#define GET_INSTANCE_ID(type) \ + static int get_##type##_instance_id(struct kobject *kobj) \ + { \ + int i; \ + \ + for (i =3D 0; i <=3D bioscfg_drv.type##_instances_count; i++) { \ + if (!strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name= )) \ + return i; \ + } \ + return -EIO; \ + } + +#define ATTRIBUTE_S_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *a= ttr, \ + char *buf) \ + { \ + int i =3D get_##type##_instance_id(kobj); \ + if (i >=3D 0) \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].name); \ + return -EIO; \ + } + +#define ATTRIBUTE_N_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *a= ttr, \ + char *buf) \ + { \ + int i =3D get_##type##_instance_id(kobj); \ + if (i >=3D 0) \ + return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].name); \ + return -EIO; \ + } + +#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) \ + { \ + char *attr_value =3D NULL; \ + int i; \ + int ret =3D -EIO; \ + \ + attr_value =3D kstrdup(buf, GFP_KERNEL); \ + if (!attr_value) \ + return -ENOMEM; \ + \ + ret =3D hp_enforce_single_line_input(attr_value, count); \ + if (!ret) { \ + i =3D get_##type##_instance_id(kobj); \ + if (i >=3D 0) \ + ret =3D validate_##type##_input(i, attr_value); \ + } \ + if (!ret) \ + ret =3D hp_set_attribute(kobj->name, attr_value); \ + if (!ret) { \ + update_##type##_value(i, attr_value); \ + if (bioscfg_drv.type##_data[i].common.requires_physical_presence) \ + hp_set_reboot_and_signal_event(); \ + } \ + hp_clear_all_credentials(); \ + 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 *a= ttr, char *buf) \ + { \ + return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data.name); \ + } + +#define ATTRIBUTE_SPM_S_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *a= ttr, char *buf) \ + { \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data.name); \ + } + +#define ATTRIBUTE_VALUES_PROPERTY_SHOW(name, type, sep) \ + static ssize_t name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + int i; \ + int len =3D 0; \ + int instance_id =3D get_##type##_instance_id(kobj); \ + \ + if (instance_id < 0) \ + return 0; \ + \ + for (i =3D 0; i < bioscfg_drv.type##_data[instance_id].name##_size; i++)= { \ + if (i) \ + len +=3D sysfs_emit_at(buf, len, "%s", sep); \ + \ + len +=3D sysfs_emit_at(buf, len, "%s", \ + bioscfg_drv.type##_data[instance_id].name[i]); \ + } \ + len +=3D sysfs_emit_at(buf, len, "\n"); \ + return len; \ + } + +#define ATTRIBUTE_S_COMMON_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *a= ttr, \ + char *buf) \ + { \ + int i =3D get_##type##_instance_id(kobj); \ + if (i >=3D 0) \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].common.name);= \ + return -EIO; \ + } + +extern struct kobj_attribute common_display_langcode; + +/* Prototypes */ + +/* String attributes */ +int hp_populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int hp_alloc_string_data(void); +void hp_exit_string_attributes(void); +int hp_populate_string_package_data(union acpi_object *str_obj, + int instance_id, + struct kobject *attr_name_kobj); + +/* Integer attributes */ +int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int hp_alloc_integer_data(void); +void hp_exit_integer_attributes(void); +int hp_populate_integer_package_data(union acpi_object *integer_obj, + int instance_id, + struct kobject *attr_name_kobj); + +/* Enumeration attributes */ +int hp_populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int hp_alloc_enumeration_data(void); +void hp_exit_enumeration_attributes(void); +int hp_populate_enumeration_package_data(union acpi_object *enum_obj, + int instance_id, + struct kobject *attr_name_kobj); + +/* Ordered list */ +int hp_populate_ordered_list_buffer_data(u8 *buffer_ptr, + u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int hp_alloc_ordered_list_data(void); +void hp_exit_ordered_list_attributes(void); +int hp_populate_ordered_list_package_data(union acpi_object *order_obj, + int instance_id, + struct kobject *attr_name_kobj); + +/* Password authentication attributes */ +int hp_populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int hp_populate_password_package_data(union acpi_object *password_obj, + int instance_id, + struct kobject *attr_name_kobj); +int hp_alloc_password_data(void); +int hp_get_password_instance_for_type(const char *name); +int hp_clear_all_credentials(void); +int hp_set_attribute(const char *a_name, const char *a_value); + +/* SPM attributes */ +void hp_exit_password_attributes(void); +void hp_exit_secure_platform_attributes(void); +int hp_populate_secure_platform_data(struct kobject *attr_name_kobj); +int hp_populate_security_buffer(u16 *buffer, const char *authentication); + +/* Bios Attributes interface */ +int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size); +int hp_wmi_perform_query(int query, enum hp_wmi_command command, + void *buffer, u32 insize, u32 outsize); + +/* Sure Start attributes */ +void hp_exit_sure_start_attributes(void); +int hp_populate_sure_start_data(struct kobject *attr_name_kobj); + +/* Bioscfg */ + +void hp_exit_attr_set_interface(void); +int hp_init_attr_set_interface(void); +size_t hp_calculate_string_buffer(const char *str); +size_t hp_calculate_security_buffer(const char *authentication); +void *hp_ascii_to_utf16_unicode(u16 *p, const u8 *str); +int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer= ); +int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u3= 2 dst_size); +int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str,= int *len); +int hp_encode_outsize_for_pvsz(int outsize); +int hp_enforce_single_line_input(char *buf, size_t count); +void hp_set_reboot_and_signal_event(void); +ssize_t display_name_language_code_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf); +union acpi_object *hp_get_wmiobj_pointer(int instance_id, const char *guid= _string); +int hp_get_instance_count(const char *guid_string); +void hp_update_attribute_permissions(bool isreadonly, struct kobj_attribut= e *current_val); +void hp_friendly_user_name_update(char *path, const char *attr_name, + char *attr_display, int attr_size); +int hp_wmi_error_and_message(int error_code); + +#endif --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57A8FC7EE2C for ; Fri, 2 Jun 2023 13:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235999AbjFBNK7 (ORCPT ); Fri, 2 Jun 2023 09:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235750AbjFBNKy (ORCPT ); Fri, 2 Jun 2023 09:10:54 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE2191AB; Fri, 2 Jun 2023 06:10:50 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-39a50fcc719so1449896b6e.2; Fri, 02 Jun 2023 06:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711450; x=1688303450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NvNZ77n4mYkbhZyOQ4VK2L2FaHp3S5YUT7w6DqhpR/g=; b=X+9PetXREG4KfIRNpSDzXe3k45x/zZN9zx7bRyCdaJmMUQbTu4Z4juowDtWPpsfhd2 V8gfm+Z2OxqNdC8vj/C8RXdl2HvG3xh+S+fE/tbI/9ULmRedsTKDTE4GGK/6iUI83FBd 00ECTWuaaTDdPqjrNP2vhY4CSX6P7IEWQy1Y3cpOKhM/shNzKzGOkzjiU6+hzCUtFdW6 P/5MBoIZZ6ynriC0QYGnhGWMzL+uOxUcV2nSp5JHJlNrue+PjIo3pDXSC03nNW+aN3ER +HCcyYu84qcx+HV0VtH25GbJfHHDnHCY5T5m3KpG4MTKV1RjDEYpbE/rnk/0SQeeBN/J Kfaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711450; x=1688303450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NvNZ77n4mYkbhZyOQ4VK2L2FaHp3S5YUT7w6DqhpR/g=; b=A4BfGixkGWZwf/r7xCfpDn1oxXHOwB5CBMT/uL0B3sMBMKC8HG/98Eaygx92G47pOw NQ5NCfCZ4oMJQz0npOVUaQYFW8XMHRCr25RfYaGlNdnkCphKTB8alcgePCQQbUQFqp0v Prqn+d8l9rSyeecpVwgQ0sLKBOdsA/V0XSl4PZyDWdNTwNu7dcSJVoHxhcoLcajbf8JA 48RIq+D0tXgObES0LxionOcRG3dXndpYfzNkUKfefO37Oi8khCBj/sqpVmMhZrhIWx96 yV4t/KE1lE+afGJpa0m224QmAvP3E78C4axIVDnYdyhYiW8L1O5aLEcVvxJihoQsANgm lQbA== X-Gm-Message-State: AC+VfDwWy+1cXikcHWUQcgIhfB2dGcwKnEiObKj9ywMPIv23xE/O+7bl qM621DNfYHrPpMxFJbVW7Nk= X-Google-Smtp-Source: ACHHUZ6yS8EfNZlz/318CUO403YWVLRi+reOSb4B4QLeJv7Rb0+bvgiPKIlL8UmZ06COv+IFNI732Q== X-Received: by 2002:aca:110e:0:b0:397:fe29:c526 with SMTP id 14-20020aca110e000000b00397fe29c526mr2551510oir.10.1685711449823; Fri, 02 Jun 2023 06:10:49 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:49 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 03/13] hp-bioscfg: bioscfg Date: Fri, 2 Jun 2023 08:10:34 -0500 Message-Id: <20230602131044.3297-4-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 986 +++++++++++++++++++ 1 file changed, 986 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platfor= m/x86/hp/hp-bioscfg/bioscfg.c new file mode 100644 index 000000000000..acebb8ae16a8 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c @@ -0,0 +1,986 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Common methods for use with hp-bioscfg driver + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include "bioscfg.h" +#include "../../firmware_attributes_class.h" +#include +#include + +MODULE_AUTHOR("Jorge Lopez "); +MODULE_DESCRIPTION("HP BIOS Configuration Driver"); +MODULE_LICENSE("GPL"); + +struct bioscfg_priv bioscfg_drv =3D { + .mutex =3D __MUTEX_INITIALIZER(bioscfg_drv.mutex), +}; + +static struct class *fw_attr_class; + +ssize_t display_name_language_code_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", LANG_CODE_STR); +} + +struct kobj_attribute common_display_langcode =3D + __ATTR_RO(display_name_language_code); + +int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer) +{ + int *ptr =3D PTR_ALIGN((int *)*buffer, sizeof(int)); + + /* Ensure there is enough space remaining to read the integer */ + if (*buffer_size < sizeof(int)) + return -EINVAL; + + *integer =3D *(ptr++); + *buffer =3D (u8 *)ptr; + *buffer_size -=3D sizeof(int); + + return 0; +} + +int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u3= 2 dst_size) +{ + u16 *src =3D (u16 *)*buffer; + u16 src_size; + + u16 size; + int i; + int conv_dst_size; + + if (*buffer_size < sizeof(u16)) + return -EINVAL; + + src_size =3D *(src++); + /* size value in u16 chars */ + size =3D src_size / sizeof(u16); + + /* Ensure there is enough space remaining to read and convert + * the string + */ + if (*buffer_size < src_size) + return -EINVAL; + + for (i =3D 0; i < size; i++) + if (src[i] =3D=3D '\\' || + src[i] =3D=3D '\r' || + src[i] =3D=3D '\n' || + src[i] =3D=3D '\t') + size++; + + /* + * Conversion is limited to destination string max number of + * bytes. + */ + conv_dst_size =3D size; + if (size > dst_size) + conv_dst_size =3D dst_size - 1; + + /* + * convert from UTF-16 unicode to ASCII + */ + utf16s_to_utf8s(src, src_size, UTF16_HOST_ENDIAN, dst, conv_dst_size); + dst[conv_dst_size] =3D 0; + + for (i =3D 0; i < size && i < conv_dst_size; i++) { + if (*src =3D=3D '\\' || + *src =3D=3D '\r' || + *src =3D=3D '\n' || + *src =3D=3D '\t') + dst[i++] =3D '\\'; + + if (*src =3D=3D '\r') + dst[i] =3D 'r'; + else if (*src =3D=3D '\n') + dst[i] =3D 'n'; + else if (*src =3D=3D '\t') + dst[i] =3D 't'; + else if (*src =3D=3D '"') + dst[i] =3D '\''; + else + dst[i] =3D *src; + src++; + } + + *buffer =3D (u8 *)src; + *buffer_size -=3D size * sizeof(u16); + + return size; +} + +int hp_enforce_single_line_input(char *buf, size_t count) +{ + char *p; + + p =3D memchr(buf, '\n', count); + + if (p =3D=3D buf + count - 1) + *p =3D '\0'; /* strip trailing newline */ + else if (p) + return -EINVAL; /* enforce single line input */ + + return 0; +} + +/* Set pending reboot value and generate KOBJ_NAME event */ +void hp_set_reboot_and_signal_event(void) +{ + bioscfg_drv.pending_reboot =3D true; + kobject_uevent(&bioscfg_drv.class_dev->kobj, KOBJ_CHANGE); +} + +/** + * hp_calculate_string_buffer() - determines size of string buffer for + * use with BIOS communication + * + * @str: the string to calculate based upon + */ +size_t hp_calculate_string_buffer(const char *str) +{ + size_t length =3D strlen(str); + + /* BIOS expects 4 bytes when an empty string is found */ + if (length =3D=3D 0) + return 4; + + /* u16 length field + one UTF16 char for each input char */ + return sizeof(u16) + strlen(str) * sizeof(u16); +} + +int hp_wmi_error_and_message(int error_code) +{ + char *error_msg =3D NULL; + int ret; + + switch (error_code) { + case SUCCESS: + error_msg =3D "Success"; + ret =3D 0; + break; + case CMD_FAILED: + error_msg =3D "Command failed"; + ret =3D -EINVAL; + break; + case INVALID_SIGN: + error_msg =3D "Invalid signature"; + ret =3D -EINVAL; + break; + case INVALID_CMD_VALUE: + error_msg =3D "Invalid command value/Feature not supported"; + ret =3D -EOPNOTSUPP; + break; + case INVALID_CMD_TYPE: + error_msg =3D "Invalid command type"; + ret =3D -EINVAL; + break; + case INVALID_DATA_SIZE: + error_msg =3D "Invalid data size"; + ret =3D -EINVAL; + break; + case INVALID_CMD_PARAM: + error_msg =3D "Invalid command parameter"; + ret =3D -EINVAL; + break; + case ENCRYP_CMD_REQUIRED: + error_msg =3D "Secure/encrypted command required"; + ret =3D -EACCES; + break; + case NO_SECURE_SESSION: + error_msg =3D "No secure session established"; + ret =3D -EACCES; + break; + case SECURE_SESSION_FOUND: + error_msg =3D "Secure session already established"; + ret =3D -EACCES; + break; + case SECURE_SESSION_FAILED: + error_msg =3D "Secure session failed"; + ret =3D -EIO; + break; + case AUTH_FAILED: + error_msg =3D "Other permission/Authentication failed"; + ret =3D -EACCES; + break; + case INVALID_BIOS_AUTH: + error_msg =3D "Invalid BIOS administrator password"; + ret =3D -EINVAL; + break; + case NONCE_DID_NOT_MATCH: + error_msg =3D "Nonce did not match"; + ret =3D -EINVAL; + break; + case GENERIC_ERROR: + error_msg =3D "Generic/Other error"; + ret =3D -EIO; + break; + case BIOS_ADMIN_POLICY_NOT_MET: + error_msg =3D "BIOS Admin password does not meet password policy require= ments"; + ret =3D -EINVAL; + break; + case BIOS_ADMIN_NOT_SET: + error_msg =3D "BIOS Setup password is not set"; + ret =3D -EPERM; + break; + case P21_NO_PROVISIONED: + error_msg =3D "P21 is not provisioned"; + ret =3D -EPERM; + break; + case P21_PROVISION_IN_PROGRESS: + error_msg =3D "P21 is already provisioned or provisioning is in progress= and a signing key has already been sent"; + ret =3D -EINPROGRESS; + break; + case P21_IN_USE: + error_msg =3D "P21 in use (cannot deprovision)"; + ret =3D -EPERM; + break; + case HEP_NOT_ACTIVE: + error_msg =3D "HEP not activated"; + ret =3D -EPERM; + break; + case HEP_ALREADY_SET: + error_msg =3D "HEP Transport already set"; + ret =3D -EINVAL; + break; + case HEP_CHECK_STATE: + error_msg =3D "Check the current HEP state"; + ret =3D -EINVAL; + break; + default: + error_msg =3D "Generic/Other error"; + ret =3D -EIO; + break; + } + + if (error_code) + pr_warn_ratelimited("Returned error 0x%x, \"%s\"\n", error_code, error_m= sg); + + return ret; +} + +static ssize_t pending_reboot_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", bioscfg_drv.pending_reboot); +} + +static struct kobj_attribute pending_reboot =3D __ATTR_RO(pending_reboot); + +/* + * create_attributes_level_sysfs_files() - Creates pending_reboot attribut= es + */ +static int create_attributes_level_sysfs_files(void) +{ + return sysfs_create_file(&bioscfg_drv.main_dir_kset->kobj, + &pending_reboot.attr); +} + +static void attr_name_release(struct kobject *kobj) +{ + kfree(kobj); +} + +static const struct kobj_type attr_name_ktype =3D { + .release =3D attr_name_release, + .sysfs_ops =3D &kobj_sysfs_ops, +}; + +/** + * hp_get_wmiobj_pointer() - Get Content of WMI block for particular insta= nce + * + * @instance_id: WMI instance ID + * @guid_string: WMI GUID (in str form) + * + * Fetches the content for WMI block (instance_id) under GUID (guid_string) + * Caller must kfree the return + */ +union acpi_object *hp_get_wmiobj_pointer(int instance_id, const char *guid= _string) +{ + struct acpi_buffer out =3D { ACPI_ALLOCATE_BUFFER, NULL }; + acpi_status status; + + status =3D wmi_query_block(guid_string, instance_id, &out); + return ACPI_SUCCESS(status) ? (union acpi_object *)out.pointer : NULL; +} + +/** + * hp_get_instance_count() - Compute total number of instances under guid_= string + * + * @guid_string: WMI GUID (in string form) + */ +int hp_get_instance_count(const char *guid_string) +{ + union acpi_object *wmi_obj =3D NULL; + int i =3D 0; + + do { + kfree(wmi_obj); + wmi_obj =3D hp_get_wmiobj_pointer(i, guid_string); + i++; + } while (wmi_obj); + + return i - 1; +} + +/** + * hp_alloc_attributes_data() - Allocate attributes data for a particular = type + * + * @attr_type: Attribute type to allocate + */ +static int hp_alloc_attributes_data(int attr_type) +{ + switch (attr_type) { + case HPWMI_STRING_TYPE: + return hp_alloc_string_data(); + + case HPWMI_INTEGER_TYPE: + return hp_alloc_integer_data(); + + case HPWMI_ENUMERATION_TYPE: + return hp_alloc_enumeration_data(); + + case HPWMI_ORDERED_LIST_TYPE: + return hp_alloc_ordered_list_data(); + + case HPWMI_PASSWORD_TYPE: + return hp_alloc_password_data(); + + default: + return 0; + } +} + +int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str,= int *len) +{ + int ret =3D 0; + int new_len =3D 0; + char tmp[] =3D "0x00"; + char *new_str =3D NULL; + long ch; + int i; + + if (input_len <=3D 0 || !input || !str || !len) + return -EINVAL; + + *len =3D 0; + *str =3D NULL; + + new_str =3D kmalloc(input_len, GFP_KERNEL); + if (!new_str) + return -ENOMEM; + + for (i =3D 0; i < input_len; i +=3D 5) { + strncpy(tmp, input + i, strlen(tmp)); + if (kstrtol(tmp, 16, &ch) =3D=3D 0) { + // escape char + if (ch =3D=3D '\\' || + ch =3D=3D '\r' || + ch =3D=3D '\n' || ch =3D=3D '\t') { + if (ch =3D=3D '\r') + ch =3D 'r'; + else if (ch =3D=3D '\n') + ch =3D 'n'; + else if (ch =3D=3D '\t') + ch =3D 't'; + new_str[new_len++] =3D '\\'; + } + new_str[new_len++] =3D ch; + if (ch =3D=3D '\0') + break; + } + } + + if (new_len) { + new_str[new_len] =3D '\0'; + *str =3D krealloc(new_str, (new_len + 1) * sizeof(char), + GFP_KERNEL); + if (*str) + *len =3D new_len; + else + ret =3D -ENOMEM; + } else { + ret =3D -EFAULT; + } + + if (ret) + kfree(new_str); + return ret; +} + +/* map output size to the corresponding WMI method id */ +int hp_encode_outsize_for_pvsz(int outsize) +{ + if (outsize > 4096) + return -EINVAL; + if (outsize > 1024) + return 5; + if (outsize > 128) + return 4; + if (outsize > 4) + return 3; + if (outsize > 0) + return 2; + return 1; +} + +/* + * Update friendly display name for several attributes associated to + * 'Schedule Power-On' + */ +void hp_friendly_user_name_update(char *path, const char *attr_name, + char *attr_display, int attr_size) +{ + if (strstr(path, SCHEDULE_POWER_ON)) + snprintf(attr_display, attr_size, "%s - %s", SCHEDULE_POWER_ON, attr_nam= e); + else + strscpy(attr_display, attr_name, attr_size); +} + +/** + * hp_update_attribute_permissions() - Update attributes permissions when + * isReadOnly value is 1 + * + * @is_readonly: bool value to indicate if it a readonly attribute. + * @current_val: kobj_attribute corresponding to attribute. + * + */ +void hp_update_attribute_permissions(bool is_readonly, struct kobj_attribu= te *current_val) +{ + current_val->attr.mode =3D is_readonly ? 0444 : 0644; +} + +/** + * destroy_attribute_objs() - Free a kset of kobjects + * @kset: The kset to destroy + * + * Fress kobjects created for each attribute_name under attribute type kset + */ +static void destroy_attribute_objs(struct kset *kset) +{ + struct kobject *pos, *next; + + list_for_each_entry_safe(pos, next, &kset->list, entry) + kobject_put(pos); +} + +/** + * release_attributes_data() - Clean-up all sysfs directories and files cr= eated + */ +static void release_attributes_data(void) +{ + mutex_lock(&bioscfg_drv.mutex); + + hp_exit_string_attributes(); + hp_exit_integer_attributes(); + hp_exit_enumeration_attributes(); + hp_exit_ordered_list_attributes(); + hp_exit_password_attributes(); + hp_exit_sure_start_attributes(); + hp_exit_secure_platform_attributes(); + + if (bioscfg_drv.authentication_dir_kset) { + destroy_attribute_objs(bioscfg_drv.authentication_dir_kset); + kset_unregister(bioscfg_drv.authentication_dir_kset); + bioscfg_drv.authentication_dir_kset =3D NULL; + } + if (bioscfg_drv.main_dir_kset) { + sysfs_remove_file(&bioscfg_drv.main_dir_kset->kobj, &pending_reboot.attr= ); + destroy_attribute_objs(bioscfg_drv.main_dir_kset); + kset_unregister(bioscfg_drv.main_dir_kset); + bioscfg_drv.main_dir_kset =3D NULL; + } + mutex_unlock(&bioscfg_drv.mutex); +} + +/** + * hp_add_other_attributes() - Initialize HP custom attributes not + * reported by BIOS and required to support Secure Platform and Sure + * Start. + * + * @attr_type: Custom HP attribute not reported by BIOS + * + * Initialize all 2 types of attributes: Platform and Sure Start + * object. Populates each attribute types respective properties + * under sysfs files. + * + * Returns zero(0) if successful. Otherwise, a negative value. + */ +static int hp_add_other_attributes(int attr_type) +{ + struct kobject *attr_name_kobj; + union acpi_object *obj =3D NULL; + int ret; + char *attr_name; + + mutex_lock(&bioscfg_drv.mutex); + + attr_name_kobj =3D kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + ret =3D -ENOMEM; + goto err_other_attr_init; + } + + /* Check if attribute type is supported */ + switch (attr_type) { + case HPWMI_SECURE_PLATFORM_TYPE: + attr_name_kobj->kset =3D bioscfg_drv.authentication_dir_kset; + attr_name =3D SPM_STR; + break; + + case HPWMI_SURE_START_TYPE: + attr_name_kobj->kset =3D bioscfg_drv.main_dir_kset; + attr_name =3D SURE_START_STR; + break; + + default: + pr_err("Error: Unknown attr_type: %d\n", attr_type); + ret =3D -EINVAL; + goto err_other_attr_init; + } + + ret =3D kobject_init_and_add(attr_name_kobj, &attr_name_ktype, + NULL, "%s", attr_name); + if (ret) { + pr_err("Error encountered [%d]\n", ret); + kobject_put(attr_name_kobj); + goto err_other_attr_init; + } + + /* Populate attribute data */ + switch (attr_type) { + case HPWMI_SECURE_PLATFORM_TYPE: + ret =3D hp_populate_secure_platform_data(attr_name_kobj); + break; + + case HPWMI_SURE_START_TYPE: + ret =3D hp_populate_sure_start_data(attr_name_kobj); + break; + + default: + goto err_other_attr_init; + } + + mutex_unlock(&bioscfg_drv.mutex); + return 0; + +err_other_attr_init: + mutex_unlock(&bioscfg_drv.mutex); + kfree(obj); + return ret; +} + +static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, + union acpi_object *obj, + const char *guid, int min_elements, + int instance_id) +{ + struct kobject *attr_name_kobj; + union acpi_object *elements; + struct kset *temp_kset; + + char *str_value =3D NULL; + int str_len; + int ret =3D 0; + + /* Take action appropriate to each ACPI TYPE */ + if (obj->package.count < min_elements) { + pr_err("ACPI-package does not have enough elements: %d < %d\n", + obj->package.count, min_elements); + goto pack_attr_exit; + } + + elements =3D obj->package.elements; + + /* sanity checking */ + if (elements[NAME].type !=3D ACPI_TYPE_STRING) { + pr_debug("incorrect element type\n"); + goto pack_attr_exit; + } + if (strlen(elements[NAME].string.pointer) =3D=3D 0) { + pr_debug("empty attribute found\n"); + goto pack_attr_exit; + } + + if (attr_type =3D=3D HPWMI_PASSWORD_TYPE) + temp_kset =3D bioscfg_drv.authentication_dir_kset; + else + temp_kset =3D bioscfg_drv.main_dir_kset; + + /* convert attribute name to string */ + ret =3D hp_convert_hexstr_to_str(elements[NAME].string.pointer, + elements[NAME].string.length, + &str_value, &str_len); + + if (ret) { + pr_debug("Failed to populate integer package data. Error [0%0x]\n", + ret); + kfree(str_value); + return ret; + } + + /* All duplicate attributes found are ignored */ + if (kset_find_obj(temp_kset, str_value)) { + pr_debug("Duplicate attribute name found - %s\n", + str_value); + goto pack_attr_exit; + } + + /* build attribute */ + attr_name_kobj =3D kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + ret =3D -ENOMEM; + goto pack_attr_exit; + } + + attr_name_kobj->kset =3D temp_kset; + + ret =3D kobject_init_and_add(attr_name_kobj, &attr_name_ktype, + NULL, "%s", str_value); + + if (ret) { + kobject_put(attr_name_kobj); + goto pack_attr_exit; + } + + /* enumerate all of these attributes */ + switch (attr_type) { + case HPWMI_STRING_TYPE: + ret =3D hp_populate_string_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_INTEGER_TYPE: + ret =3D hp_populate_integer_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_ENUMERATION_TYPE: + ret =3D hp_populate_enumeration_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_ORDERED_LIST_TYPE: + ret =3D hp_populate_ordered_list_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_PASSWORD_TYPE: + ret =3D hp_populate_password_package_data(elements, + instance_id, + attr_name_kobj); + break; + default: + pr_debug("Unknown attribute type found: 0x%x\n", attr_type); + break; + } + +pack_attr_exit: + kfree(str_value); + return ret; +} + +static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, + union acpi_object *obj, + const char *guid, int min_elements, + int instance_id) +{ + struct kobject *attr_name_kobj; + struct kset *temp_kset; + char str[MAX_BUFF_SIZE]; + + char *temp_str =3D NULL; + char *str_value =3D NULL; + u8 *buffer_ptr =3D NULL; + int buffer_size; + int ret =3D 0; + + buffer_size =3D obj->buffer.length; + buffer_ptr =3D obj->buffer.pointer; + + ret =3D hp_get_string_from_buffer(&buffer_ptr, + &buffer_size, str, MAX_BUFF_SIZE); + + if (ret < 0) + goto buff_attr_exit; + + if (attr_type =3D=3D HPWMI_PASSWORD_TYPE || + attr_type =3D=3D HPWMI_SECURE_PLATFORM_TYPE) + temp_kset =3D bioscfg_drv.authentication_dir_kset; + else + temp_kset =3D bioscfg_drv.main_dir_kset; + + /* All duplicate attributes found are ignored */ + if (kset_find_obj(temp_kset, str)) { + pr_debug("Duplicate attribute name found - %s\n", str); + goto buff_attr_exit; + } + + /* build attribute */ + attr_name_kobj =3D kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + ret =3D -ENOMEM; + goto buff_attr_exit; + } + + attr_name_kobj->kset =3D temp_kset; + + temp_str =3D str; + if (attr_type =3D=3D HPWMI_SECURE_PLATFORM_TYPE) + temp_str =3D "SPM"; + + ret =3D kobject_init_and_add(attr_name_kobj, + &attr_name_ktype, NULL, "%s", + temp_str); + if (ret) { + kobject_put(attr_name_kobj); + goto buff_attr_exit; + } + + /* enumerate all of these attributes */ + switch (attr_type) { + case HPWMI_STRING_TYPE: + ret =3D hp_populate_string_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_INTEGER_TYPE: + ret =3D hp_populate_integer_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_ENUMERATION_TYPE: + ret =3D hp_populate_enumeration_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_ORDERED_LIST_TYPE: + ret =3D hp_populate_ordered_list_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_PASSWORD_TYPE: + ret =3D hp_populate_password_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + default: + pr_debug("Unknown attribute type found: 0x%x\n", attr_type); + break; + } + +buff_attr_exit: + kfree(str_value); + return ret; +} + +/** + * hp_init_bios_attributes() - Initialize all attributes for a type + * @attr_type: The attribute type to initialize + * @guid: The WMI GUID associated with this type to initialize + * + * Initialize all 5 types of attributes: enumeration, integer, + * string, password, ordered list object. Populates each attribute types + * respective properties under sysfs files + */ +static int hp_init_bios_attributes(enum hp_wmi_data_type attr_type, const = char *guid) +{ + union acpi_object *obj =3D NULL; + int min_elements; + + /* instance_id needs to be reset for each type GUID + * also, instance IDs are unique within GUID but not across + */ + int instance_id =3D 0; + int ret =3D 0; + + ret =3D hp_alloc_attributes_data(attr_type); + if (ret) + return ret; + + switch (attr_type) { + case HPWMI_STRING_TYPE: + min_elements =3D STR_ELEM_CNT; + break; + case HPWMI_INTEGER_TYPE: + min_elements =3D INT_ELEM_CNT; + break; + case HPWMI_ENUMERATION_TYPE: + min_elements =3D ENUM_ELEM_CNT; + break; + case HPWMI_ORDERED_LIST_TYPE: + min_elements =3D ORD_ELEM_CNT; + break; + case HPWMI_PASSWORD_TYPE: + min_elements =3D PSWD_ELEM_CNT; + break; + default: + pr_err("Error: Unknown attr_type: %d\n", attr_type); + return -EINVAL; + } + + /* need to use specific instance_id and guid combination to get right dat= a */ + obj =3D hp_get_wmiobj_pointer(instance_id, guid); + if (!obj) + return -ENODEV; + + mutex_lock(&bioscfg_drv.mutex); + while (obj) { + /* Take action appropriate to each ACPI TYPE */ + if (obj->type =3D=3D ACPI_TYPE_PACKAGE) { + ret =3D hp_init_bios_package_attribute(attr_type, obj, + guid, min_elements, + instance_id); + if (ret) + goto err_attr_init; + } else if (obj->type =3D=3D ACPI_TYPE_BUFFER) { + ret =3D hp_init_bios_buffer_attribute(attr_type, obj, + guid, min_elements, + instance_id); + if (ret) + goto err_attr_init; + } else { + pr_err("Expected ACPI-package or buffer type, got: %d\n", + obj->type); + ret =3D -EIO; + goto err_attr_init; + } + + kfree(obj); + instance_id++; + obj =3D hp_get_wmiobj_pointer(instance_id, guid); + } + +err_attr_init: + mutex_unlock(&bioscfg_drv.mutex); + kfree(obj); + return ret; +} + +static int __init hp_init(void) +{ + int ret; + int hp_bios_capable =3D wmi_has_guid(HP_WMI_BIOS_GUID); + int set_bios_settings =3D wmi_has_guid(HP_WMI_SET_BIOS_SETTING_GUID); + + if (!hp_bios_capable) { + pr_err("Unable to run on non-HP system\n"); + return -ENODEV; + } + + if (!set_bios_settings) { + pr_err("Unable to set BIOS settings on HP systems\n"); + return -ENODEV; + } + + ret =3D hp_init_attr_set_interface(); + if (ret) + return ret; + + ret =3D fw_attributes_class_get(&fw_attr_class); + if (ret) + goto err_unregister_class; + + bioscfg_drv.class_dev =3D device_create(fw_attr_class, NULL, MKDEV(0, 0), + NULL, "%s", DRIVER_NAME); + if (IS_ERR(bioscfg_drv.class_dev)) { + ret =3D PTR_ERR(bioscfg_drv.class_dev); + goto err_unregister_class; + } + + bioscfg_drv.main_dir_kset =3D kset_create_and_add("attributes", NULL, + &bioscfg_drv.class_dev->kobj); + if (!bioscfg_drv.main_dir_kset) { + ret =3D -ENOMEM; + pr_debug("Failed to create and add attributes\n"); + goto err_destroy_classdev; + } + + bioscfg_drv.authentication_dir_kset =3D kset_create_and_add("authenticati= on", NULL, + &bioscfg_drv.class_dev->kobj); + if (!bioscfg_drv.authentication_dir_kset) { + ret =3D -ENOMEM; + pr_debug("Failed to create and add authentication\n"); + goto err_release_attributes_data; + } + + /* + * sysfs level attributes. + * - pending_reboot + */ + ret =3D create_attributes_level_sysfs_files(); + if (ret) + pr_debug("Failed to create sysfs level attributes\n"); + + ret =3D hp_init_bios_attributes(HPWMI_STRING_TYPE, HP_WMI_BIOS_STRING_GUI= D); + if (ret) + pr_debug("Failed to populate string type attributes\n"); + + ret =3D hp_init_bios_attributes(HPWMI_INTEGER_TYPE, HP_WMI_BIOS_INTEGER_G= UID); + if (ret) + pr_debug("Failed to populate integer type attributes\n"); + + ret =3D hp_init_bios_attributes(HPWMI_ENUMERATION_TYPE, HP_WMI_BIOS_ENUME= RATION_GUID); + if (ret) + pr_debug("Failed to populate enumeration type attributes\n"); + + ret =3D hp_init_bios_attributes(HPWMI_ORDERED_LIST_TYPE, HP_WMI_BIOS_ORDE= RED_LIST_GUID); + if (ret) + pr_debug("Failed to populate ordered list object type attributes\n"); + + ret =3D hp_init_bios_attributes(HPWMI_PASSWORD_TYPE, HP_WMI_BIOS_PASSWORD= _GUID); + if (ret) + pr_debug("Failed to populate password object type attributes\n"); + + bioscfg_drv.spm_data.attr_name_kobj =3D NULL; + ret =3D hp_add_other_attributes(HPWMI_SECURE_PLATFORM_TYPE); + if (ret) + pr_debug("Failed to populate secure platform object type attribute\n"); + + bioscfg_drv.sure_start_attr_kobj =3D NULL; + ret =3D hp_add_other_attributes(HPWMI_SURE_START_TYPE); + if (ret) + pr_debug("Failed to populate sure start object type attribute\n"); + + return 0; + +err_release_attributes_data: + release_attributes_data(); + +err_destroy_classdev: + device_destroy(fw_attr_class, MKDEV(0, 0)); + +err_unregister_class: + fw_attributes_class_put(); + hp_exit_attr_set_interface(); + + return ret; +} + +static void __exit hp_exit(void) +{ + release_attributes_data(); + device_destroy(fw_attr_class, MKDEV(0, 0)); + + fw_attributes_class_put(); + hp_exit_attr_set_interface(); +} + +module_init(hp_init); +module_exit(hp_exit); --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A8CDC7EE2C for ; Fri, 2 Jun 2023 13:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236027AbjFBNLL (ORCPT ); Fri, 2 Jun 2023 09:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235979AbjFBNKy (ORCPT ); Fri, 2 Jun 2023 09:10:54 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BBA91B6; Fri, 2 Jun 2023 06:10:52 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-39a55e5cfc0so1754535b6e.3; Fri, 02 Jun 2023 06:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711451; x=1688303451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RZU9mJB4e9US6MCdUI4SgAPj2VKTbassbztj2iVhT3I=; b=TNCIRYaiUeg9WdMhl1tBc85lJclJFdPd19g9hrRjdQ/Cf4Z/AC/cVVm8uv3DTmc8pV EYBhr4lU6fPwlSlkKhL39/Afb9BDfuIFqa8sOW6i1G5OqoNKtOFDn8pa/BE7292pr2lK WKPBVgDIgLb9dfQ70wkKOajbjHPRCOzJy7JiwtL04l9FoKqlZ/lDd1NaDgQ44l4Is9tF CwrL7wZJEQ6ZhsHWszlzgkXe4Fzv1ans2RGYbabYrbSWKzLg6+f2hg4k4WcB1W5PcI8a 1URKx/E2SZdu258KP+8GU9sGtm0WS08NPWxpnflVXiCYuCfCRftUXOmbTjXmWWe+YSI3 JqeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711451; x=1688303451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RZU9mJB4e9US6MCdUI4SgAPj2VKTbassbztj2iVhT3I=; b=grQnQnSbwcNOwA/ISwF48Fof2fdHXYT2Lr+L/7Jd2+do3reibJ5bQjAsXSRvqbwPKE Pqfg/930PZlboNAIhVgR+xoaITaNBv7VPGlmmnjdtCvAugr83Yr1QEa12sNAUik2DbRO muanO5AwEiYzErHYKFrqscR7U5C1w7DFJqg1GEqKpbg2pY1tWfaYOLAPAeLQVqxCn4qH VDjRU2CjBflJ7qa9bI+MMzPLQv3Oco6j8K20XbwJ7cqIAme+rxVlN/mXgxZuYCIanker 8ZQOTs+6wCgsJIj9iJnfrIXxVUcUbwLVik7pk4QhRm48Kdzd1CYVDDaPIqMWTg5L9iST lLaQ== X-Gm-Message-State: AC+VfDzSkMN3bfaqWrEBi1jKL591BUBVJyoPYrxse6VmUu5ZYglRsuBl 58O4G/dQAvDDnefXAu5Lf9E= X-Google-Smtp-Source: ACHHUZ7ZM853el2B2KL/2nQLo+ORcJ7OhuxVsnrdtZfUoOxTlPv5fulNCmpqnT9z/vxz8zupE2LWig== X-Received: by 2002:a05:6808:307:b0:398:342a:f491 with SMTP id i7-20020a056808030700b00398342af491mr2438754oie.34.1685711451003; Fri, 02 Jun 2023 06:10:51 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:50 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 04/13] hp-bioscfg: biosattr-interface Date: Fri, 2 Jun 2023 08:10:35 -0500 Message-Id: <20230602131044.3297-5-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/biosattr-interface.c | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c b/driv= ers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file mode 100644 index 000000000000..1d59ad600b84 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c @@ -0,0 +1,312 @@ +// 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 +#include "bioscfg.h" + +/* + * 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_query funct= ion. + */ +struct bios_args { + u32 signature; + u32 command; + u32 commandtype; + u32 datasize; + u8 data[]; +}; + +/** + * hp_set_attribute + * + * @a_name: The attribute name + * @a_value: The attribute value + * + * Sets an attribute to new value + * + * Returns zero on success + * -ENODEV if device is not found + * -EINVAL if the instance of 'Setup Admin' password is not found. + * -ENOMEM unable to allocate memory + */ +int hp_set_attribute(const char *a_name, const char *a_value) +{ + int security_area_size; + int a_name_size, a_value_size; + u16 *buffer =3D NULL; + u16 *start; + int buffer_size, instance, ret; + char *auth_token_choice; + + mutex_lock(&bioscfg_drv.mutex); + + instance =3D hp_get_password_instance_for_type(SETUP_PASSWD); + if (instance < 0) { + ret =3D -EINVAL; + goto out_set_attribute; + } + + /* Select which auth token to use; password or [auth token] */ + if (bioscfg_drv.spm_data.auth_token) + auth_token_choice =3D bioscfg_drv.spm_data.auth_token; + else + auth_token_choice =3D bioscfg_drv.password_data[instance].current_passwo= rd; + + a_name_size =3D hp_calculate_string_buffer(a_name); + a_value_size =3D hp_calculate_string_buffer(a_value); + security_area_size =3D hp_calculate_security_buffer(auth_token_choice); + buffer_size =3D a_name_size + a_value_size + security_area_size; + + buffer =3D kmalloc(buffer_size + 1, GFP_KERNEL); + if (!buffer) { + ret =3D -ENOMEM; + goto out_set_attribute; + } + + /* build variables to set */ + start =3D buffer; + start =3D hp_ascii_to_utf16_unicode(start, a_name); + if (!start) { + ret =3D -EINVAL; + goto out_set_attribute; + } + + start =3D hp_ascii_to_utf16_unicode(start, a_value); + if (!start) { + ret =3D -EINVAL; + goto out_set_attribute; + } + + ret =3D hp_populate_security_buffer(start, auth_token_choice); + if (ret < 0) + goto out_set_attribute; + + ret =3D 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) + * @command: 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 outp= ut + * size. E.g. Battery info query is defined to have 1 byte input + * and 128 byte output. The caller would do: + * buffer =3D kzalloc(128, GFP_KERNEL); + * ret =3D 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 *buf= fer, + u32 insize, u32 outsize) +{ + struct acpi_buffer input, output =3D { ACPI_ALLOCATE_BUFFER, NULL }; + struct bios_return *bios_return; + union acpi_object *obj =3D NULL; + struct bios_args *args =3D NULL; + u32 mid, actual_outsize, ret; + size_t bios_args_size; + + mid =3D hp_encode_outsize_for_pvsz(outsize); + if (WARN_ON(mid < 0)) + return mid; + + bios_args_size =3D struct_size(args, data, insize); + args =3D kmalloc(bios_args_size, GFP_KERNEL); + if (!args) + return -ENOMEM; + + input.length =3D bios_args_size; + input.pointer =3D args; + + /* BIOS expects 'SECU' in hex as the signature value*/ + args->signature =3D 0x55434553; + args->command =3D command; + args->commandtype =3D query; + args->datasize =3D insize; + memcpy(args->data, buffer, flex_array_size(args, data, insize)); + + ret =3D wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output); + if (ret) + goto out_free; + + obj =3D output.pointer; + if (!obj) { + ret =3D -EINVAL; + goto out_free; + } + + if (obj->type !=3D ACPI_TYPE_BUFFER || + obj->buffer.length < sizeof(*bios_return)) { + pr_warn("query 0x%x returned wrong type or too small buffer\n", query); + ret =3D -EINVAL; + goto out_free; + } + + bios_return =3D (struct bios_return *)obj->buffer.pointer; + ret =3D bios_return->return_code; + if (ret) { + if (ret !=3D INVALID_CMD_VALUE && ret !=3D INVALID_CMD_TYPE) + 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 =3D min_t(u32, outsize, obj->buffer.length - sizeof(*bios_= return)); + memcpy_and_pad(buffer, outsize, obj->buffer.pointer + sizeof(*bios_return= ), + actual_outsize, 0); + +out_free: + ret =3D hp_wmi_error_and_message(ret); + + kfree(obj); + kfree(args); + return ret; +} + +static void *utf16_empty_string(u16 *p) +{ + *p++ =3D 2; + *p++ =3D 0x00; + return p; +} + +/** + * hp_ascii_to_utf16_unicode - Convert ascii string to UTF-16 unicode + * + * BIOS supports UTF-16 characters that are 2 bytes long. No variable + * multi-byte language supported. + * + * @p: Unicode buffer address + * @str: string to convert to unicode + * + * Returns a void pointer to the buffer string + */ +void *hp_ascii_to_utf16_unicode(u16 *p, const u8 *str) +{ + int len =3D strlen(str); + int ret; + + /* + * Add null character when reading an empty string + * "02 00 00 00" + */ + if (len =3D=3D 0) + return utf16_empty_string(p); + + /* Move pointer len * 2 number of bytes */ + *p++ =3D len * 2; + ret =3D utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN, p, len); + if (ret < 0) { + dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n"); + return NULL; + } + + if (ret * sizeof(u16) > U16_MAX) { + dev_err(bioscfg_drv.class_dev, "Error string too long\n"); + return NULL; + } + + p +=3D 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, oth= erwise + * -ENOMEM unable to allocate memory + * -EINVAL buffer not allocated or too small + */ +int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size) +{ + union acpi_object *obj; + struct acpi_buffer input =3D {input_size, input_buffer}; + struct acpi_buffer output =3D {ACPI_ALLOCATE_BUFFER, NULL}; + int ret; + + ret =3D wmi_evaluate_method(HP_WMI_SET_BIOS_SETTING_GUID, 0, 1, &input, &= output); + + obj =3D output.pointer; + if (!obj) + return -EINVAL; + + if (obj->type !=3D ACPI_TYPE_INTEGER) { + ret =3D -EINVAL; + goto out_free; + } + + ret =3D obj->integer.value; + if (ret) { + ret =3D hp_wmi_error_and_message(ret); + goto out_free; + } + +out_free: + kfree(obj); + return ret; +} + +static int hp_attr_set_interface_probe(struct wmi_device *wdev, const void= *context) +{ + mutex_lock(&bioscfg_drv.mutex); + mutex_unlock(&bioscfg_drv.mutex); + return 0; +} + +static void hp_attr_set_interface_remove(struct wmi_device *wdev) +{ + mutex_lock(&bioscfg_drv.mutex); + mutex_unlock(&bioscfg_drv.mutex); +} + +static const struct wmi_device_id hp_attr_set_interface_id_table[] =3D { + { .guid_string =3D HP_WMI_BIOS_GUID}, + { } +}; + +static struct wmi_driver hp_attr_set_interface_driver =3D { + .driver =3D { + .name =3D DRIVER_NAME, + }, + .probe =3D hp_attr_set_interface_probe, + .remove =3D hp_attr_set_interface_remove, + .id_table =3D hp_attr_set_interface_id_table, +}; + +int hp_init_attr_set_interface(void) +{ + return wmi_driver_register(&hp_attr_set_interface_driver); +} + +void hp_exit_attr_set_interface(void) +{ + wmi_driver_unregister(&hp_attr_set_interface_driver); +} + +MODULE_DEVICE_TABLE(wmi, hp_attr_set_interface_id_table); --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4923AC7EE2C for ; Fri, 2 Jun 2023 13:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235552AbjFBNLO (ORCPT ); Fri, 2 Jun 2023 09:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235987AbjFBNKz (ORCPT ); Fri, 2 Jun 2023 09:10:55 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBBBB1B8; Fri, 2 Jun 2023 06:10:52 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-557ca32515eso1419100eaf.3; Fri, 02 Jun 2023 06:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711452; x=1688303452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=z9cvNeG2lQEBFA2epAf8/IWbUQtxuRd9agaxVVMvooI=; b=G6b/PwnAkd+Lt1c6xw+DWS1DaxAZHuJBKFh4hl5jtgSCTig0ygkDDhlgRAdHeITpgM TJesjJYHhIrVHUxZgI926o000SMUzILTczVJIo/J4UD4R8/OicMRzxmjSYRigNWouZCm wT8pIQ1xpBJ31o4Na8VkJjtNTBXwBnA4+flJZrIdyoJf141cK8cSkWcOzN5qpTo8Ok8d a6kbbahDSUQa+GBwfAJkjJUoz2M5o1bVRGLV3DEJi5KHrYF577ldYYFF6R6vthiRzf49 bBAlXdQiI9IeXA/7A1SFzv8W5gtoy/AFueE3e7y9R7Xa8CQySDhY40EODyzJEy+r2yIM CvSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711452; x=1688303452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z9cvNeG2lQEBFA2epAf8/IWbUQtxuRd9agaxVVMvooI=; b=AdxGacmjzB1TPDhsWrnMHlRq08ZwTj++KoiVxvTKldXAEihs7q77BNDm0dvvy8LNCQ dW7Oc1SEJgwS3WE4ZPHfmU9JFz8yfTA9eLAL63XyNNnBDjEA9ePtTN0rz3I/sARmeU+L R6g/JGag4wjNAFep1oR3uCL18eTQvuz/6qT39abfW//6A7dakkSIctj4mwsukNpNxXwQ orCEUKBCY4Ei1alX1+KcNBfeViPHjyGhqxmxA0YwfR3IBLqguC7y633pgWXz4RSBTgwT C374BVF1ttDIGqs1aU+IB9lQI56E0zX4ZuJE5pXW183Bu75DJIHGzZ1TcRvENtk92YlH 1G6w== X-Gm-Message-State: AC+VfDyhvFf+hICqp8JBmyPA8Jh6/YRHJXll4faLt54hWPf5bCkSTyiG X5eLIGhnYsnNWNYmskbikfY= X-Google-Smtp-Source: ACHHUZ7YiIsDEbHC+cbikBhAStz0/nX0myyz051qEKIlxnvbLVIBocp0YScQRiuQWn85sbVA4QO07w== X-Received: by 2002:aca:2310:0:b0:394:4603:77f2 with SMTP id e16-20020aca2310000000b00394460377f2mr2337944oie.2.1685711452094; Fri, 02 Jun 2023 06:10:52 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:51 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 05/13] hp-bioscfg: enum-attributes Date: Fri, 2 Jun 2023 08:10:36 -0500 Message-Id: <20230602131044.3297-6-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/enum-attributes.c | 462 ++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c b/drivers= /platform/x86/hp/hp-bioscfg/enum-attributes.c new file mode 100644 index 000000000000..b116a6efd76b --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c @@ -0,0 +1,462 @@ +// 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_attrib= ute *attr, char *buf) +{ + int instance_id =3D get_enumeration_instance_id(kobj); + + if (instance_id < 0) + return -EIO; + + return sysfs_emit(buf, "%s\n", + bioscfg_drv.enumeration_data[instance_id].current_value); +} + +/** + * 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) +{ + int i; + int found =3D 0; + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + /* Is it a read only attribute */ + if (enum_data->common.is_readonly) + return -EIO; + + for (i =3D 0; i < enum_data->possible_values_size && !found; i++) + if (!strcmp(enum_data->possible_values[i], buf)) + found =3D 1; + + if (!found) + return -EINVAL; + + return 0; +} + +static void update_enumeration_value(int instance_id, char *attr_value) +{ + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + strscpy(enum_data->current_value, + attr_value, + sizeof(enum_data->current_value)); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, enumeration); +static struct kobj_attribute enumeration_display_name =3D + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, enumeration); +static struct kobj_attribute enumeration_current_val =3D + __ATTR_RW(current_value); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(possible_values, enumeration, SEMICOLON_SEP= ); +static struct kobj_attribute enumeration_poss_val =3D + __ATTR_RO(possible_values); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "enumeration\n"); +} + +static struct kobj_attribute enumeration_type =3D + __ATTR_RO(type); + +static struct attribute *enumeration_attrs[] =3D { + &common_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 =3D { + .attrs =3D enumeration_attrs, +}; + +int hp_alloc_enumeration_data(void) +{ + bioscfg_drv.enumeration_instances_count =3D + hp_get_instance_count(HP_WMI_BIOS_ENUMERATION_GUID); + + bioscfg_drv.enumeration_data =3D kcalloc(bioscfg_drv.enumeration_instance= s_count, + sizeof(*bioscfg_drv.enumeration_data), GFP_KERNEL); + if (!bioscfg_drv.enumeration_data) { + bioscfg_drv.enumeration_instances_count =3D 0; + return -ENOMEM; + } + return 0; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_enum_types[] =3D { + [NAME] =3D ACPI_TYPE_STRING, + [VALUE] =3D ACPI_TYPE_STRING, + [PATH] =3D ACPI_TYPE_STRING, + [IS_READONLY] =3D ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] =3D ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] =3D ACPI_TYPE_INTEGER, + [SEQUENCE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES] =3D ACPI_TYPE_STRING, + [SECURITY_LEVEL] =3D ACPI_TYPE_INTEGER, + [ENUM_CURRENT_VALUE] =3D ACPI_TYPE_STRING, + [ENUM_SIZE] =3D ACPI_TYPE_INTEGER, + [ENUM_POSSIBLE_VALUES] =3D ACPI_TYPE_STRING, +}; + +static int hp_populate_enumeration_elements_from_package(union acpi_object= *enum_obj, + int enum_obj_count, + int instance_id) +{ + char *str_value =3D NULL; + int value_len; + u32 size =3D 0; + u32 int_value; + int elem =3D 0; + int reqs; + int pos_values; + int ret; + int eloc; + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + for (elem =3D 1, eloc =3D 1; elem < enum_obj_count; elem++, eloc++) { + /* ONLY look at the first ENUM_ELEM_CNT elements */ + if (eloc =3D=3D ENUM_ELEM_CNT) + goto exit_enumeration_package; + + switch (enum_obj[elem].type) { + case ACPI_TYPE_STRING: + if (PREREQUISITES !=3D elem && ENUM_POSSIBLE_VALUES !=3D elem) { + ret =3D hp_convert_hexstr_to_str(enum_obj[elem].string.pointer, + enum_obj[elem].string.length, + &str_value, &value_len); + if (ret) + return -EINVAL; + } + break; + case ACPI_TYPE_INTEGER: + int_value =3D (u32)enum_obj[elem].integer.value; + break; + default: + pr_warn("Unsupported object type [%d]\n", enum_obj[elem].type); + continue; + } + + /* Check that both expected and read object type match */ + if (expected_enum_types[eloc] !=3D enum_obj[elem].type) { + pr_err("Error expected type %d for elem %d, but got type %d instead\n", + expected_enum_types[eloc], elem, enum_obj[elem].type); + return -EIO; + } + + /* Assign appropriate element value to corresponding field */ + switch (eloc) { + case NAME: + case VALUE: + break; + case PATH: + strscpy(enum_data->common.path, str_value, + sizeof(enum_data->common.path)); + break; + case IS_READONLY: + enum_data->common.is_readonly =3D int_value; + break; + case DISPLAY_IN_UI: + enum_data->common.display_in_ui =3D int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + enum_data->common.requires_physical_presence =3D int_value; + break; + case SEQUENCE: + enum_data->common.sequence =3D int_value; + break; + case PREREQUISITES_SIZE: + enum_data->common.prerequisites_size =3D int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of eleme= nts supported or data may be malformed\n"); + + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + + case PREREQUISITES: + size =3D min_t(u32, enum_data->common.prerequisites_size, MAX_PREREQUIS= ITES_SIZE); + for (reqs =3D 0; reqs < size; reqs++) { + if (elem >=3D enum_obj_count) { + pr_err("Error enum-objects package is too small\n"); + return -EINVAL; + } + + ret =3D hp_convert_hexstr_to_str(enum_obj[elem + reqs].string.pointer, + enum_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + return -EINVAL; + + strscpy(enum_data->common.prerequisites[reqs], + str_value, + sizeof(enum_data->common.prerequisites[reqs])); + + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + enum_data->common.security_level =3D int_value; + break; + + case ENUM_CURRENT_VALUE: + strscpy(enum_data->current_value, + str_value, sizeof(enum_data->current_value)); + break; + case ENUM_SIZE: + enum_data->possible_values_size =3D int_value; + if (int_value > MAX_VALUES_SIZE) + pr_warn("Possible number values size value exceeded the maximum number= of elements supported or data may be malformed\n"); + + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. POSSIBLE_VALUES + * object is omitted by BIOS when the size is zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + + case ENUM_POSSIBLE_VALUES: + size =3D enum_data->possible_values_size; + + for (pos_values =3D 0; pos_values < size && pos_values < MAX_VALUES_SIZ= E; + pos_values++) { + if (elem >=3D enum_obj_count) { + pr_err("Error enum-objects package is too small\n"); + return -EINVAL; + } + + ret =3D hp_convert_hexstr_to_str(enum_obj[elem + pos_values].string.po= inter, + enum_obj[elem + pos_values].string.length, + &str_value, &value_len); + + if (ret) + return -EINVAL; + + /* + * ignore strings when possible values size + * is greater than MAX_VALUES_SIZE + */ + if (size < MAX_VALUES_SIZE) + strscpy(enum_data->possible_values[pos_values], + str_value, + sizeof(enum_data->possible_values[pos_values])); + } + break; + default: + pr_warn("Invalid element: %d found in Enumeration attribute or data may= be malformed\n", elem); + break; + } + + kfree(str_value); + } + +exit_enumeration_package: + kfree(str_value); + return 0; +} + +/** + * hp_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 hp_populate_enumeration_package_data(union acpi_object *enum_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + enum_data->attr_name_kobj =3D attr_name_kobj; + + hp_populate_enumeration_elements_from_package(enum_obj, + enum_obj->package.count, + instance_id); + hp_update_attribute_permissions(enum_data->common.is_readonly, + &enumeration_current_val); + /* + * Several attributes have names such "MONDAY". Friendly + * user nane is generated to make the name more descriptive + */ + hp_friendly_user_name_update(enum_data->common.path, + attr_name_kobj->name, + enum_data->common.display_name, + sizeof(enum_data->common.display_name)); + return sysfs_create_group(attr_name_kobj, &enumeration_attr_group); +} + +static int hp_populate_enumeration_elements_from_buffer(u8 *buffer_ptr, u3= 2 *buffer_size, + int instance_id) +{ + int reqs; + int values; + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + /* + * In earlier implementation, reported errors were ignored + * causing the data to remain uninitialized. It is for this + * reason functions may return an error and no validation + * takes place. + */ + + // VALUE: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, enum_data->current_va= lue, + sizeof(enum_data->current_value)); + + // PATH: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, enum_data->common.pat= h, + sizeof(enum_data->common.path)); + + // IS_READONLY: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.is_readonly); + + //DISPLAY_IN_UI: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.display_in_ui); + + // REQUIRES_PHYSICAL_PRESENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.requires_physical_presence); + + // SEQUENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.sequence); + + // PREREQUISITES_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.prerequisites_size); + + if (enum_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) { + /* Report a message and limit prerequisite size to maximum value */ + pr_warn("Enum Prerequisites size value exceeded the maximum number of el= ements supported or data may be malformed\n"); + enum_data->common.prerequisites_size =3D MAX_PREREQUISITES_SIZE; + } + + // PREREQUISITES: + for (reqs =3D 0; reqs < enum_data->common.prerequisites_size; reqs++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + enum_data->common.prerequisites[reqs], + sizeof(enum_data->common.prerequisites[reqs])); + + // SECURITY_LEVEL: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->common.security_level); + + // ENUM_CURRENT_VALUE: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + enum_data->current_value, + sizeof(enum_data->current_value)); + // ENUM_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &enum_data->possible_values_size); + + if (enum_data->possible_values_size > MAX_VALUES_SIZE) { + /* Report a message and limit possible values size to maximum value */ + pr_warn("Enum Possible size value exceeded the maximum number of element= s supported or data may be malformed\n"); + enum_data->possible_values_size =3D MAX_VALUES_SIZE; + } + + // ENUM_POSSIBLE_VALUES: + + for (values =3D 0; values < enum_data->possible_values_size; values++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + enum_data->possible_values[values], + sizeof(enum_data->possible_values[values])); + + return 0; +} + +/** + * hp_populate_enumeration_buffer_data() - + * Populate all properties of an instance under enumeration attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj) +{ + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[inst= ance_id]; + + enum_data->attr_name_kobj =3D attr_name_kobj; + + /* Populate enumeration elements */ + hp_populate_enumeration_elements_from_buffer(buffer_ptr, buffer_size, ins= tance_id); + + hp_update_attribute_permissions(enum_data->common.is_readonly, + &enumeration_current_val); + /* + * Several attributes have names such "MONDAY". A Friendlier + * user nane is generated to make the name more descriptive + */ + hp_friendly_user_name_update(enum_data->common.path, + attr_name_kobj->name, + enum_data->common.display_name, + sizeof(enum_data->common.display_name)); + + return sysfs_create_group(attr_name_kobj, &enumeration_attr_group); +} + +/** + * hp_exit_enumeration_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void hp_exit_enumeration_attributes(void) +{ + int instance_id; + + for (instance_id =3D 0; instance_id < bioscfg_drv.enumeration_instances_c= ount; + instance_id++) { + struct enumeration_data *enum_data =3D &bioscfg_drv.enumeration_data[ins= tance_id]; + struct kobject *attr_name_kobj =3D enum_data->attr_name_kobj; + + if (attr_name_kobj) + sysfs_remove_group(attr_name_kobj, &enumeration_attr_group); + } + bioscfg_drv.enumeration_instances_count =3D 0; + + kfree(bioscfg_drv.enumeration_data); + bioscfg_drv.enumeration_data =3D NULL; +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A625C7EE24 for ; Fri, 2 Jun 2023 13:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235783AbjFBNLQ (ORCPT ); Fri, 2 Jun 2023 09:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236000AbjFBNLH (ORCPT ); Fri, 2 Jun 2023 09:11:07 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 585731BB; Fri, 2 Jun 2023 06:10:54 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-38e3228d120so1276320b6e.3; Fri, 02 Jun 2023 06:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711453; x=1688303453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VhMNElMcD96BiWO7VwSZ4kHuPne7boxpbc3pYu3wsd0=; b=c/QdU1O9EMqQkb24x1xAOOkYfgty/smk0nAdhU6DqgF7gcdOhCh5Q2SGuCBX00bdOa Dm0VumgpdX2rShNHPcyKl7myI5e4CbMaj340p2rPyJSKOduku28OLONDtnmfA0gWx4Xp DStqTigqBs9jmW8vqzqFeLGUx9+tq/B4gVLjJwufz+XD2te8LcJ67OkojKVqCTwopokN LBOE4priAeAFvYdp9wBwEfW16bz+HlrS9wgHvURU/vlNkP9xeraqMlETEMaFF37VAi90 qL8ni1KsrYP2j134p1AOQcRsAnFLqZQP/l/8Hi8uAAZBwn2d15uYdGoflYcbq9fN0iFG b2ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711453; x=1688303453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VhMNElMcD96BiWO7VwSZ4kHuPne7boxpbc3pYu3wsd0=; b=SNCnEI5a8IxkNGPD4sh8yujNB+nkzPjhcNo4wy+DmL98uImNZ506wNrvZjfVcsxomT UiP1/Jvm+7S+cWE0LWoMyTtTR9BQLDI6XBsvSkFDyIUqykfMOuQGKDXlRJCEO5+8kN6G 5eFoS3IoS06KNhN0sMow+GHc5lzlIIpLG/cIKNThPeBgGKnk100opYFnZtNNebBb5VUr 7eGhM9aSgOoIgVKoXG6DGctOX+ZcyyOpU/vxjx8NFlEbTFHGXH8R0qoPNT7UUpr0RV/o 4sTtGC412NeQQouzTk1ZFJViJvajqL1exl8nEemFTuN7XqPIU6PHw0mdV98R5X8AcZlg KNlA== X-Gm-Message-State: AC+VfDyuxOblTJDxSIVudys+CJ8WGcuY3/m6TZIREVq/MxHdC0llDy+0 FJETCakYoI+EfmdwCr0eDtY= X-Google-Smtp-Source: ACHHUZ4zAaZWpxVK7cEJg4Id61Vo59khBEyMdjn41MXorY08M77AS/sh5uq+lzWpOZbDhARQyb+rCg== X-Received: by 2002:a54:410f:0:b0:398:41b4:5b2 with SMTP id l15-20020a54410f000000b0039841b405b2mr1817981oic.23.1685711453512; Fri, 02 Jun 2023 06:10:53 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:53 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 06/13] hp-bioscfg: int-attributes Date: Fri, 2 Jun 2023 08:10:37 -0500 Message-Id: <20230602131044.3297-7-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/int-attributes.c | 437 ++++++++++++++++++ 1 file changed, 437 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c b/drivers/= platform/x86/hp/hp-bioscfg/int-attributes.c new file mode 100644 index 000000000000..87aa72eae4f2 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c @@ -0,0 +1,437 @@ +// 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_attrib= ute *attr, char *buf) +{ + int instance_id =3D get_integer_instance_id(kobj); + + if (instance_id < 0) + return -EIO; + + return sysfs_emit(buf, "%d\n", + bioscfg_drv.integer_data[instance_id].current_value); +} + +/** + * 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; + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + /* BIOS treats it as a read only attribute */ + if (integer_data->common.is_readonly) + return -EIO; + + ret =3D kstrtoint(buf, 10, &in_val); + if (ret < 0) + return ret; + + if (in_val < integer_data->lower_bound || + in_val > integer_data->upper_bound) + return -ERANGE; + + return 0; +} + +static void update_integer_value(int instance_id, char *attr_value) +{ + int in_val; + int ret; + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + ret =3D kstrtoint(attr_value, 10, &in_val); + if (ret =3D=3D 0) + integer_data->current_value =3D in_val; + else + pr_warn("Invalid integer value found: %s\n", attr_value); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, integer); +static struct kobj_attribute integer_display_name =3D + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, integer); +static struct kobj_attribute integer_current_val =3D + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_N_PROPERTY_SHOW(lower_bound, integer); +static struct kobj_attribute integer_lower_bound =3D + __ATTR_RO(lower_bound); + +ATTRIBUTE_N_PROPERTY_SHOW(upper_bound, integer); +static struct kobj_attribute integer_upper_bound =3D + __ATTR_RO(upper_bound); + +ATTRIBUTE_N_PROPERTY_SHOW(scalar_increment, integer); +static struct kobj_attribute integer_scalar_increment =3D + __ATTR_RO(scalar_increment); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "integer\n"); +} + +static struct kobj_attribute integer_type =3D + __ATTR_RO(type); + +static struct attribute *integer_attrs[] =3D { + &common_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 =3D { + .attrs =3D integer_attrs, +}; + +int hp_alloc_integer_data(void) +{ + bioscfg_drv.integer_instances_count =3D hp_get_instance_count(HP_WMI_BIOS= _INTEGER_GUID); + bioscfg_drv.integer_data =3D kcalloc(bioscfg_drv.integer_instances_count, + sizeof(*bioscfg_drv.integer_data), GFP_KERNEL); + + if (!bioscfg_drv.integer_data) { + bioscfg_drv.integer_instances_count =3D 0; + return -ENOMEM; + } + return 0; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_integer_types[] =3D { + [NAME] =3D ACPI_TYPE_STRING, + [VALUE] =3D ACPI_TYPE_STRING, + [PATH] =3D ACPI_TYPE_STRING, + [IS_READONLY] =3D ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] =3D ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] =3D ACPI_TYPE_INTEGER, + [SEQUENCE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES] =3D ACPI_TYPE_STRING, + [SECURITY_LEVEL] =3D ACPI_TYPE_INTEGER, + [INT_LOWER_BOUND] =3D ACPI_TYPE_INTEGER, + [INT_UPPER_BOUND] =3D ACPI_TYPE_INTEGER, + [INT_SCALAR_INCREMENT] =3D ACPI_TYPE_INTEGER, +}; + +static int hp_populate_integer_elements_from_package(union acpi_object *in= teger_obj, + int integer_obj_count, + int instance_id) +{ + char *str_value =3D NULL; + int value_len; + int ret; + u32 int_value; + int elem; + int reqs; + int eloc; + int size; + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + if (!integer_obj) + return -EINVAL; + + for (elem =3D 1, eloc =3D 1; elem < integer_obj_count; elem++, eloc++) { + /* ONLY look at the first INTEGER_ELEM_CNT elements */ + if (eloc =3D=3D INT_ELEM_CNT) + goto exit_integer_package; + + switch (integer_obj[elem].type) { + case ACPI_TYPE_STRING: + if (elem !=3D PREREQUISITES) { + ret =3D hp_convert_hexstr_to_str(integer_obj[elem].string.pointer, + integer_obj[elem].string.length, + &str_value, &value_len); + if (ret) + continue; + } + break; + case ACPI_TYPE_INTEGER: + int_value =3D (u32)integer_obj[elem].integer.value; + break; + default: + pr_warn("Unsupported object type [%d]\n", integer_obj[elem].type); + continue; + } + /* Check that both expected and read object type match */ + if (expected_integer_types[eloc] !=3D integer_obj[elem].type) { + pr_err("Error expected type %d for elem %d, but got type %d instead\n", + expected_integer_types[eloc], elem, integer_obj[elem].type); + return -EIO; + } + /* Assign appropriate element value to corresponding field*/ + switch (eloc) { + case VALUE: + ret =3D kstrtoint(str_value, 10, &int_value); + if (ret) + continue; + + integer_data->current_value =3D int_value; + break; + case PATH: + strscpy(integer_data->common.path, str_value, + sizeof(integer_data->common.path)); + break; + case IS_READONLY: + integer_data->common.is_readonly =3D int_value; + break; + case DISPLAY_IN_UI: + integer_data->common.display_in_ui =3D int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + integer_data->common.requires_physical_presence =3D int_value; + break; + case SEQUENCE: + integer_data->common.sequence =3D int_value; + break; + case PREREQUISITES_SIZE: + if (integer_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of eleme= nts supported or data may be malformed\n"); + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (integer_data->common.prerequisites_size =3D=3D 0) + eloc++; + break; + case PREREQUISITES: + size =3D min_t(u32, integer_data->common.prerequisites_size, MAX_PREREQ= UISITES_SIZE); + + for (reqs =3D 0; reqs < size; reqs++) { + if (elem >=3D integer_obj_count) { + pr_err("Error elem-objects package is too small\n"); + return -EINVAL; + } + + ret =3D hp_convert_hexstr_to_str(integer_obj[elem + reqs].string.point= er, + integer_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(integer_data->common.prerequisites[reqs], + str_value, + sizeof(integer_data->common.prerequisites[reqs])); + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + integer_data->common.security_level =3D int_value; + break; + case INT_LOWER_BOUND: + integer_data->lower_bound =3D int_value; + break; + case INT_UPPER_BOUND: + integer_data->upper_bound =3D int_value; + break; + case INT_SCALAR_INCREMENT: + integer_data->scalar_increment =3D int_value; + break; + default: + pr_warn("Invalid element: %d found in Integer attribute or data may be = malformed\n", elem); + break; + } + } +exit_integer_package: + kfree(str_value); + return 0; +} + +/** + * hp_populate_integer_package_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 hp_populate_integer_package_data(union acpi_object *integer_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + integer_data->attr_name_kobj =3D attr_name_kobj; + hp_populate_integer_elements_from_package(integer_obj, + integer_obj->package.count, + instance_id); + hp_update_attribute_permissions(integer_data->common.is_readonly, + &integer_current_val); + hp_friendly_user_name_update(integer_data->common.path, + attr_name_kobj->name, + integer_data->common.display_name, + sizeof(integer_data->common.display_name)); + return sysfs_create_group(attr_name_kobj, &integer_attr_group); +} + +static int hp_populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *b= uffer_size, + int instance_id) +{ + char *dst =3D NULL; + int reqs; + int ret; + int dst_size =3D *buffer_size / sizeof(u16); + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + dst =3D kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + /* + * Only data relevant to this driver and its functionality is + * read. BIOS defines the order in which each * element is + * read. Element 0 data is not relevant to this + * driver hence it is ignored. For clarity, all element names + * (DISPLAY_IN_UI) which defines the order in which is read + * and the name matches the variable where the data is stored. + */ + + /* + * In earlier implementation, reported errors were ignored + * causing the data to remain uninitialized. It is for this + * reason functions may return an error and no validation + * takes place. + */ + + // VALUE: + integer_data->current_value =3D 0; + + hp_get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + ret =3D kstrtoint(dst, 10, &integer_data->current_value); + if (ret) + pr_warn("Unable to convert string to integer: %s\n", dst); + kfree(dst); + + // PATH: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, integer_data->common.= path, + sizeof(integer_data->common.path)); + + // IS_READONLY: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.is_readonly); + + //DISPLAY_IN_UI: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.display_in_ui); + + // REQUIRES_PHYSICAL_PRESENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.requires_physical_presence); + + // SEQUENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.sequence); + + // PREREQUISITES_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.prerequisites_size); + + if (integer_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) { + /* Report a message and limit prerequisite size to maximum value */ + pr_warn("Integer Prerequisites size value exceeded the maximum number of= elements supported or data may be malformed\n"); + integer_data->common.prerequisites_size =3D MAX_PREREQUISITES_SIZE; + } + + // PREREQUISITES: + for (reqs =3D 0; reqs < integer_data->common.prerequisites_size; reqs++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + integer_data->common.prerequisites[reqs], + sizeof(integer_data->common.prerequisites[reqs])); + + // SECURITY_LEVEL: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->common.security_level); + + // INT_LOWER_BOUND: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->lower_bound); + + // INT_UPPER_BOUND: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->upper_bound); + + // INT_SCALAR_INCREMENT: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &integer_data->scalar_increment); + + return 0; +} + +/** + * hp_populate_integer_buffer_data() - + * Populate all properties of an instance under integer attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int = instance_id, + struct kobject *attr_name_kobj) +{ + struct integer_data *integer_data =3D &bioscfg_drv.integer_data[instance_= id]; + + integer_data->attr_name_kobj =3D attr_name_kobj; + + /* Populate integer elements */ + hp_populate_integer_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + hp_update_attribute_permissions(integer_data->common.is_readonly, + &integer_current_val); + hp_friendly_user_name_update(integer_data->common.path, + attr_name_kobj->name, + integer_data->common.display_name, + sizeof(integer_data->common.display_name)); + + return sysfs_create_group(attr_name_kobj, &integer_attr_group); +} + +/** + * hp_exit_integer_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void hp_exit_integer_attributes(void) +{ + int instance_id; + + for (instance_id =3D 0; instance_id < bioscfg_drv.integer_instances_count; + instance_id++) { + struct kobject *attr_name_kobj =3D + bioscfg_drv.integer_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) + sysfs_remove_group(attr_name_kobj, &integer_attr_group); + } + bioscfg_drv.integer_instances_count =3D 0; + + kfree(bioscfg_drv.integer_data); + bioscfg_drv.integer_data =3D NULL; +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63520C7EE29 for ; Fri, 2 Jun 2023 13:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236054AbjFBNLV (ORCPT ); Fri, 2 Jun 2023 09:11:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235982AbjFBNLK (ORCPT ); Fri, 2 Jun 2023 09:11:10 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216FA1BF; Fri, 2 Jun 2023 06:10:56 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3909756b8b1so895729b6e.1; Fri, 02 Jun 2023 06:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711455; x=1688303455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=G49atfAQCgSCYBfeGPg2LE9mmP22glB+FYscmE+VeHo=; b=V3y8xygPuKwntv2luacIZqYS5YXadR5C40+Z/oZE4540GHYzZb3QcxtnRs9H1vojVm 6yRYN32/mwpJJB1Yge7Yfdq/afgmsyLsdi6mDg4VDD81Ol+3tPWwVTqLKkg4JTRih8rj tZuTdYkjw/9DUK87VQNISVuRlpy+QkTeW3rsSLg2y62Wo/CwMtoOHYTtMmmbfpR9U/Wc vnIJDMcTkVsryiU5QJuFQMVx+KRT02cNVNqd5VL0O4DkvjdCNWVwAHaCn8ZDRSRe1h/K BdIIRTbvPekR9Gzq7N8CmK00h2ta4YDOsDSq6EjTPUt/XRjXzZIaFOpXzjVnhSd35MrL 8zqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711455; x=1688303455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G49atfAQCgSCYBfeGPg2LE9mmP22glB+FYscmE+VeHo=; b=bjeOAA02Mm5HXdWSy90s2HwthUMOSRuXtKz8r7S3gBq4s2OHjbPGvOm49XtRVOMglc KV/btdTiPyq7qqrZna1QsY/ZaCpZvSwQG2TUosyt4XVRvUAiv+IA2HWGU4TXnxu/ITV8 YfZ9k6PE/nrYSeQY6w8OuhPJuOg97YsR67mN81efhu4/pLRuvvteu+7uN+IOIRsZDAs+ DEc3D/vBo6mq2yahbeyd/d/rk0LzDHHE48DRaqPXutcl+JCZfy/whDEFuG7dedkh8Oxx 7n10YwviIP4hjWalZEsAHWBZfdmcLGkCf5RTlrJkMQLtZnv85M9SPCGarilLI/F8Wiy9 VYpg== X-Gm-Message-State: AC+VfDyuUFn9LBw7TM0M8stHvchEH7RT+VqAMTlaRDPXaRPC0EhFi5Yx kGEFfIFckkQvwfr4P1ve3VA= X-Google-Smtp-Source: ACHHUZ6CNgEZPSrzXw36MTbhl32T1ti10S+QwiuuQkQgb5f0Halk+Tif3zQgJ4fcjUwbAVxBC1KAEw== X-Received: by 2002:a54:4691:0:b0:39a:815d:8ab6 with SMTP id k17-20020a544691000000b0039a815d8ab6mr607187oic.34.1685711455246; Fri, 02 Jun 2023 06:10:55 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:54 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 07/13] hp-bioscfg: order-list-attributes Date: Fri, 2 Jun 2023 08:10:38 -0500 Message-Id: <20230602131044.3297-8-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/order-list-attributes.c | 451 ++++++++++++++++++ 1 file changed, 451 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/order-list-attribute= s.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c b/d= rivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c new file mode 100644 index 000000000000..6a4cb8e53108 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c @@ -0,0 +1,451 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to ordered list type attributes under + * BIOS ORDERED LIST GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" + +GET_INSTANCE_ID(ordered_list); + +static ssize_t current_value_show(struct kobject *kobj, struct kobj_attrib= ute *attr, char *buf) +{ + int instance_id =3D get_ordered_list_instance_id(kobj); + + if (instance_id < 0) + return -EIO; + + return sysfs_emit(buf, "%s\n", + bioscfg_drv.ordered_list_data[instance_id].current_value); +} + +static int replace_char_str(u8 *buffer, char *repl_char, char *repl_with) +{ + char *src =3D buffer; + int buflen =3D strlen(buffer); + int item; + + if (buflen < 1) + return -EINVAL; + + for (item =3D 0; item < buflen; item++) + if (src[item] =3D=3D *repl_char) + src[item] =3D *repl_with; + + return 0; +} + +/** + * validate_ordered_list_input() - + * Validate input of current_value against possible values + * + * @instance: The instance on which input is validated + * @buf: Input value + */ +static int validate_ordered_list_input(int instance, char *buf) +{ + /* validation is done by BIOS. This validation function will + * convert semicolon to commas. BIOS uses commas as + * separators when reporting ordered-list values. + */ + return replace_char_str(buf, SEMICOLON_SEP, COMMA_SEP); +} + +static void update_ordered_list_value(int instance, char *attr_value) +{ + struct ordered_list_data *ordered_list_data =3D &bioscfg_drv.ordered_list= _data[instance]; + + strscpy(ordered_list_data->current_value, + attr_value, + sizeof(ordered_list_data->current_value)); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, ordered_list); +static struct kobj_attribute ordered_list_display_name =3D + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, ordered_list); +static struct kobj_attribute ordered_list_current_val =3D + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(elements, ordered_list, SEMICOLON_SEP); +static struct kobj_attribute ordered_list_elements_val =3D + __ATTR_RO(elements); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "ordered-list\n"); +} + +static struct kobj_attribute ordered_list_type =3D + __ATTR_RO(type); + +static struct attribute *ordered_list_attrs[] =3D { + &common_display_langcode.attr, + &ordered_list_display_name.attr, + &ordered_list_current_val.attr, + &ordered_list_elements_val.attr, + &ordered_list_type.attr, + NULL +}; + +static const struct attribute_group ordered_list_attr_group =3D { + .attrs =3D ordered_list_attrs, +}; + +int hp_alloc_ordered_list_data(void) +{ + bioscfg_drv.ordered_list_instances_count =3D + hp_get_instance_count(HP_WMI_BIOS_ORDERED_LIST_GUID); + bioscfg_drv.ordered_list_data =3D kcalloc(bioscfg_drv.ordered_list_instan= ces_count, + sizeof(*bioscfg_drv.ordered_list_data), + GFP_KERNEL); + if (!bioscfg_drv.ordered_list_data) { + bioscfg_drv.ordered_list_instances_count =3D 0; + return -ENOMEM; + } + return 0; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_order_types[] =3D { + [NAME] =3D ACPI_TYPE_STRING, + [VALUE] =3D ACPI_TYPE_STRING, + [PATH] =3D ACPI_TYPE_STRING, + [IS_READONLY] =3D ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] =3D ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] =3D ACPI_TYPE_INTEGER, + [SEQUENCE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES] =3D ACPI_TYPE_STRING, + [SECURITY_LEVEL] =3D ACPI_TYPE_INTEGER, + [ORD_LIST_SIZE] =3D ACPI_TYPE_INTEGER, + [ORD_LIST_ELEMENTS] =3D ACPI_TYPE_STRING, +}; + +static int hp_populate_ordered_list_elements_from_package(union acpi_objec= t *order_obj, + int order_obj_count, + int instance_id) +{ + char *str_value =3D NULL; + int value_len; + int ret; + u32 size; + u32 int_value; + int elem; + int reqs; + int eloc; + char *tmpstr =3D NULL; + char *part_tmp =3D NULL; + int tmp_len =3D 0; + char *part =3D NULL; + struct ordered_list_data *ordered_list_data =3D &bioscfg_drv.ordered_list= _data[instance_id]; + + if (!order_obj) + return -EINVAL; + + for (elem =3D 1, eloc =3D 1; elem < order_obj_count; elem++, eloc++) { + /* ONLY look at the first ORDERED_ELEM_CNT elements */ + if (eloc =3D=3D ORD_ELEM_CNT) + goto exit_list; + + switch (order_obj[elem].type) { + case ACPI_TYPE_STRING: + if (elem !=3D PREREQUISITES && elem !=3D ORD_LIST_ELEMENTS) { + ret =3D hp_convert_hexstr_to_str(order_obj[elem].string.pointer, + order_obj[elem].string.length, + &str_value, &value_len); + if (ret) + continue; + } + break; + case ACPI_TYPE_INTEGER: + int_value =3D (u32)order_obj[elem].integer.value; + break; + default: + pr_warn("Unsupported object type [%d]\n", order_obj[elem].type); + continue; + } + + /* Check that both expected and read object type match */ + if (expected_order_types[eloc] !=3D order_obj[elem].type) { + pr_err("Error expected type %d for elem %d, but got type %d instead\n", + expected_order_types[eloc], elem, order_obj[elem].type); + return -EIO; + } + + /* Assign appropriate element value to corresponding field*/ + switch (eloc) { + case VALUE: + strscpy(ordered_list_data->current_value, + str_value, sizeof(ordered_list_data->current_value)); + replace_char_str(ordered_list_data->current_value, COMMA_SEP, SEMICOLON= _SEP); + break; + case PATH: + strscpy(ordered_list_data->common.path, str_value, + sizeof(ordered_list_data->common.path)); + break; + case IS_READONLY: + ordered_list_data->common.is_readonly =3D int_value; + break; + case DISPLAY_IN_UI: + ordered_list_data->common.display_in_ui =3D int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + ordered_list_data->common.requires_physical_presence =3D int_value; + break; + case SEQUENCE: + ordered_list_data->common.sequence =3D int_value; + break; + case PREREQUISITES_SIZE: + ordered_list_data->common.prerequisites_size =3D int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of eleme= nts supported or data may be malformed\n"); + + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + case PREREQUISITES: + size =3D min_t(u32, ordered_list_data->common.prerequisites_size, + MAX_PREREQUISITES_SIZE); + for (reqs =3D 0; reqs < size; reqs++) { + ret =3D hp_convert_hexstr_to_str(order_obj[elem + reqs].string.pointer, + order_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(ordered_list_data->common.prerequisites[reqs], + str_value, + sizeof(ordered_list_data->common.prerequisites[reqs])); + + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + ordered_list_data->common.security_level =3D int_value; + break; + + case ORD_LIST_SIZE: + ordered_list_data->elements_size =3D int_value; + if (int_value > MAX_ELEMENTS_SIZE) + pr_warn("Ordered List size value exceeded the maximum number of elemen= ts supported or data may be malformed\n"); + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. ORD_LIST_ELEMENTS + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + case ORD_LIST_ELEMENTS: + size =3D ordered_list_data->elements_size; + + /* + * Ordered list data is stored in hex and comma separated format + * Convert the data and split it to show each element + */ + ret =3D hp_convert_hexstr_to_str(str_value, value_len, &tmpstr, &tmp_le= n); + if (ret) + goto exit_list; + + part_tmp =3D tmpstr; + part =3D strsep(&part_tmp, COMMA_SEP); + if (!part) + strscpy(ordered_list_data->elements[0], + tmpstr, + sizeof(ordered_list_data->elements[0])); + + for (elem =3D 1; elem < MAX_ELEMENTS_SIZE && part; elem++) { + strscpy(ordered_list_data->elements[elem], + part, + sizeof(ordered_list_data->elements[elem])); + part =3D strsep(&part_tmp, SEMICOLON_SEP); + } + + break; + default: + pr_warn("Invalid element: %d found in Ordered_List attribute or data ma= y be malformed\n", elem); + break; + } + kfree(tmpstr); + kfree(str_value); + } + +exit_list: + kfree(tmpstr); + kfree(str_value); + return 0; +} + +/** + * hp_populate_ordered_list_package_data() - + * Populate all properties of an instance under ordered_list attribute + * + * @order_obj: ACPI object with ordered_list data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_ordered_list_package_data(union acpi_object *order_obj, in= t instance_id, + struct kobject *attr_name_kobj) +{ + struct ordered_list_data *ordered_list_data =3D &bioscfg_drv.ordered_list= _data[instance_id]; + + ordered_list_data->attr_name_kobj =3D attr_name_kobj; + + hp_populate_ordered_list_elements_from_package(order_obj, + order_obj->package.count, + instance_id); + hp_update_attribute_permissions(ordered_list_data->common.is_readonly, + &ordered_list_current_val); + hp_friendly_user_name_update(ordered_list_data->common.path, + attr_name_kobj->name, + ordered_list_data->common.display_name, + sizeof(ordered_list_data->common.display_name)); + return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group); +} + +static int hp_populate_ordered_list_elements_from_buffer(u8 *buffer_ptr, u= 32 *buffer_size, + int instance_id) +{ + int reqs; + int values; + struct ordered_list_data *ordered_list_data =3D &bioscfg_drv.ordered_list= _data[instance_id]; + + /* + * In earlier implementation, reported errors were ignored + * causing the data to remain uninitialized. It is for this + * reason functions may return an error and no validation + * takes place. + */ + + // VALUE: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, ordered_list_data->cu= rrent_value, + sizeof(ordered_list_data->current_value)); + replace_char_str(ordered_list_data->current_value, COMMA_SEP, SEMICOLON_S= EP); + + // PATH: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, ordered_list_data->co= mmon.path, + sizeof(ordered_list_data->common.path)); + + // IS_READONLY: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.is_readonly); + + //DISPLAY_IN_UI: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.display_in_ui); + + // REQUIRES_PHYSICAL_PRESENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.requires_physical_presence); + + // SEQUENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.sequence); + + // PREREQUISITES_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.prerequisites_size); + + if (ordered_list_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE= ) { + /* Report a message and limit prerequisite size to maximum value */ + pr_warn("String Prerequisites size value exceeded the maximum number of = elements supported or data may be malformed\n"); + ordered_list_data->common.prerequisites_size =3D MAX_PREREQUISITES_SIZE; + } + + // PREREQUISITES: + for (reqs =3D 0; reqs < ordered_list_data->common.prerequisites_size; req= s++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + ordered_list_data->common.prerequisites[reqs], + sizeof(ordered_list_data->common.prerequisites[reqs])); + + // SECURITY_LEVEL: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->common.security_level); + + // ORD_LIST_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &ordered_list_data->elements_size); + + if (ordered_list_data->elements_size > MAX_ELEMENTS_SIZE) { + /* Report a message and limit elements size to maximum value */ + pr_warn("Ordered List size value exceeded the maximum number of elements= supported or data may be malformed\n"); + ordered_list_data->elements_size =3D MAX_ELEMENTS_SIZE; + } + + // ORD_LIST_ELEMENTS: + for (values =3D 0; values < ordered_list_data->elements_size; values++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + ordered_list_data->elements[values], + sizeof(ordered_list_data->elements[values])); + + return 0; +} + +/** + * hp_populate_ordered_list_buffer_data() - Populate all properties of an + * instance under ordered list attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_ordered_list_buffer_data(u8 *buffer_ptr, u32 *buffer_size,= int instance_id, + struct kobject *attr_name_kobj) +{ + struct ordered_list_data *ordered_list_data =3D &bioscfg_drv.ordered_list= _data[instance_id]; + + ordered_list_data->attr_name_kobj =3D attr_name_kobj; + + /* Populate ordered list elements */ + hp_populate_ordered_list_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + hp_update_attribute_permissions(ordered_list_data->common.is_readonly, + &ordered_list_current_val); + hp_friendly_user_name_update(ordered_list_data->common.path, + attr_name_kobj->name, + ordered_list_data->common.display_name, + sizeof(ordered_list_data->common.display_name)); + + return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group); +} + +/** + * hp_exit_ordered_list_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void hp_exit_ordered_list_attributes(void) +{ + int instance_id; + + for (instance_id =3D 0; instance_id < bioscfg_drv.ordered_list_instances_= count; + instance_id++) { + struct kobject *attr_name_kobj =3D + bioscfg_drv.ordered_list_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) + sysfs_remove_group(attr_name_kobj, + &ordered_list_attr_group); + } + bioscfg_drv.ordered_list_instances_count =3D 0; + + kfree(bioscfg_drv.ordered_list_data); + bioscfg_drv.ordered_list_data =3D NULL; +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D6B2C7EE24 for ; Fri, 2 Jun 2023 13:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236016AbjFBNL0 (ORCPT ); Fri, 2 Jun 2023 09:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbjFBNLK (ORCPT ); Fri, 2 Jun 2023 09:11:10 -0400 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6FAE43; Fri, 2 Jun 2023 06:10:57 -0700 (PDT) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5523bd97c64so2232714eaf.0; Fri, 02 Jun 2023 06:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711456; x=1688303456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2opJ1+W5HOUNs6DOaSrjyXEyOXFf95SoCXdS03bl+3g=; b=a7rvZb3Vn6syKz5kJateGXUkkq4A2du+cWVTQx50PTbneY5bfaFfu6hRqPhgMmebhS 5Qb702Snw+5MSUWdvZ7ZuStKZRZLapVHgkIF8eZVSfm9ID/1144yt5MoguBQWRnNRX5j HTnCiPq9qxBZfRZlUQxwGq2bg6UTgZLYwZnnT3JzPzsmGRURTMoJneCau6Jhj4sfnUfI 4Ho0DIMCdFjb45mwcGdDFsaG4lb6izt43enTOcyFbuBL2BRo3VvFXYzoJD7b0vicYs8H czuCnhWdFkS6gNdKT/udAclpbpHpomo/emn0KMvVdFz82BZ3YaZ9qKIp0719mx1bWoxl 5h0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711456; x=1688303456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2opJ1+W5HOUNs6DOaSrjyXEyOXFf95SoCXdS03bl+3g=; b=arJMp9o8OoJExcPptEmQn8JqkE0ZVj+39UNfknPERyWgjGiD/P4u+4w6/eBf03FiBf ceONrDyIxaUj/R7x9tfoWPS9xgsBqZZdm/072cJtXurWWC8UhzTlTGzehjVb6w3BOv/z MbPEXWvXJFYZAf03zdaiQmBn0GLf87rx66wG+XvQNVVPFh16od0GBvLn6ih9MwJuvC0q dx5S+1liZbpZibGPXa/Kc92iqiFdz7DiWev81LLN0QZ1OMpYjuN341UomtapNMiFG6v/ 5SKKidpZAmdlXNcirEXcT7Du1G/KCzb0Wrlr/D343/l7fMPESivrplwfJxAMaO8y9dE+ 8xlA== X-Gm-Message-State: AC+VfDw+21OBRbz/lhpHFy+1Mo4aNv7llZzNb2VskbR56kmaBvfZmMrD tP5VkpTkVbzxPRIFTJwTzec= X-Google-Smtp-Source: ACHHUZ5ZRsR4RM986s0IlG2EcdEz48nTvFmXe1mL4bYHWvz5OG7f3TNuO/VVNsbE2DCKWUpm45FQug== X-Received: by 2002:a05:6808:3ae:b0:38e:d57:1979 with SMTP id n14-20020a05680803ae00b0038e0d571979mr1187070oie.23.1685711456562; Fri, 02 Jun 2023 06:10:56 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:56 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 08/13] hp-bioscfg: passwdobj-attributes Date: Fri, 2 Jun 2023 08:10:39 -0500 Message-Id: <20230602131044.3297-9-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/passwdobj-attributes.c | 540 ++++++++++++++++++ 1 file changed, 540 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes= .c diff --git a/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c b/dr= ivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c new file mode 100644 index 000000000000..483426696144 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c @@ -0,0 +1,540 @@ +// 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 + +GET_INSTANCE_ID(password); +/* + * Clear all passwords copied to memory for a particular + * authentication instance + */ +static int clear_passwords(const int instance) +{ + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce]; + + if (!password_data->is_enabled) + return 0; + + memset(password_data->current_password, + 0, sizeof(password_data->current_password)); + memset(password_data->new_password, + 0, sizeof(password_data->new_password)); + + return 0; +} + +/* + * Clear all credentials copied to memory for both Power-ON and Setup + * BIOS instances + */ +int hp_clear_all_credentials(void) +{ + int count =3D bioscfg_drv.password_instances_count; + int instance; + + /* clear all passwords */ + for (instance =3D 0; instance < count; instance++) + clear_passwords(instance); + + /* clear auth_token */ + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token =3D NULL; + + return 0; +} + +int hp_get_password_instance_for_type(const char *name) +{ + int count =3D bioscfg_drv.password_instances_count; + int instance; + + for (instance =3D 0; instance < count; instance++) + if (!strcmp(bioscfg_drv.password_data[instance].common.display_name, nam= e)) + return instance; + + return -EINVAL; +} + +static int validate_password_input(int instance_id, const char *buf) +{ + int length; + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce_id]; + + length =3D strlen(buf); + if (buf[length - 1] =3D=3D '\n') + length--; + + if (length > MAX_PASSWD_SIZE) + return INVALID_BIOS_AUTH; + + if (password_data->min_password_length > length || + password_data->max_password_length < length) + return INVALID_BIOS_AUTH; + return SUCCESS; +} + +ATTRIBUTE_N_PROPERTY_SHOW(is_enabled, password); +static struct kobj_attribute password_is_password_set =3D __ATTR_RO(is_ena= bled); + +static int store_password_instance(struct kobject *kobj, const char *buf, + size_t count, bool is_current) +{ + char *buf_cp; + int id, ret =3D 0; + + buf_cp =3D kstrdup(buf, GFP_KERNEL); + if (!buf_cp) + return -ENOMEM; + + ret =3D hp_enforce_single_line_input(buf_cp, count); + if (!ret) { + id =3D get_password_instance_id(kobj); + + if (id >=3D 0) + ret =3D validate_password_input(id, buf_cp); + } + + if (!ret) { + if (is_current) + strscpy(bioscfg_drv.password_data[id].current_password, + buf_cp, + sizeof(bioscfg_drv.password_data[id].current_password)); + else + strscpy(bioscfg_drv.password_data[id].new_password, + buf_cp, + sizeof(bioscfg_drv.password_data[id].new_password)); + } + + kfree(buf_cp); + return ret < 0 ? ret : count; +} + +static ssize_t current_password_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + return store_password_instance(kobj, buf, count, true); +} + +static struct kobj_attribute password_current_password =3D __ATTR_WO(curre= nt_password); + +static ssize_t new_password_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + return store_password_instance(kobj, buf, count, true); +} + +static struct kobj_attribute password_new_password =3D __ATTR_WO(new_passw= ord); + +ATTRIBUTE_N_PROPERTY_SHOW(min_password_length, password); +static struct kobj_attribute password_min_password_length =3D __ATTR_RO(mi= n_password_length); + +ATTRIBUTE_N_PROPERTY_SHOW(max_password_length, password); +static struct kobj_attribute password_max_password_length =3D __ATTR_RO(ma= x_password_length); + +static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr= , char *buf) +{ + if (!strcmp(kobj->name, SETUP_PASSWD)) + return sysfs_emit(buf, "%s\n", BIOS_ADMIN); + + if (!strcmp(kobj->name, POWER_ON_PASSWD)) + return sysfs_emit(buf, "%s\n", POWER_ON); + + return -EIO; +} + +static struct kobj_attribute password_role =3D __ATTR_RO(role); + +static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute = *attr, + char *buf) +{ + int i =3D get_password_instance_id(kobj); + + if (i < 0) + return i; + + if (bioscfg_drv.password_data[i].mechanism !=3D PASSWORD) + return -EINVAL; + + return sysfs_emit(buf, "%s\n", PASSWD_MECHANISM_TYPES); +} + +static struct kobj_attribute password_mechanism =3D __ATTR_RO(mechanism); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(encodings, password, SEMICOLON_SEP); +static struct kobj_attribute password_encodings_val =3D __ATTR_RO(encoding= s); + +static struct attribute *password_attrs[] =3D { + &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_encodings_val.attr, + NULL +}; + +static const struct attribute_group password_attr_group =3D { + .attrs =3D password_attrs +}; + +int hp_alloc_password_data(void) +{ + bioscfg_drv.password_instances_count =3D hp_get_instance_count(HP_WMI_BIO= S_PASSWORD_GUID); + bioscfg_drv.password_data =3D kcalloc(bioscfg_drv.password_instances_coun= t, + sizeof(*bioscfg_drv.password_data), GFP_KERNEL); + if (!bioscfg_drv.password_data) { + bioscfg_drv.password_instances_count =3D 0; + return -ENOMEM; + } + + return 0; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_password_types[] =3D { + [NAME] =3D ACPI_TYPE_STRING, + [VALUE] =3D ACPI_TYPE_STRING, + [PATH] =3D ACPI_TYPE_STRING, + [IS_READONLY] =3D ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] =3D ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] =3D ACPI_TYPE_INTEGER, + [SEQUENCE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES] =3D ACPI_TYPE_STRING, + [SECURITY_LEVEL] =3D ACPI_TYPE_INTEGER, + [PSWD_MIN_LENGTH] =3D ACPI_TYPE_INTEGER, + [PSWD_MAX_LENGTH] =3D ACPI_TYPE_INTEGER, + [PSWD_SIZE] =3D ACPI_TYPE_INTEGER, + [PSWD_ENCODINGS] =3D ACPI_TYPE_STRING, + [PSWD_IS_SET] =3D ACPI_TYPE_INTEGER, +}; + +static int hp_populate_password_elements_from_package(union acpi_object *p= assword_obj, + int password_obj_count, + int instance_id) +{ + char *str_value =3D NULL; + int value_len; + int ret; + u32 size; + u32 int_value; + int elem; + int reqs; + int eloc; + int pos_values; + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce_id]; + + if (!password_obj) + return -EINVAL; + + for (elem =3D 1, eloc =3D 1; elem < password_obj_count; elem++, eloc++) { + /* ONLY look at the first PASSWORD_ELEM_CNT elements */ + if (eloc =3D=3D PSWD_ELEM_CNT) + goto exit_package; + + switch (password_obj[elem].type) { + case ACPI_TYPE_STRING: + if (PREREQUISITES !=3D elem && PSWD_ENCODINGS !=3D elem) { + ret =3D hp_convert_hexstr_to_str(password_obj[elem].string.pointer, + password_obj[elem].string.length, + &str_value, &value_len); + if (ret) + continue; + } + break; + case ACPI_TYPE_INTEGER: + int_value =3D (u32)password_obj[elem].integer.value; + break; + default: + pr_warn("Unsupported object type [%d]\n", password_obj[elem].type); + continue; + } + + /* Check that both expected and read object type match */ + if (expected_password_types[eloc] !=3D password_obj[elem].type) { + pr_err("Error expected type %d for elem %d, but got type %d instead\n", + expected_password_types[eloc], elem, password_obj[elem].type); + return -EIO; + } + + /* Assign appropriate element value to corresponding field*/ + switch (eloc) { + case VALUE: + break; + case PATH: + strscpy(password_data->common.path, str_value, + sizeof(password_data->common.path)); + break; + case IS_READONLY: + password_data->common.is_readonly =3D int_value; + break; + case DISPLAY_IN_UI: + password_data->common.display_in_ui =3D int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + password_data->common.requires_physical_presence =3D int_value; + break; + case SEQUENCE: + password_data->common.sequence =3D int_value; + break; + case PREREQUISITES_SIZE: + password_data->common.prerequisites_size =3D int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of eleme= nts supported or data may be malformed\n"); + + /* This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + case PREREQUISITES: + size =3D min_t(u32, password_data->common.prerequisites_size, + MAX_PREREQUISITES_SIZE); + + for (reqs =3D 0; reqs < size; reqs++) { + ret =3D hp_convert_hexstr_to_str(password_obj[elem + reqs].string.poin= ter, + password_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + break; + + strscpy(password_data->common.prerequisites[reqs], + str_value, + sizeof(password_data->common.prerequisites[reqs])); + + kfree(str_value); + } + break; + case SECURITY_LEVEL: + password_data->common.security_level =3D int_value; + break; + case PSWD_MIN_LENGTH: + password_data->min_password_length =3D int_value; + break; + case PSWD_MAX_LENGTH: + password_data->max_password_length =3D int_value; + break; + case PSWD_SIZE: + password_data->encodings_size =3D int_value; + if (int_value > MAX_ENCODINGS_SIZE) + pr_warn("Password Encoding size value exceeded the maximum number of e= lements supported or data may be malformed\n"); + + /* This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PSWD_ENCODINGS + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value =3D=3D 0) + eloc++; + break; + case PSWD_ENCODINGS: + size =3D min_t(u32, password_data->encodings_size, MAX_ENCODINGS_SIZE); + for (pos_values =3D 0; pos_values < size; pos_values++) { + ret =3D hp_convert_hexstr_to_str(password_obj[elem + pos_values].strin= g.pointer, + password_obj[elem + pos_values].string.length, + &str_value, &value_len); + if (ret) + break; + + strscpy(password_data->encodings[pos_values], + str_value, + sizeof(password_data->encodings[pos_values])); + kfree(str_value); + } + break; + case PSWD_IS_SET: + password_data->is_enabled =3D int_value; + break; + default: + pr_warn("Invalid element: %d found in Password attribute or data may be= malformed\n", elem); + break; + } + } + +exit_package: + kfree(str_value); + return 0; +} + +/** + * hp_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 hp_populate_password_package_data(union acpi_object *password_obj, int= instance_id, + struct kobject *attr_name_kobj) +{ + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce_id]; + + password_data->attr_name_kobj =3D attr_name_kobj; + + hp_populate_password_elements_from_package(password_obj, + password_obj->package.count, + instance_id); + + hp_friendly_user_name_update(password_data->common.path, + attr_name_kobj->name, + password_data->common.display_name, + sizeof(password_data->common.display_name)); + + if (!strcmp(attr_name_kobj->name, SETUP_PASSWD)) + return sysfs_create_group(attr_name_kobj, &password_attr_group); + + return sysfs_create_group(attr_name_kobj, &password_attr_group); +} + +static int hp_populate_password_elements_from_buffer(u8 *buffer_ptr, u32 *= buffer_size, + int instance_id) +{ + int reqs; + int values; + int isreadonly; + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce_id]; + + // VALUE: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, password_data->curren= t_password, + sizeof(password_data->current_password)); + + // PATH: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, password_data->common= .path, + sizeof(password_data->common.path)); + + // IS_READONLY: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.is_readonly); + + //DISPLAY_IN_UI: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.display_in_ui); + + // REQUIRES_PHYSICAL_PRESENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.requires_physical_presence); + + // SEQUENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.sequence); + + // PREREQUISITES_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.prerequisites_size); + + if (password_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) { + /* Report a message and limit prerequisite size to maximum value */ + pr_warn("Password Prerequisites size value exceeded the maximum number o= f elements supported or data may be malformed\n"); + password_data->common.prerequisites_size =3D MAX_PREREQUISITES_SIZE; + } + + // PREREQUISITES: + for (reqs =3D 0; reqs < password_data->common.prerequisites_size; reqs++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + password_data->common.prerequisites[reqs], + sizeof(password_data->common.prerequisites[reqs])); + + // SECURITY_LEVEL: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->common.security_level); + + // PSWD_MIN_LENGTH: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->min_password_length); + + // PSWD_MAX_LENGTH: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &password_data->max_password_length); + + // PSWD_SIZE: + if (password_data->encodings_size > MAX_ENCODINGS_SIZE) { + /* Report a message and limit possible values size to maximum value */ + pr_warn("Password Encoding size value exceeded the maximum number of ele= ments supported or data may be malformed\n"); + password_data->encodings_size =3D MAX_ENCODINGS_SIZE; + } + + // PSWD_ENCODINGS: + for (values =3D 0; values < password_data->encodings_size; values++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + password_data->encodings[values], + sizeof(password_data->encodings[values])); + + // PSWD_IS_SET: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, &isreadonly); + password_data->is_enabled =3D isreadonly ? true : false; + + return 0; +} + +/** + * hp_populate_password_buffer_data() + * Populate all properties for an instance under password object attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int= instance_id, + struct kobject *attr_name_kobj) +{ + struct password_data *password_data =3D &bioscfg_drv.password_data[instan= ce_id]; + + password_data->attr_name_kobj =3D attr_name_kobj; + + /* Populate Password attributes */ + hp_populate_password_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + hp_friendly_user_name_update(password_data->common.path, + attr_name_kobj->name, + password_data->common.display_name, + sizeof(password_data->common.display_name)); + if (!strcmp(attr_name_kobj->name, SETUP_PASSWD)) + return sysfs_create_group(attr_name_kobj, &password_attr_group); + + return sysfs_create_group(attr_name_kobj, &password_attr_group); +} + +/** + * hp_exit_password_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void hp_exit_password_attributes(void) +{ + int instance_id; + + for (instance_id =3D 0; instance_id < bioscfg_drv.password_instances_coun= t; + instance_id++) { + struct kobject *attr_name_kobj =3D + bioscfg_drv.password_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) { + if (!strcmp(attr_name_kobj->name, SETUP_PASSWD)) + sysfs_remove_group(attr_name_kobj, + &password_attr_group); + else + sysfs_remove_group(attr_name_kobj, + &password_attr_group); + } + } + bioscfg_drv.password_instances_count =3D 0; + kfree(bioscfg_drv.password_data); + bioscfg_drv.password_data =3D NULL; +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01752C7EE29 for ; Fri, 2 Jun 2023 13:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236019AbjFBNLa (ORCPT ); Fri, 2 Jun 2023 09:11:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236022AbjFBNLL (ORCPT ); Fri, 2 Jun 2023 09:11:11 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465FAE4A; Fri, 2 Jun 2023 06:10:59 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6af6fe73f11so1913836a34.0; Fri, 02 Jun 2023 06:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711458; x=1688303458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5rcLh+ezPUZ3Wpmj87jem1GbMOx+BuJLTxVZIDGJ+Js=; b=SblYK8iDc268jkV/yI3Gw0WtNkRVlHcEwmXQ8mNRIc/2TeAyB9VPMiTyIadwb0PtPd r3IqePjLKgpRHWcOpKng2maF9cP7bcLD8UmRCNkLP/9ts5dyX+FSovOsqN4lDlmNvSkM rv/ZsuljztHkRuSFYQ6VH4KBIqe9/uZdSt3zWyupOu89DO3CuwZIa3tIFuznFc+grwUT jGN1fVx+u10a5l6zUrupWt798IaXYaIeS++6/BypgpQX5U2b0dnFrTl4CyB+oTgU1atG fuMtokfGugRFvTx/cwSllcDeyio4NkRlD8NuinIwZS8V/jZlgQD1yPPfEnj5rke5nBs+ jP3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711458; x=1688303458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5rcLh+ezPUZ3Wpmj87jem1GbMOx+BuJLTxVZIDGJ+Js=; b=RB3HcrcTU+1sG4NqHy9CwwO8wot3q9wKD8r98h4xwyV/sDCefDwyBma6+EmbSnKUPn /L/l/JtdL7YwhLIHcJVzQQJbaBf/e4bewPjJBwWiwY1x239/f/j5wN20c5qfQkTCmycp d+a3+WXfNDhP8Kv72n6OfRUCx82rVAUB5xJhLbo6+3RlXQvILI5ZXC4TFB3x5GCFN1pv oq0n3K7iunedorGdxt1rz1Obw97J12ckDdenErRHaFq0RslncsgkfdAAUOEzIOlqtNqa gl81Eem/uLlPkYEqp57LypEhyoK65rmJT2IoZ4U5wo1eJrxtlZ8PzvcS4fROulIvZHkf w7Fg== X-Gm-Message-State: AC+VfDyc/mMDjqjkQapwdvcOUDu8BtKc3lJ61y1vMXzmClYB8kvH0HX9 TCIXdH9CS0m4p+njNUpmGQA= X-Google-Smtp-Source: ACHHUZ7zvCQNTsDxfthFwpbKiLcPykqWm9PnveHqMrbPTBWJy7uBICbtwW9SeS/exNZx6Q3cFac9Qg== X-Received: by 2002:a05:6808:aae:b0:398:5a28:d80f with SMTP id r14-20020a0568080aae00b003985a28d80fmr2740571oij.4.1685711458355; Fri, 02 Jun 2023 06:10:58 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:58 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 09/13] hp-bioscfg: spmobj-attributes Date: Fri, 2 Jun 2023 08:10:40 -0500 Message-Id: <20230602131044.3297-10-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/spmobj-attributes.c | 386 ++++++++++++++++++ 1 file changed, 386 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c b/drive= rs/platform/x86/hp/hp-bioscfg/spmobj-attributes.c new file mode 100644 index 000000000000..02291e32684f --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c @@ -0,0 +1,386 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to secure platform management object type + * attributes under BIOS PASSWORD for use with hp-bioscfg driver + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" + +static const char * const spm_state_types[] =3D { + "not provisioned", + "provisioned", + "provisioning in progress", +}; + +static const char * const spm_mechanism_types[] =3D { + "not provisioned", + "signing-key", + "endorsement-key", +}; + +struct secureplatform_provisioning_data { + u8 state; + u8 version[2]; + u8 reserved1; + u32 features; + u32 nonce; + u8 reserved2[28]; + u8 sk_mod[MAX_KEY_MOD_SIZE]; + u8 kek_mod[MAX_KEY_MOD_SIZE]; +}; + +/** + * hp_calculate_security_buffer() - determines size of security buffer + * for authentication scheme + * + * @authentication: the authentication content + * + * Currently only supported type is Admin password + */ +size_t hp_calculate_security_buffer(const char *authentication) +{ + size_t size, authlen; + + if (!authentication) + return sizeof(u16) * 2; + + authlen =3D strlen(authentication); + if (!authlen) + return sizeof(u16) * 2; + + size =3D sizeof(u16) + authlen * sizeof(u16); + if (!strstarts(authentication, BEAM_PREFIX)) + size +=3D strlen(UTF_PREFIX) * sizeof(u16); + + return size; +} + +/** + * hp_populate_security_buffer() - builds a security buffer for + * authentication scheme + * + * @authbuf: the security buffer + * @authentication: the authentication content + * + * Currently only supported type is PLAIN TEXT + */ +int hp_populate_security_buffer(u16 *authbuf, const char *authentication) +{ + u16 *auth =3D authbuf; + char *strprefix =3D NULL; + int ret =3D 0; + + if (strstarts(authentication, BEAM_PREFIX)) { + /* + * BEAM_PREFIX is append to authbuf when a signature + * is provided and Sure Admin is enabled in BIOS + */ + /* BEAM_PREFIX found, convert part to unicode */ + auth =3D hp_ascii_to_utf16_unicode(auth, authentication); + if (!auth) + return -EINVAL; + + } else { + /* + * UTF-16 prefix is append to the * authbuf when a BIOS + * admin password is configured in BIOS + */ + + /* append UTF_PREFIX to part and then convert it to unicode */ + strprefix =3D kasprintf(GFP_KERNEL, "%s%s", UTF_PREFIX, + authentication); + if (!strprefix) + return -ENOMEM; + + auth =3D hp_ascii_to_utf16_unicode(auth, strprefix); + kfree(strprefix); + + if (!auth) { + ret =3D -EINVAL; + goto out_buffer; + } + } + +out_buffer: + return ret; +} + +static ssize_t update_spm_state(void) +{ + struct secureplatform_provisioning_data data; + int ret; + + ret =3D hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE, + HPWMI_SECUREPLATFORM, &data, 0, + sizeof(data)); + if (ret < 0) + return ret; + + bioscfg_drv.spm_data.mechanism =3D data.state; + if (bioscfg_drv.spm_data.mechanism) + bioscfg_drv.spm_data.is_enabled =3D 1; + + return 0; +} + +static ssize_t statusbin(struct kobject *kobj, + struct kobj_attribute *attr, + struct secureplatform_provisioning_data *buf) +{ + int ret =3D hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE, + HPWMI_SECUREPLATFORM, buf, 0, + sizeof(*buf)); + + if (ret < 0) + return ret; + + return sizeof(struct secureplatform_provisioning_data); +} + +/* + * status_show - Reads SPM status + */ +static ssize_t status_show(struct kobject *kobj, struct kobj_attribute + *attr, char *buf) +{ + int ret, i; + int len =3D 0; + struct secureplatform_provisioning_data data; + + ret =3D statusbin(kobj, attr, &data); + if (ret < 0) + return ret; + + /* + * 'status' is a read-only file that returns ASCII text in + * JSON format reporting the status information. + * + * "State": "not provisioned | provisioned | provisioning in progress ", + * "Version": " Major. Minor ", + * "Nonce": <16-bit unsigned number display in base 10>, + * "FeaturesInUse": <16-bit unsigned number display in base 10>, + * "EndorsementKeyMod": "<256 bytes in base64>", + * "SigningKeyMod": "<256 bytes in base64>" + */ + + len +=3D sysfs_emit_at(buf, len, "{\n"); + len +=3D sysfs_emit_at(buf, len, "\t\"State\": \"%s\",\n", + spm_state_types[data.state]); + len +=3D sysfs_emit_at(buf, len, "\t\"Version\": \"%d.%d\"", + data.version[0], data.version[1]); + + /* + * state =3D=3D 0 means secure platform management + * feature is not configured in BIOS. + */ + if (data.state =3D=3D 0) { + len +=3D sysfs_emit_at(buf, len, "\n"); + goto status_exit; + } else { + len +=3D sysfs_emit_at(buf, len, ",\n"); + } + + len +=3D sysfs_emit_at(buf, len, "\t\"Nonce\": %d,\n", data.nonce); + len +=3D sysfs_emit_at(buf, len, "\t\"FeaturesInUse\": %d,\n", data.featu= res); + len +=3D sysfs_emit_at(buf, len, "\t\"EndorsementKeyMod\": \""); + + for (i =3D 255; i >=3D 0; i--) + len +=3D sysfs_emit_at(buf, len, " %u", data.kek_mod[i]); + + len +=3D sysfs_emit_at(buf, len, " \",\n"); + len +=3D sysfs_emit_at(buf, len, "\t\"SigningKeyMod\": \""); + + for (i =3D 255; i >=3D 0; i--) + len +=3D sysfs_emit_at(buf, len, " %u", data.sk_mod[i]); + + /* Return buf contents */ + len +=3D sysfs_emit_at(buf, len, " \"\n"); + +status_exit: + len +=3D sysfs_emit_at(buf, len, "}\n"); + + return len; +} + +static struct kobj_attribute password_spm_status =3D __ATTR_RO(status); + +ATTRIBUTE_SPM_N_PROPERTY_SHOW(is_enabled, spm); +static struct kobj_attribute password_spm_is_key_enabled =3D __ATTR_RO(is_= enabled); + +static ssize_t key_mechanism_show(struct kobject *kobj, struct kobj_attrib= ute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", + spm_mechanism_types[bioscfg_drv.spm_data.mechanism]); +} + +static struct kobj_attribute password_spm_key_mechanism =3D __ATTR_RO(key_= mechanism); + +static ssize_t sk_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int ret; + int length; + + length =3D count; + if (buf[length - 1] =3D=3D '\n') + length--; + + /* allocate space and copy current signing key */ + bioscfg_drv.spm_data.signing_key =3D kmalloc(length, GFP_KERNEL); + if (!bioscfg_drv.spm_data.signing_key) + return -ENOMEM; + + memcpy(bioscfg_drv.spm_data.signing_key, buf, length); + + /* submit signing key payload */ + ret =3D hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_SK, + HPWMI_SECUREPLATFORM, + (void *)bioscfg_drv.spm_data.signing_key, + count, 0); + + if (!ret) { + bioscfg_drv.spm_data.mechanism =3D SIGNING_KEY; + hp_set_reboot_and_signal_event(); + } + + kfree(bioscfg_drv.spm_data.signing_key); + bioscfg_drv.spm_data.signing_key =3D NULL; + + return ret ? ret : count; +} + +static struct kobj_attribute password_spm_signing_key =3D __ATTR_WO(sk); + +static ssize_t kek_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int ret; + int length; + + length =3D count; + if (buf[length - 1] =3D=3D '\n') + length--; + + /* allocate space and copy current signing key */ + bioscfg_drv.spm_data.endorsement_key =3D kmalloc(length, GFP_KERNEL); + if (!bioscfg_drv.spm_data.endorsement_key) { + ret =3D -ENOMEM; + goto exit_kek; + } + + memcpy(bioscfg_drv.spm_data.endorsement_key, buf, length); + + ret =3D hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_KEK, + HPWMI_SECUREPLATFORM, + (void *)bioscfg_drv.spm_data.endorsement_key, + count, 0); + + if (!ret) { + bioscfg_drv.spm_data.mechanism =3D ENDORSEMENT_KEY; + hp_set_reboot_and_signal_event(); + } + +exit_kek: + kfree(bioscfg_drv.spm_data.endorsement_key); + bioscfg_drv.spm_data.endorsement_key =3D NULL; + + return ret ? ret : count; +} + +static struct kobj_attribute password_spm_endorsement_key =3D __ATTR_WO(ke= k); + +static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", BIOS_SPM); +} + +static struct kobj_attribute password_spm_role =3D __ATTR_RO(role); + +static ssize_t auth_token_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int ret =3D 0; + int length; + + length =3D count; + if (buf[length - 1] =3D=3D '\n') + length--; + + /* allocate space and copy current auth token */ + bioscfg_drv.spm_data.auth_token =3D kmalloc(length, GFP_KERNEL); + if (!bioscfg_drv.spm_data.auth_token) { + ret =3D -ENOMEM; + goto exit_token; + } + + memcpy(bioscfg_drv.spm_data.auth_token, buf, length); + return count; + +exit_token: + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token =3D NULL; + + return ret; +} + +static struct kobj_attribute password_spm_auth_token =3D __ATTR_WO(auth_to= ken); + +static struct attribute *secure_platform_attrs[] =3D { + &password_spm_is_key_enabled.attr, + &password_spm_signing_key.attr, + &password_spm_endorsement_key.attr, + &password_spm_key_mechanism.attr, + &password_spm_status.attr, + &password_spm_role.attr, + &password_spm_auth_token.attr, + NULL, +}; + +static const struct attribute_group secure_platform_attr_group =3D { + .attrs =3D secure_platform_attrs, +}; + +void hp_exit_secure_platform_attributes(void) +{ + /* remove secure platform sysfs entry and free key data*/ + + kfree(bioscfg_drv.spm_data.endorsement_key); + bioscfg_drv.spm_data.endorsement_key =3D NULL; + + kfree(bioscfg_drv.spm_data.signing_key); + bioscfg_drv.spm_data.signing_key =3D NULL; + + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token =3D NULL; + + if (bioscfg_drv.spm_data.attr_name_kobj) + sysfs_remove_group(bioscfg_drv.spm_data.attr_name_kobj, + &secure_platform_attr_group); +} + +int hp_populate_secure_platform_data(struct kobject *attr_name_kobj) +{ + /* Populate data for Secure Platform Management */ + bioscfg_drv.spm_data.attr_name_kobj =3D attr_name_kobj; + + strscpy(bioscfg_drv.spm_data.attribute_name, SPM_STR, + sizeof(bioscfg_drv.spm_data.attribute_name)); + + bioscfg_drv.spm_data.is_enabled =3D 0; + bioscfg_drv.spm_data.mechanism =3D 0; + bioscfg_drv.pending_reboot =3D false; + update_spm_state(); + + bioscfg_drv.spm_data.endorsement_key =3D NULL; + bioscfg_drv.spm_data.signing_key =3D NULL; + bioscfg_drv.spm_data.auth_token =3D NULL; + + return sysfs_create_group(attr_name_kobj, &secure_platform_attr_group); +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27FDCC7EE2C for ; Fri, 2 Jun 2023 13:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236058AbjFBNLm (ORCPT ); Fri, 2 Jun 2023 09:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236034AbjFBNLM (ORCPT ); Fri, 2 Jun 2023 09:11:12 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07FAAE59; Fri, 2 Jun 2023 06:11:01 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-38e04d1b2b4so1640611b6e.3; Fri, 02 Jun 2023 06:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711460; x=1688303460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Yhj3dwdBzocrWFhPP87+FKOEWGQOG6inffzg73F1c3c=; b=loFoqWX//HSFKwU8JPCOkgeG0rGWviFSLIwQekL956njuKpi34A+Xi0Ki+moCXiH8P 8xHK18b04uN+MsL24yGC0Z1LoSLVNs5beYUeRNh7VSjCYNEys3hHBiQwbd0++kG2iPsu SIo6KcFkuOI2/zuXRVEg5R32xflcdg20ljM04XfaRtAdYIXGcFibzJq/LiOT4FaxlPz+ AazpcTJizHmKE8j14h8jeeFvbIPcwaGEflwokFdALbynhHBbi4rITTg5u1M3HqmZTIS+ hoA3IS7oe9tTkyU1BMqgx9As+wd7TJs9bkj+ht0GW+YxA6I/VTtf6X40Y51NjO/TaX03 Fcmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711460; x=1688303460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yhj3dwdBzocrWFhPP87+FKOEWGQOG6inffzg73F1c3c=; b=fIpShSnACkoAYFqZYYrEMge23vv7ald+U7cW5JsjqzorVYOvQoYBERyNP5QyiHMixR ZG9e716jWPlSSERtjsj0H/5qyaOq2OaH9TSzIXoyIOkZvA08CaTzj26EgMmMm+FcrSof fDZc926Ucyjq5L9m4t04GUG6Zi6V3tblr3O+dLY+V+CcCWMVlwIro8lB5jrW69ogXvoo TWCbfO5NM7o1gx9KKZ51i0LxY/dXEz9oRLzqZAUF5Z3MPvHozpt56mSTFMSp0vbGJgWL dUkGXhYWIob5HcBxI0lE18NtIsi3TkFi+CF2eUbYuTFBZJKXNx2sPCxsckkoQaPkUKgG e/tg== X-Gm-Message-State: AC+VfDzXFzy4c+ib3bWw90ZhfQWyszO0EYr1BvohLshTMW85Z6HboYDI ffx0YSkBakxN3WppoaK4kT8pNSzWMTw= X-Google-Smtp-Source: ACHHUZ7OG9aUBEp0IvrWpMK+5t+4hZZb3S2G6ZYLXpFGC61f8WP27soq2SaKcWmrbjM2V6bO7DO7Mw== X-Received: by 2002:a05:6808:4d2:b0:397:f46a:ad39 with SMTP id a18-20020a05680804d200b00397f46aad39mr2426802oie.22.1685711460121; Fri, 02 Jun 2023 06:11:00 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:10:59 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 10/13] hp-bioscfg: string-attributes Date: Fri, 2 Jun 2023 08:10:41 -0500 Message-Id: <20230602131044.3297-11-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/string-attributes.c | 401 ++++++++++++++++++ 1 file changed, 401 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/string-attributes.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c b/drive= rs/platform/x86/hp/hp-bioscfg/string-attributes.c new file mode 100644 index 000000000000..2bff81ff2d63 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c @@ -0,0 +1,401 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to string type attributes under + * HP_WMI_BIOS_STRING_GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" + +#define WMI_STRING_TYPE "HPBIOS_BIOSString" + +GET_INSTANCE_ID(string); + +static ssize_t current_value_show(struct kobject *kobj, struct kobj_attrib= ute *attr, char *buf) +{ + int instance_id =3D get_string_instance_id(kobj); + + if (instance_id < 0) + return -EIO; + + return sysfs_emit(buf, "%s\n", + bioscfg_drv.string_data[instance_id].current_value); +} + +/** + * validate_string_input() - + * Validate input of current_value against min and max lengths + * + * @instance_id: The instance on which input is validated + * @buf: Input value + */ +static int validate_string_input(int instance_id, const char *buf) +{ + int in_len =3D strlen(buf); + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + /* BIOS treats it as a read only attribute */ + if (string_data->common.is_readonly) + return -EIO; + + if (in_len < string_data->min_length || in_len > string_data->max_length) + return -ERANGE; + + return 0; +} + +static void update_string_value(int instance_id, char *attr_value) +{ + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + /* Write settings to BIOS */ + strscpy(string_data->current_value, attr_value, sizeof(string_data->curre= nt_value)); +} + +/* + * ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, string); + * static struct kobj_attribute string_display_langcode =3D + * __ATTR_RO(display_name_language_code); + */ + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, string); +static struct kobj_attribute string_display_name =3D + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, string); +static struct kobj_attribute string_current_val =3D + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_N_PROPERTY_SHOW(min_length, string); +static struct kobj_attribute string_min_length =3D + __ATTR_RO(min_length); + +ATTRIBUTE_N_PROPERTY_SHOW(max_length, string); +static struct kobj_attribute string_max_length =3D + __ATTR_RO(max_length); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "string\n"); +} + +static struct kobj_attribute string_type =3D + __ATTR_RO(type); + +static struct attribute *string_attrs[] =3D { + &common_display_langcode.attr, + &string_display_name.attr, + &string_current_val.attr, + &string_min_length.attr, + &string_max_length.attr, + &string_type.attr, + NULL +}; + +static const struct attribute_group string_attr_group =3D { + .attrs =3D string_attrs, +}; + +int hp_alloc_string_data(void) +{ + bioscfg_drv.string_instances_count =3D hp_get_instance_count(HP_WMI_BIOS_= STRING_GUID); + bioscfg_drv.string_data =3D kcalloc(bioscfg_drv.string_instances_count, + sizeof(*bioscfg_drv.string_data), GFP_KERNEL); + if (!bioscfg_drv.string_data) { + bioscfg_drv.string_instances_count =3D 0; + return -ENOMEM; + } + return 0; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_string_types[] =3D { + [NAME] =3D ACPI_TYPE_STRING, + [VALUE] =3D ACPI_TYPE_STRING, + [PATH] =3D ACPI_TYPE_STRING, + [IS_READONLY] =3D ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] =3D ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] =3D ACPI_TYPE_INTEGER, + [SEQUENCE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] =3D ACPI_TYPE_INTEGER, + [PREREQUISITES] =3D ACPI_TYPE_STRING, + [SECURITY_LEVEL] =3D ACPI_TYPE_INTEGER, + [STR_MIN_LENGTH] =3D ACPI_TYPE_INTEGER, + [STR_MAX_LENGTH] =3D ACPI_TYPE_INTEGER, +}; + +static int hp_populate_string_elements_from_package(union acpi_object *str= ing_obj, + int string_obj_count, + int instance_id) +{ + char *str_value =3D NULL; + int value_len; + int ret =3D 0; + u32 int_value; + int elem; + int reqs; + int eloc; + int size; + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + if (!string_obj) + return -EINVAL; + + for (elem =3D 1, eloc =3D 1; elem < string_obj_count; elem++, eloc++) { + /* ONLY look at the first STRING_ELEM_CNT elements */ + if (eloc =3D=3D STR_ELEM_CNT) + goto exit_string_package; + + switch (string_obj[elem].type) { + case ACPI_TYPE_STRING: + if (elem !=3D PREREQUISITES) { + ret =3D hp_convert_hexstr_to_str(string_obj[elem].string.pointer, + string_obj[elem].string.length, + &str_value, &value_len); + + if (ret) + continue; + } + break; + case ACPI_TYPE_INTEGER: + int_value =3D (u32)string_obj[elem].integer.value; + break; + default: + pr_warn("Unsupported object type [%d]\n", string_obj[elem].type); + continue; + } + + /* Check that both expected and read object type match */ + if (expected_string_types[eloc] !=3D string_obj[elem].type) { + pr_err("Error expected type %d for elem %d, but got type %d instead\n", + expected_string_types[eloc], elem, string_obj[elem].type); + return -EIO; + } + + /* Assign appropriate element value to corresponding field*/ + switch (eloc) { + case VALUE: + strscpy(string_data->current_value, + str_value, sizeof(string_data->current_value)); + break; + case PATH: + strscpy(string_data->common.path, str_value, + sizeof(string_data->common.path)); + break; + case IS_READONLY: + string_data->common.is_readonly =3D int_value; + break; + case DISPLAY_IN_UI: + string_data->common.display_in_ui =3D int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + string_data->common.requires_physical_presence =3D int_value; + break; + case SEQUENCE: + string_data->common.sequence =3D int_value; + break; + case PREREQUISITES_SIZE: + string_data->common.prerequisites_size =3D int_value; + + if (string_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of eleme= nts supported or data may be malformed\n"); + /* + * This HACK is needed to keep the expected + * element list pointing to the right obj[elem].type + * when the size is zero. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (string_data->common.prerequisites_size =3D=3D 0) + eloc++; + break; + case PREREQUISITES: + size =3D min_t(u32, string_data->common.prerequisites_size, + MAX_PREREQUISITES_SIZE); + + for (reqs =3D 0; reqs < size; reqs++) { + if (elem >=3D string_obj_count) { + pr_err("Error elem-objects package is too small\n"); + return -EINVAL; + } + + ret =3D hp_convert_hexstr_to_str(string_obj[elem + reqs].string.pointe= r, + string_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(string_data->common.prerequisites[reqs], + str_value, + sizeof(string_data->common.prerequisites[reqs])); + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + string_data->common.security_level =3D int_value; + break; + case STR_MIN_LENGTH: + string_data->min_length =3D int_value; + break; + case STR_MAX_LENGTH: + string_data->max_length =3D int_value; + break; + default: + pr_warn("Invalid element: %d found in String attribute or data may be m= alformed\n", elem); + break; + } + + kfree(str_value); + } + +exit_string_package: + kfree(str_value); + return 0; +} + +/** + * hp_populate_string_package_data() - + * Populate all properties of an instance under string attribute + * + * @string_obj: ACPI object with string data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_string_package_data(union acpi_object *string_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + string_data->attr_name_kobj =3D attr_name_kobj; + + hp_populate_string_elements_from_package(string_obj, + string_obj->package.count, + instance_id); + + hp_update_attribute_permissions(string_data->common.is_readonly, + &string_current_val); + hp_friendly_user_name_update(string_data->common.path, + attr_name_kobj->name, + string_data->common.display_name, + sizeof(string_data->common.display_name)); + return sysfs_create_group(attr_name_kobj, &string_attr_group); +} + +static int hp_populate_string_elements_from_buffer(u8 *buffer_ptr, u32 *bu= ffer_size, + int instance_id) +{ + int reqs; + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + // VALUE: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, string_data->current_= value, + sizeof(string_data->current_value)); + + // PATH: + hp_get_string_from_buffer(&buffer_ptr, buffer_size, string_data->common.p= ath, + sizeof(string_data->common.path)); + + // IS_READONLY: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.is_readonly); + + //DISPLAY_IN_UI: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.display_in_ui); + + // REQUIRES_PHYSICAL_PRESENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.requires_physical_presence); + + // SEQUENCE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.sequence); + + // PREREQUISITES_SIZE: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.prerequisites_size); + + if (string_data->common.prerequisites_size > MAX_PREREQUISITES_SIZE) { + /* Report a message and limit prerequisite size to maximum value */ + pr_warn("String Prerequisites size value exceeded the maximum number of = elements supported or data may be malformed\n"); + string_data->common.prerequisites_size =3D MAX_PREREQUISITES_SIZE; + } + + // PREREQUISITES: + for (reqs =3D 0; reqs < string_data->common.prerequisites_size; reqs++) + hp_get_string_from_buffer(&buffer_ptr, buffer_size, + string_data->common.prerequisites[reqs], + sizeof(string_data->common.prerequisites[reqs])); + + // SECURITY_LEVEL: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->common.security_level); + + // STR_MIN_LENGTH: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->min_length); + + // STR_MAX_LENGTH: + hp_get_integer_from_buffer(&buffer_ptr, buffer_size, + &string_data->max_length); + + return 0; +} + +/** + * hp_populate_string_buffer_data() - + * Populate all properties of an instance under string attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int hp_populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj) +{ + struct string_data *string_data =3D &bioscfg_drv.string_data[instance_id]; + + string_data->attr_name_kobj =3D attr_name_kobj; + + hp_populate_string_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + + hp_update_attribute_permissions(string_data->common.is_readonly, + &string_current_val); + hp_friendly_user_name_update(string_data->common.path, + attr_name_kobj->name, + string_data->common.display_name, + sizeof(string_data->common.display_name)); + + return sysfs_create_group(attr_name_kobj, &string_attr_group); +} + +/** + * hp_exit_string_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void hp_exit_string_attributes(void) +{ + int instance_id; + + for (instance_id =3D 0; instance_id < bioscfg_drv.string_instances_count; + instance_id++) { + struct kobject *attr_name_kobj =3D + bioscfg_drv.string_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) + sysfs_remove_group(attr_name_kobj, &string_attr_group); + } + bioscfg_drv.string_instances_count =3D 0; + + kfree(bioscfg_drv.string_data); + bioscfg_drv.string_data =3D NULL; +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBA8DC7EE29 for ; Fri, 2 Jun 2023 13:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235750AbjFBNLr (ORCPT ); Fri, 2 Jun 2023 09:11:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235982AbjFBNLW (ORCPT ); Fri, 2 Jun 2023 09:11:22 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE32E64; Fri, 2 Jun 2023 06:11:02 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-38dec65ab50so1752456b6e.2; Fri, 02 Jun 2023 06:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711462; x=1688303462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=nyFMP/6OFZeTM83vwUJOErQ+JrxpPbaie3LCiQYLuP4=; b=feT5lNUxSEH+bCr6Q51VRZkwai/OZbg+Fl1e7/Q1ErKEpHTzoKaaOGdOYFleJXUsas eHb6+wfRpnurqvCYuPRsinek4Y1tvrizCp9XSQ//o1CEA4lUyH31Pl+mXV2W9YvCHpd9 Dd2Ci3HgzFXW7kqq2wJZRyprE22CBI0DewRWVPA9G7aM3ZrQslqtK3vXxl110xaacagx Yb2a9AGyS4p2J74Xv5OvTB64q2a95q08sQf4nMEjoxxWZCqb19iRM0xxGF5tVOnGGFSh 7Vo9tCS9SfEjZU8dj6SQOhdq9a60Kwq9VToYRcjhhmGYXnqWRxvLrXI9v3kdllpxATfu JBkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711462; x=1688303462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nyFMP/6OFZeTM83vwUJOErQ+JrxpPbaie3LCiQYLuP4=; b=hyLko9+9eXdNLi1L+oTEb7NiM1tbDgG4sOga+o6isp9lVDKZjJ/GFW4aeMn03btim9 5sMAhEOgdoirXapN203/uPJqRRNA6TNvhr2WjIbUR1szYA9QSsyNHs0VZuyLho/drTWy eeTLOt/nUVV0641TT2MgKaWiiIuOMvpBSeXpDE2lHo5WK78dxdaj1HT9XJ+DN0aUmG9c cZMFu6n/SBQsZ9aaC0zXy7PaNtxzduvOY1/XWkfiC7qpTyXTTXw2o4H9Z5Ydm/aHP+VR O8flqb6Kds9dXR2QG9nrZOiJLn+TvzheIkGrc7NKi1fXdrKJZzDM4/N0gZlnQds94xr2 iTrw== X-Gm-Message-State: AC+VfDxPVWLvdQ1KJtR7bV2hpxRUshZYD44bcdG4Yq++xpwac3nJBcAn v4Rb0WH6cBTLHEff1hiCjR89lTQtGm8= X-Google-Smtp-Source: ACHHUZ7kHFN8yyzl5bIcquQFF1odFyQCTn6YoRfnwc1eJ8+Ea+IykYjtv+ZLhezD7GV3Ffl/1CEydw== X-Received: by 2002:aca:1a01:0:b0:398:f740:631e with SMTP id a1-20020aca1a01000000b00398f740631emr2009541oia.16.1685711461858; Fri, 02 Jun 2023 06:11:01 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:11:01 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 11/13] hp-bioscfg: surestart-attributes Date: Fri, 2 Jun 2023 08:10:42 -0500 Message-Id: <20230602131044.3297-12-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- .../x86/hp/hp-bioscfg/surestart-attributes.c | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/surestart-attributes= .c diff --git a/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c b/dr= ivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c new file mode 100644 index 000000000000..b57e42f29282 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to sure start object type attributes under + * BIOS for use with hp-bioscfg driver + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" +#include + +/* Maximum number of log entries supported when log entry size is 16 + * bytes. This value is calculated by dividing 4096 (page size) by + * log entry size. + */ +#define LOG_MAX_ENTRIES 254 + +/* + * Current Log entry size. This value size will change in the + * future. The driver reads a total of 128 bytes for each log entry + * provided by BIOS but only the first 16 bytes are used/read. + */ +#define LOG_ENTRY_SIZE 16 + +/* + * audit_log_entry_count_show - Reports the number of + * existing audit log entries available + * to be read + */ +static ssize_t audit_log_entry_count_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int ret; + u32 count =3D 0; + + ret =3D hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT, + HPWMI_SURESTART, + &count, 1, sizeof(count)); + + if (ret < 0) + return ret; + + return sysfs_emit(buf, "%d,%d,%d\n", count, LOG_ENTRY_SIZE, + LOG_MAX_ENTRIES); +} + +/* + * audit_log_entries_show() - Return all entries found in log file + */ +static ssize_t audit_log_entries_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int ret; + int i; + u32 count =3D 0; + u8 audit_log_buffer[128]; + + // Get the number of event logs + ret =3D hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT, + HPWMI_SURESTART, + &count, 1, sizeof(count)); + + if (ret < 0) + return ret; + + /* + * The show() api will not work if the audit logs ever go + * beyond 4KB + */ + if (count * LOG_ENTRY_SIZE > PAGE_SIZE) + return -EIO; + + /* + * We are guaranteed the buffer is 4KB so today all the event + * logs will fit + */ + for (i =3D 0; i < count; i++) { + audit_log_buffer[0] =3D i + 1; + + /* + * read audit log entry at a time. 'buf' input value + * provides the audit log entry to be read. On + * input, Byte 0 =3D Audit Log entry number from + * beginning (1..254) + * Entry number 1 is the newest entry whereas the + * highest entry number (number of entries) is the + * oldest entry. + */ + ret =3D hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG, + HPWMI_SURESTART, + audit_log_buffer, 1, 128); + + if (ret < 0 || (LOG_ENTRY_SIZE * i) > PAGE_SIZE) { + /* + * Encountered a failure while reading + * individual logs. Only a partial list of + * audit log will be returned. + */ + break; + } else { + memcpy(buf, audit_log_buffer, LOG_ENTRY_SIZE); + buf +=3D LOG_ENTRY_SIZE; + } + } + + return i * LOG_ENTRY_SIZE; +} + +static struct kobj_attribute sure_start_audit_log_entry_count =3D __ATTR_R= O(audit_log_entry_count); +static struct kobj_attribute sure_start_audit_log_entries =3D __ATTR_RO(au= dit_log_entries); + +static struct attribute *sure_start_attrs[] =3D { + &sure_start_audit_log_entry_count.attr, + &sure_start_audit_log_entries.attr, + NULL +}; + +static const struct attribute_group sure_start_attr_group =3D { + .attrs =3D sure_start_attrs, +}; + +void hp_exit_sure_start_attributes(void) +{ + sysfs_remove_group(bioscfg_drv.sure_start_attr_kobj, + &sure_start_attr_group); +} + +int hp_populate_sure_start_data(struct kobject *attr_name_kobj) +{ + bioscfg_drv.sure_start_attr_kobj =3D attr_name_kobj; + return sysfs_create_group(attr_name_kobj, &sure_start_attr_group); +} --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A60C5C7EE24 for ; Fri, 2 Jun 2023 13:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235512AbjFBNLx (ORCPT ); Fri, 2 Jun 2023 09:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236063AbjFBNLX (ORCPT ); Fri, 2 Jun 2023 09:11:23 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6FF0E6B; Fri, 2 Jun 2023 06:11:03 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6af86627460so1908843a34.1; Fri, 02 Jun 2023 06:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711463; x=1688303463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wENMhZEUKQoXANDT/rq1tLQ+DSTMyGsBS/qf3ADAcCs=; b=I44RzOw2tbwDqTnLw3HDaFA+1oD8TrEvDltU5Jd04njsCC9KnMZyAqsogTp2AgydhY Pt02P0i9ERi7VklW7tBl4tNXyfbwKEkXBaSMmAn21r28QAzkxielT7JZsDgj+S+OGXl7 pRdtZdIQmh5ulpqvcxR3DkSZABfhFIBXVNJZGRHEuV8WH9zliURKVZPdGwDCGUzyGbJq SiHva2vH/nJ8o8+dYIGP+oKFT412zTc0PCjiBN260T+mZytg1WbnbVdkDrrfRvwZhjc2 EtPLkkHJ5AdujCml/FTqu0w/RsYg1ZfXf7GSTODhKSX85da9HxGmkQwEROuN3Hsj7uyU Heww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711463; x=1688303463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wENMhZEUKQoXANDT/rq1tLQ+DSTMyGsBS/qf3ADAcCs=; b=YppC73NrP5RDAZDrQBvf+JOILvGnMMFnKN/CsEmT4cwuon0gfPB7OyBDmrwPx148L1 z0O5qeedQ9UVDPy8wAUmBEIyP6SWLpyfdHE+ylu/NzneclU5Dyof7EFQYw4Jgx+rEuKV Z4ZT6SLcPknuw5H7JAO4zPF3LLsNk5bbJ2Dbv3bw9sJhATaWjAsDlQM7DvBbZPcA5qse XkphVYMirIDR0E19HDVXcmn5UDxXxDM1njEbxXqg3qnSjfeRtvmGkOAmL+M1QhZFlPs2 IATFfFg7obkN79F1TMO1V8rLJMfaYw6oBkztiG6yKvzyGqob/gCpT2ZDb3TGARJmwpxk hK8A== X-Gm-Message-State: AC+VfDzxOUXoSxlUnPOQSaTea+iXCnYO7BE7acY/gS2jTMan3iugD2Zu r1Rxn7P9WpKHAdx0tPWODR8= X-Google-Smtp-Source: ACHHUZ4372lQDnEDnbCXVDjjMlpw1wnO0U+2fjy56vHnl3ojMAeV54jQTQnfRqndzvwZCN9r6CMuFA== X-Received: by 2002:a05:6808:2888:b0:38b:c4e0:a23 with SMTP id eu8-20020a056808288800b0038bc4e00a23mr2115053oib.57.1685711462920; Fri, 02 Jun 2023 06:11:02 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:11:02 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 12/13] hp-bioscfg: Makefile Date: Fri, 2 Jun 2023 08:10:43 -0500 Message-Id: <20230602131044.3297-13-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- drivers/platform/x86/hp/Kconfig | 16 ++++++++++++++++ drivers/platform/x86/hp/Makefile | 1 + drivers/platform/x86/hp/hp-bioscfg/Makefile | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile diff --git a/drivers/platform/x86/hp/Kconfig b/drivers/platform/x86/hp/Kcon= fig index ae165955311c..7fef4f12e498 100644 --- a/drivers/platform/x86/hp/Kconfig +++ b/drivers/platform/x86/hp/Kconfig @@ -60,4 +60,20 @@ config TC1100_WMI This is a driver for the WMI extensions (wireless and bluetooth power control) of the HP Compaq TC1100 tablet. =20 +config HP_BIOSCFG + tristate "HP BIOS Configuration Driver" + default m + depends on ACPI_WMI + select NLS + select FW_ATTR_CLASS + help + This driver enables administrators to securely manage BIOS settings + using digital certificates and public-key cryptography that eliminate + the need for passwords for both remote and local management. It supports + changing BIOS settings on many HP machines from 2018 and newer without + the use of any additional software. + + To compile this driver as a module, choose M here: the module will + be called hp-bioscfg. + endif # X86_PLATFORM_DRIVERS_HP diff --git a/drivers/platform/x86/hp/Makefile b/drivers/platform/x86/hp/Mak= efile index db1eed4cd7c7..e4f908a61acf 100644 --- a/drivers/platform/x86/hp/Makefile +++ b/drivers/platform/x86/hp/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_HP_ACCEL) +=3D hp_accel.o obj-$(CONFIG_HP_WMI) +=3D hp-wmi.o obj-$(CONFIG_TC1100_WMI) +=3D tc1100-wmi.o +obj-$(CONFIG_HP_BIOSCFG) +=3D hp-bioscfg/ diff --git a/drivers/platform/x86/hp/hp-bioscfg/Makefile b/drivers/platform= /x86/hp/hp-bioscfg/Makefile new file mode 100644 index 000000000000..67be0d917753 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/Makefile @@ -0,0 +1,11 @@ +obj-$(CONFIG_HP_BIOSCFG) :=3D hp-bioscfg.o + +hp-bioscfg-objs :=3D bioscfg.o \ + biosattr-interface.o \ + enum-attributes.o \ + int-attributes.o \ + order-list-attributes.o \ + passwdobj-attributes.o \ + spmobj-attributes.o \ + string-attributes.o \ + surestart-attributes.o --=20 2.34.1 From nobody Sun Feb 8 04:12:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2320C7EE29 for ; Fri, 2 Jun 2023 13:11:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235306AbjFBNL5 (ORCPT ); Fri, 2 Jun 2023 09:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236031AbjFBNLk (ORCPT ); Fri, 2 Jun 2023 09:11:40 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F13CE79; Fri, 2 Jun 2023 06:11:04 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-38c35975545so1749285b6e.1; Fri, 02 Jun 2023 06:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685711464; x=1688303464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=l9HhW1QPOz6WTxYOa6mD6gfn6R8qH8lALXUH8QmZoMg=; b=fQ+qAfBQMjIuAyRlAvTPwfbf5Me5ZjpGp7P7C51kYjBG6myQT0L8e9fnKJMlORybYt Bw+ZdWD4uuHH2WWr4TyXroo9YXXsLKtl7/54p9ZLNgceLALBEJEtqDv2lEK392HXxMDl Po3SsGa3VAMdOX9/JgtL08ecHAZGBDPjz+PMU02R9cfosPtCCLCiXgQIbyjuXcKbgrgQ L4jk1lvVuVXwi2nu0Fy9ygqve/dMpvWKU4i36AwovhDjKkTc0cYIhLrWgsdTSdLS0Nio asORBip7bUgL5LMDcLct1OPW/6hJTRiSm1sA98sBvra59JaK1sWgFL0Emxgrq1lL1xLX rl3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685711464; x=1688303464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l9HhW1QPOz6WTxYOa6mD6gfn6R8qH8lALXUH8QmZoMg=; b=TtrW52Ms91gAuImUVkZWCzsg+oM1RmxpC2VmXAqPUEoogWEbudt1kPLPzWzCPpbU4S jNWwpclI9TwBmdRynQXbi3OQmpssYq+fx7903glVLD6EzolFPF9Ef7jRdBc0YaJbN4kV hIknNNwCgN2Aupu9WrXrQXBzH9qW0un6J7rcL8q68de4SjBYaW6eQrFXsew2EleaYGro grsOKsUs0YkHbLyFqbekLxGqUPN+zY0n+oUJWWkwOmC596sihXTnDWjWqSD/6vb3OeVr PygSS2qLT3XbGRyhl6YgYnEiXSFz1JUrWSHsLST1V4ycsqAAEMsdi6Qo+zjWvvkySGmc DUUA== X-Gm-Message-State: AC+VfDyM2a9QM1hk390RAowJokGO8PDL5Ek4i0JxynU/JkG9izfHhWkh A0lozM5797HrF3xbkfIrL3hr6wyFhb4= X-Google-Smtp-Source: ACHHUZ747itczI8l3V7O4QkNLcuUjGdXcX1NaPUDKfDI8JJ/kf7SUwxb9g2OcGiDHfhQ6VVWtBzhhQ== X-Received: by 2002:a05:6808:64c:b0:398:5478:b7fa with SMTP id z12-20020a056808064c00b003985478b7famr2436212oih.45.1685711463936; Fri, 02 Jun 2023 06:11:03 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:125c:6b6d:18e9:9361]) by smtp.gmail.com with ESMTPSA id k17-20020a544691000000b0039a531d9b92sm483762oic.56.2023.06.02.06.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 06:11:03 -0700 (PDT) From: Jorge Lopez X-Google-Original-From: Jorge Lopez To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, thomas@t-8ch.de, ilpo.jarvinen@linux.intel.com Subject: [PATCH v16 13/13] hp-bioscfg: MAINTAINERS Date: Fri, 2 Jun 2023 08:10:44 -0500 Message-Id: <20230602131044.3297-14-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230602131044.3297-1-jorge.lopez2@hp.com> References: <20230602131044.3297-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.=E2=80=99s commerc= ial notebooks. Many features of HP Commercial notebooks 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 BIOSCFG 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 HP-specific firmware sysfs attributes such Secure Platform Management and Sure Start. Each section provides security feature description and identifies sysfs directories and files exposed by the driver. Many HP Commercial notebooks 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 notebooks 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 cryptographic signature-based authorization string that the BIOS will use to verify authorization to modify the setting. Linux Security components are under development and not published yet. The only linux component is the driver (hp bioscfg) at this time. Other published security components are under Windows. Signed-off-by: Jorge Lopez --- Based on the latest platform-drivers-x86.git/for-next --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9af9ace0e348..648c986f5867 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9436,6 +9436,12 @@ S: Obsolete W: http://w1.fi/hostap-driver.html F: drivers/net/wireless/intersil/hostap/ =20 +HP BIOSCFG DRIVER +M: Jorge Lopez +L: platform-driver-x86@vger.kernel.org +S: Maintained +F: drivers/platform/x86/hp/hp-bioscfg/ + HP COMPAQ TC1100 TABLET WMI EXTRAS DRIVER L: platform-driver-x86@vger.kernel.org S: Orphan --=20 2.34.1