From patchwork Thu Apr 20 16:54:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219000 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 3B090C77B73 for ; Thu, 20 Apr 2023 16:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbjDTQzB (ORCPT ); Thu, 20 Apr 2023 12:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbjDTQy7 (ORCPT ); Thu, 20 Apr 2023 12:54:59 -0400 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6652E2719; Thu, 20 Apr 2023 09:54:58 -0700 (PDT) Received: by mail-oo1-xc32.google.com with SMTP id k13-20020a4ad98d000000b00542416816b1so827978oou.7; Thu, 20 Apr 2023 09:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009697; x=1684601697; 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=2uw6cJJOj4NpjhqsMBl9W9u80TyJYI2izxlDAFaHoDI=; b=fJ/D4PKxwtTSrEgqvukmzSFD0SJI3Sd6XOPDQ9jTaE7PEoB0glKn6Mnz0hwQMfshwe +QHVu6HR+PKmMcyF8RJewtkbcETyUVz6EjLV4zHOwbHKHHcvpFt2tFk91WDwSAelpFaS fwQKJq5p9Qd1C/0Z2ZU9iwSOTQTwyQUmL5CyUZjEOTtYBLLuuIHIdrauj8sCMUGRn5Bh EDWuCrqSxTkDy1cRCZfPLIR9Tku43ueIw7vnDp3FDkEKjjP+oIEOf0d3f3NjFY7zH50n 9YjGG+BLJcaYpbFo2ZtuTxAhp0UMkRtMLe687qBx7F8owhB8IfLnGMuLcwWT1SChaQWp +Bzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009697; x=1684601697; 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=2uw6cJJOj4NpjhqsMBl9W9u80TyJYI2izxlDAFaHoDI=; b=eHdgtBYfsPgW+I2jmIYQFGTr9Ff9UzSbyjuwqHZfMcmf9L2hCL6HuBAY2uZogx61fh jYCAJkEdnaddj3ow3ot/XUC7LIu36ZMEkhyUyWIphdNphF/KzObxKy9IECb06hfOrpAG g9Mumxvctca2kX8DUmjNr7+mCfFzbUFkI23HkysfpfI5py8g7g1lwuI1nKR3ONSO5bnc LlE7pHZUSFkTrHpmFIiylxfZh2c4ZBRzxS6IGZGZ+DMZnfNg/stqx1Od1id7vL2qmVoW 1thoOWYNAt0rUByiG95wgCR79aIzhQSNyBVCBle4nSNczOvktZ+Mts+G9x+3fdA/wuWj 4UzA== X-Gm-Message-State: AAQBX9cgvWSZ1bKlOq52d4W6srjCFCihcF8+Rxd1GNf3wiPCcv94qvh4 o5gkTIxY5f4ttPE+aVUSfrQ= X-Google-Smtp-Source: AKy350ZI12IiJBDlabsyJN07F4WUwEobDo/rJevGUt9Gk/gyc9uf4D700RZVimYpO2Vzt2b3dPRFQw== X-Received: by 2002:a4a:3790:0:b0:546:d2db:ff9d with SMTP id r138-20020a4a3790000000b00546d2dbff9dmr1055608oor.1.1682009697590; Thu, 20 Apr 2023 09:54:57 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:54:57 -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 Subject: [PATCH v11 01/14] HP BIOSCFG driver - Documentation Date: Thu, 20 Apr 2023 11:54:41 -0500 Message-Id: <20230420165454.9517-2-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 98 ++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-firmware-attributes b/Documentation/ABI/testing/sysfs-class-firmware-attributes index 4cdba3477176..73d7b8fbc0b2 100644 --- a/Documentation/ABI/testing/sysfs-class-firmware-attributes +++ b/Documentation/ABI/testing/sysfs-class-firmware-attributes @@ -22,6 +22,12 @@ Description: - integer: a range of numerical values - string + HP specific types + ----------------- + - ordered-list - a set of ordered list valid values + - sure-start - report audit logs read from BIOS + + All attribute types support the following values: current_value: @@ -126,6 +132,44 @@ Description: value will not be effective through sysfs until this rule is met. + HP specific class extensions + ------------------------------ + + On HP systems the following additional attributes are available: + + "ordered-list"-type specific properties: + + elements: + A file that can be read to obtain the possible + list of values of the . Values are separated using + semi-colon (``;``). The order individual elements are 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. + + "sure-start"-type specific properties: + + audit_log_entries: + A read-only file that returns the events in the log. + Values are separated using semi-colon (``;``) + + Audit log entry format + + Byte 0-15: Requested Audit Log entry (Each Audit log is 16 bytes) + Byte 16-127: Unused + + audit_log_entry_count: + A read-only file that returns the number of existing audit log events available to be read. + 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 to up to 128 bytes long + in future BIOS versions. + + What: /sys/class/firmware-attributes/*/authentication/ Date: February 2021 KernelVersion: 5.11 @@ -206,7 +250,7 @@ Description: Drivers may emit a CHANGE uevent when a password is set or unset userspace may check it again. - On Dell and Lenovo systems, if Admin password is set, then all BIOS attributes + On Dell, Lenovo and HP systems, if Admin password is set, then all BIOS attributes require password validation. On Lenovo systems if you change the Admin password the new password is not active until the next boot. @@ -296,6 +340,15 @@ Description: echo "signature" > authentication/Admin/signature echo "password" > authentication/Admin/certificate_to_password + HP specific class extensions + -------------------------------- + + On HP systems the following additional settings are available: + + role: enhanced-bios-auth: + This role is specific to Secure Platform Management (SPM) attribute. + It requires configuring an endorsement (kek) and signing certificate (sk). + What: /sys/class/firmware-attributes/*/attributes/pending_reboot Date: February 2021 @@ -311,7 +364,7 @@ Description: == ========================================= 0 All BIOS attributes setting are current 1 A reboot is necessary to get pending BIOS - attribute changes applied + attribute changes applied == ========================================= Note, userspace applications need to follow below steps for efficient @@ -364,3 +417,44 @@ Description: use it to enable extra debug attributes or BIOS features for testing purposes. Note that any changes to this attribute requires a reboot for changes to take effect. + + + HP specific class extensions - Secure Platform Manager (SPM) + -------------------------------- + +What: /sys/class/firmware-attributes/*/authentication/SPM/kek +Date: March 29 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: 'kek' Key-Encryption-Key is a write-only file that can be used to configure the + RSA public key that will be used by the BIOS to verify + signatures when setting the signing key. When written, + the bytes should correspond to the KEK certificate + (x509 .DER format containing an OU). The size of the + certificate must be less than or equal to 4095 bytes. + + +What: /sys/class/firmware-attributes/*/authentication/SPM/sk +Date: March 29 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: 'sk' Signature Key is a write-only file that can be used to configure the RSA + public key that will be used by the BIOS to verify signatures + when configuring BIOS settings and security features. When + written, the bytes should correspond to the modulus of the + public key. The exponent is assumed to be 0x10001. + + +What: /sys/class/firmware-attributes/*/authentication/SPM/status +Date: March 29 +KernelVersion: 5.18 +Contact: "Jorge Lopez" +Description: '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>" From patchwork Thu Apr 20 16:54:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219001 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 40E5AC77B7E for ; Thu, 20 Apr 2023 16:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjDTQzC (ORCPT ); Thu, 20 Apr 2023 12:55:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbjDTQzB (ORCPT ); Thu, 20 Apr 2023 12:55:01 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CEF21FDA; Thu, 20 Apr 2023 09:54:59 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1842c7c2daaso382433fac.0; Thu, 20 Apr 2023 09:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009699; x=1684601699; 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=TssjylOZexEMAMfaEjdEtOjrRg1jd4qjFlWCipzYcuM=; b=k+xlPqDpzwgJNB5ta0Vl8afYIHNFMvzdI5cwPwSmSeIJjF4hA9q0MsYTVVLLDwagDl 3wEqKowkRlHU9dydZw1tu0Rl/R3VTkTMe7byKG74rDf7v+cOQINYoR8nkvpFJF4S/2XU GNUFkQneNw4/6SbGLp0Iqc/WQznVHggmfncwM3LEJHQzkyoPnYydA7Dusb0dzXpoconR +amolmojEPtHMGidODiGrevgQJOSgecqW2IcHea5D2SloheKwfyeuRwoK4M1zZtWkJvE BAau8tPvXq7TNDgW0xfkHiMX23rk9GH/66yBUqxdPHNQ5E9AiM72Hn3Fowvr81D5FvhO +DXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009699; x=1684601699; 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=TssjylOZexEMAMfaEjdEtOjrRg1jd4qjFlWCipzYcuM=; b=eKigWagP0P6xs1D42/B2qcAvz7Kx+H9Co31gKfUcN8ZnAMHfi4glLUKq2nGp0W/PEC 7LDUTVk1OsWf6NhAMxV3LfEEvnGgjNyanWZQBohZogEvZ/sFa8YacwPfKIVcppbJ36jW h33YPM3UdcTpIckAOItGdeveVUDtyYdeSrOkH2BuHArOA80+XVXFC1ELIspXvfhBGtYj QBT5weSiuiuCSlhYXeMnuiL5ABMNyRni1rDwnboBeJfbnSjKfVyCXwePHX33ewj+1BGT k8HKCl4hvZ6D5aeEZ0nzSf6YnG74o/mQ5YXTcuFO74L2xHW9AxmT0lq8KWsLfjx8bVLS 4eIQ== X-Gm-Message-State: AAQBX9dkmfPDJOEt4EiBWc7AQLumBYjsy+PAGh9wG1CEFFRDs6otlOzh LB5adYdF167iCwLGlyKaJuWBF0OU8rk= X-Google-Smtp-Source: AKy350Z7JkFEDZHxGtBuOpdO71I5SBxmS6uTM414zGWCw/+pGcavHTh4p9a4UV+CkrEowaPixeeCmA== X-Received: by 2002:a05:6870:828f:b0:187:8189:86ad with SMTP id q15-20020a056870828f00b00187818986admr1666910oae.14.1682009698751; Thu, 20 Apr 2023 09:54:58 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:54: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 Subject: [PATCH v11 02/14] HP BIOSCFG driver - biosattr-interface Date: Thu, 20 Apr 2023 11:54:42 -0500 Message-Id: <20230420165454.9517-3-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 307 ++++++++++++++++++ 1 file changed, 307 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/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c new file mode 100644 index 000000000000..f09dd41867f7 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/biosattr-interface.c @@ -0,0 +1,307 @@ +// 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" + +#define SET_DEFAULT_VALUES_METHOD_ID 0x02 +#define SET_BIOS_DEFAULTS_METHOD_ID 0x03 +#define SET_ATTRIBUTE_METHOD_ID 0x04 + +/* + * set_attribute() - Update an attribute value + * @a_name: The attribute name + * @a_value: The attribute value + * + * Sets an attribute to new value + */ +int hp_set_attribute(const char *a_name, const char *a_value) +{ + size_t security_area_size; + size_t a_name_size, a_value_size; + u16 *buffer = NULL; + u16 *start = NULL; + int buffer_size; + int ret = 0; + int instance; + char *auth_empty_value = ""; + char *auth_token_choice = NULL; + + + mutex_lock(&bioscfg_drv.mutex); + if (!bioscfg_drv.bios_attr_wdev) { + ret = -ENODEV; + goto out_set_attribute; + } + + instance = get_password_instance_for_type(SETUP_PASSWD); + if (instance < 0) { + ret = -EINVAL; + goto out_set_attribute; + } + + if (strlen(bioscfg_drv.password_data[instance].current_password) == 0) + strscpy(bioscfg_drv.password_data[instance].current_password, + auth_empty_value, + sizeof(bioscfg_drv.password_data[instance].current_password)); + + /* Select which auth token to use; password or [auth token] */ + + if (bioscfg_drv.spm_data.auth_token != NULL) + auth_token_choice = bioscfg_drv.spm_data.auth_token; + else + auth_token_choice = bioscfg_drv.password_data[instance].current_password; + + a_name_size = bioscfg_calculate_string_buffer(a_name); + a_value_size = bioscfg_calculate_string_buffer(a_value); + security_area_size = calculate_security_buffer(auth_token_choice); + buffer_size = a_name_size + a_value_size + security_area_size; + + buffer = kmalloc(buffer_size + 1, GFP_KERNEL); + if (!buffer) { + ret = -ENOMEM; + goto out_set_attribute; + } + + /* build variables to set */ + start = buffer; + start = ascii_to_utf16_unicode(start, a_name); + if (!start) + goto out_set_attribute; + + start = ascii_to_utf16_unicode(start, a_value); + if (!start) + goto out_set_attribute; + + populate_security_buffer(start, auth_token_choice); + + ret = hp_wmi_set_bios_setting(buffer, buffer_size); + + +out_set_attribute: + kfree(buffer); + mutex_unlock(&bioscfg_drv.mutex); + return ret; +} + +/* + * hp_wmi_perform_query + * + * query: The commandtype (enum hp_wmi_commandtype) + * write: The command (enum hp_wmi_command) + * buffer: Buffer used as input and/or output + * insize: Size of input buffer + * outsize: Size of output buffer + * + * returns zero on success + * an HP WMI query specific error code (which is positive) + * -EINVAL if the query was not successful at all + * -EINVAL if the output buffer size exceeds buffersize + * + * Note: The buffersize must at least be the maximum of the input and output + * size. E.g. Battery info query is defined to have 1 byte input + * and 128 byte output. The caller would do: + * buffer = kzalloc(128, GFP_KERNEL); + * ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ, + * buffer, 1, 128) + */ +int hp_wmi_perform_query(int query, enum hp_wmi_command command, void *buffer, + int insize, int outsize) +{ + struct acpi_buffer input, output = { ACPI_ALLOCATE_BUFFER, NULL }; + struct bios_return *bios_return; + union acpi_object *obj = NULL; + struct bios_args *args = NULL; + int mid, actual_outsize; + size_t bios_args_size; + int ret; + + mid = encode_outsize_for_pvsz(outsize); + if (WARN_ON(mid < 0)) + return mid; + + bios_args_size = struct_size(args, data, insize); + args = kmalloc(bios_args_size, GFP_KERNEL); + if (!args) + return -ENOMEM; + + input.length = bios_args_size; + input.pointer = args; + + args->signature = 0x55434553; + args->command = command; + args->commandtype = query; + args->datasize = insize; + memcpy(args->data, buffer, flex_array_size(args, data, insize)); + + ret = wmi_evaluate_method(HP_WMI_BIOS_GUID, 0, mid, &input, &output); + bioscfg_wmi_error_and_message(ret); + + if (ret) + goto out_free; + + obj = output.pointer; + if (!obj) { + ret = -EINVAL; + goto out_free; + } + if (query != HPWMI_SECUREPLATFORM_GET_STATE && + command != HPWMI_SECUREPLATFORM) + if (obj->type != ACPI_TYPE_BUFFER || + obj->buffer.length < sizeof(*bios_return)) { + pr_warn("query 0x%x returned wrong type or too small buffer\n", query); + ret = -EINVAL; + goto out_free; + } + + + bios_return = (struct bios_return *)obj->buffer.pointer; + ret = bios_return->return_code; + bioscfg_wmi_error_and_message(ret); + + if (ret) { + if (ret != HPWMI_RET_UNKNOWN_COMMAND && + ret != HPWMI_RET_UNKNOWN_CMDTYPE) + pr_warn("query 0x%x returned error 0x%x\n", query, ret); + goto out_free; + } + + /* Ignore output data of zero size */ + if (!outsize) + goto out_free; + + actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return))); + memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize); + memset(buffer + actual_outsize, 0, outsize - actual_outsize); + +out_free: + kfree(obj); + kfree(args); + return ret; +} + +static void *utf16_empty_string(u16 *p) +{ + *p++ = 2; + *p++ = (u8)0x00; + return p; +} + +/* + * 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 containing unicode string + */ +void *ascii_to_utf16_unicode(u16 *p, const u8 *str) +{ + int len = strlen(str); + int ret; + + /* + * Add null character when reading an empty string + * "02 00 00 00" + */ + if (len == 0) + return utf16_empty_string(p); + + /* Move pointer len * 2 number of bytes */ + *p++ = len * 2; + ret = utf8s_to_utf16s(str, strlen(str), UTF16_HOST_ENDIAN, p, len); + if (ret < 0) { + dev_err(bioscfg_drv.class_dev, "UTF16 conversion failed\n"); + goto ascii_to_utf16_unicode_out; + } + + if ((ret * sizeof(u16)) > U16_MAX) { + dev_err(bioscfg_drv.class_dev, "Error string too long\n"); + goto ascii_to_utf16_unicode_out; + } + +ascii_to_utf16_unicode_out: + p += len; + return p; +} + +/* + * hp_wmi_set_bios_setting - Set setting's value in BIOS + * + * @input_buffer: Input buffer address + * @input_size: Input buffer size + * + * Returns: Count of unicode characters written to BIOS if successful, otherwise + * -ENOMEM unable to allocate memory + * -EINVAL buffer not allocated or too small + */ +int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size) +{ + union acpi_object *obj; + struct acpi_buffer input = {input_size, input_buffer}; + struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; + int ret = 0; + + ret = wmi_evaluate_method(HP_WMI_SET_BIOS_SETTING_GUID, 0, 1, &input, &output); + + obj = output.pointer; + if (!obj) + return -EINVAL; + + if (obj->type != ACPI_TYPE_INTEGER) + ret = -EINVAL; + + ret = obj->integer.value; + bioscfg_wmi_error_and_message(ret); + + kfree(obj); + return ret; +} + +static int bios_attr_set_interface_probe(struct wmi_device *wdev, const void *context) +{ + mutex_lock(&bioscfg_drv.mutex); + bioscfg_drv.bios_attr_wdev = wdev; + mutex_unlock(&bioscfg_drv.mutex); + return 0; +} + +static void bios_attr_set_interface_remove(struct wmi_device *wdev) +{ + mutex_lock(&bioscfg_drv.mutex); + bioscfg_drv.bios_attr_wdev = NULL; + mutex_unlock(&bioscfg_drv.mutex); +} + +static const struct wmi_device_id bios_attr_set_interface_id_table[] = { + { .guid_string = HP_WMI_BIOS_GUID}, + { } +}; +static struct wmi_driver bios_attr_set_interface_driver = { + .driver = { + .name = DRIVER_NAME + }, + .probe = bios_attr_set_interface_probe, + .remove = bios_attr_set_interface_remove, + .id_table = bios_attr_set_interface_id_table +}; + +int init_bios_attr_set_interface(void) +{ + return wmi_driver_register(&bios_attr_set_interface_driver); +} + +void exit_bios_attr_set_interface(void) +{ + wmi_driver_unregister(&bios_attr_set_interface_driver); +} + +MODULE_DEVICE_TABLE(wmi, bios_attr_set_interface_id_table); From patchwork Thu Apr 20 16:54:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219002 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 44195C77B7A for ; Thu, 20 Apr 2023 16:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbjDTQzI (ORCPT ); Thu, 20 Apr 2023 12:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjDTQzE (ORCPT ); Thu, 20 Apr 2023 12:55:04 -0400 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6337E2721; Thu, 20 Apr 2023 09:55:00 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id i10-20020a4ad68a000000b0053b8aa32089so835043oot.5; Thu, 20 Apr 2023 09:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009699; x=1684601699; 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=SFSUReylnms78o9Ra2IqvMYEWG7+IT6tmyoTJ3+uXcs=; b=SmnFYWLn1Hkhefe641hmHbyAMFgnEukv02JhuomEKLE2tqHq9AKY9xou4MuZM639ps 0iZmOg6eNyH/K2dfi9Q9eVFaaohObGzmhQ1eyN9CHm2MsjIYySng+myR2rhgHW1Lvpl8 jfVQ4jrm0lzg5eK/Xbw2HvmrF4QSZLcj8Prhbx0dOa7PtH2kLBRkZmOyhOkOlw9EGyGO N98MSNS1/6HnXvjSy88fBorXUN7bg8xt/zk1+j/D8PiAYsIbyjk7oAQ7ne9xpdY6DXDa 7W6yYVVs0Uf36HbsfusU6aQSERYH8880nnp6nAk3H8RBUjpXihp8iF/1zKlE9HIYGV9p 5FMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009699; x=1684601699; 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=SFSUReylnms78o9Ra2IqvMYEWG7+IT6tmyoTJ3+uXcs=; b=B+bJHz9sRIc+MTYkzvtddMzQFChC6s1lWw20k5gfIofFMvLVFZyvi6PcFMCo7ZXCyC prYAsV7VH2ewoxF+h01j+/e7ws/xFhveexpfMGx2DlpG55l1TIX47wLdxt5COp58Bcsb gGvdFgc3OrTSBOLT54QHkcrtzFBa82IrHkt6xfBf0PKnUKok+JlkbVX9cdk9b8/JHMSs pRLTX9Lkcdcg9Az2ZQySKyJyag9yHbxoaJah9+VY6ZnqrA887Rl8XleVHuncPFRcWTOj FgiKcqw/X7vHS98rM171MIOyBxDerH1OQVKQroQkYpTFIml8aIFLeChUaOHirt0jJl4i 0zCA== X-Gm-Message-State: AAQBX9fK7MCDBIi1fo9yHVY2NRCbtIhu+BDCiBze7QVbUbiF9vFb6hZk j71Uvmql6aDc66TavLgqPiA= X-Google-Smtp-Source: AKy350YpJ/lS6rOQhE9tL28nVVNmqDAfra57cxg5GtLd0C3MtZXBNeiBu88NP0EevwKuLKXV77xVgg== X-Received: by 2002:a4a:52d4:0:b0:546:569b:d419 with SMTP id d203-20020a4a52d4000000b00546569bd419mr1209221oob.4.1682009699603; Thu, 20 Apr 2023 09:54:59 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:54: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 Subject: [PATCH v11 03/14] HP BIOSCFG driver - bioscfg Date: Thu, 20 Apr 2023 11:54:43 -0500 Message-Id: <20230420165454.9517-4-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 961 +++++++++++++++++++ 1 file changed, 961 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/platform/x86/hp/hp-bioscfg/bioscfg.c new file mode 100644 index 000000000000..4b0d4f56e65f --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c @@ -0,0 +1,961 @@ +// 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 = { + .mutex = __MUTEX_INITIALIZER(bioscfg_drv.mutex), +}; + +static struct class *fw_attr_class; + +int get_integer_from_buffer(int **buffer, u32 *buffer_size, int *integer) +{ + int *ptr = PTR_ALIGN(*buffer, 4); + + /* Ensure there is enough space remaining to read the integer */ + if (*buffer_size < sizeof(int)) + return -EINVAL; + + *integer = *(ptr++); + *buffer = ptr; + *buffer_size -= sizeof(int); + + return 0; +} + + +int get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_size) +{ + u16 *src = (u16 *)*buffer; + u16 src_size; + + u16 size; + int i; + int escape = 0; + int conv_dst_size; + + if (*buffer_size < sizeof(u16)) + return -EINVAL; + + src_size = *(src++); + /* size value in u16 chars */ + size = 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 = 0; i < size; i++) + if (src[i] == '\\' || + src[i] == '\r' || + src[i] == '\n' || + src[i] == '\t') + escape++; + + size += escape; + + /* + * Conversion is limited to destination string max number of + * bytes. + */ + conv_dst_size = size; + if (size > dst_size) + conv_dst_size = 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] = 0; + + for (i = 0; i < size && i < conv_dst_size; i++) { + if (*src == '\\' || + *src == '\r' || + *src == '\n' || + *src == '\t') + dst[i++] = '\\'; + + if (*src == '\r') + dst[i] = 'r'; + else if (*src == '\n') + dst[i] = 'n'; + else if (*src == '\t') + dst[i] = 't'; + else if (*src == '"') + dst[i] = '\''; + else + dst[i] = *src; + src++; + } + + *buffer = (u8 *)src; + *buffer_size -= size * sizeof(u16); + + return size; +} + + +/* + * calculate_string_buffer() - determines size of string buffer for use with BIOS communication + * @str: the string to calculate based upon + */ +size_t bioscfg_calculate_string_buffer(const char *str) +{ + int length = strlen(str); + int size; + + /* BIOS expects 4 bytes when an empty string is found */ + if (!length) + length = 1; + + /* u16 length field + one UTF16 char for each input char */ + size = sizeof(u16) + length * sizeof(u16); + + return size; +} + +int bioscfg_wmi_error_and_message(int error_code) +{ + char *error_msg = NULL; + int ret; + + switch (error_code) { + case SUCCESS: + error_msg = "Success"; + ret = 0; + break; + case CMD_FAILED: + error_msg = "Command failed"; + ret = -EINVAL; + break; + case INVALID_SIGN: + error_msg = "Invalid signature"; + ret = -EINVAL; + break; + case INVALID_CMD_VALUE: + error_msg = "Invalid command value/Feature not supported"; + ret = -EOPNOTSUPP; + break; + case INVALID_CMD_TYPE: + error_msg = "Invalid command type"; + ret = -EINVAL; + break; + case INVALID_DATA_SIZE: + error_msg = "Invalid data size"; + ret = -EINVAL; + break; + case INVALID_CMD_PARAM: + error_msg = "Invalid command parameter"; + ret = -EINVAL; + break; + case ENCRYP_CMD_REQUIRED: + error_msg = "Secure/encrypted command required"; + ret = -EACCES; + break; + case NO_SECURE_SESSION: + error_msg = "No secure session established"; + ret = -EACCES; + break; + case SECURE_SESSION_FOUND: + error_msg = "Secure session already established"; + ret = -EACCES; + break; + case SECURE_SESSION_FAILED: + error_msg = "Secure session failed"; + ret = -EIO; + break; + case AUTH_FAILED: + error_msg = "Other permission/Authentication failed"; + ret = -EACCES; + break; + case INVALID_BIOS_AUTH: + error_msg = "Invalid BIOS administrator password"; + ret = -EINVAL; + break; + case NONCE_DID_NOT_MATCH: + error_msg = "Nonce did not match"; + ret = -EINVAL; + break; + case GENERIC_ERROR: + error_msg = "Generic/Other error"; + ret = -EIO; + break; + case BIOS_ADMIN_POLICY_NOT_MET: + error_msg = "BIOS Admin password does not meet password policy requirements"; + ret = -EINVAL; + break; + case BIOS_ADMIN_NOT_SET: + error_msg = "BIOS Setup password is not set."; + ret = -EPERM; + break; + case P21_NO_PROVISIONED: + error_msg = "P21 is not provisioned"; + ret = -EPERM; + break; + case P21_PROVISION_IN_PROGRESS: + error_msg = "P21 is already provisioned or provisioning is in progress and a signing key has already been sent."; + ret = -EINPROGRESS; + break; + case P21_IN_USE: + error_msg = "P21 in use (cannot deprovision)"; + ret = -EPERM; + break; + case HEP_NOT_ACTIVE: + error_msg = "HEP not activated"; + ret = -EPERM; + break; + case HEP_ALREADY_SET: + error_msg = "HEP Transport already set"; + ret = -EINVAL; + break; + case HEP_CHECK_STATE: + error_msg = "Check the current HEP state"; + ret = -EINVAL; + break; + default: + error_msg = "Generic/Other error"; + ret = -EIO; + break; + } + + if (error_code) + pr_warn_ratelimited("Returned error 0x%x, \"%s\"\n", error_code, error_msg); + + return ret; +} + + +/* + * pending_reboot_show() - sysfs implementaton for read pending_reboot + * @kobj: Kernel object for this attribute + * @attr: Kernel object attribute + * @buf: The buffer to display to userspace + * + * Stores default value as 0 + * When current_value is changed this attribute is set to 1 to notify reboot may be required + */ +static ssize_t pending_reboot_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%d\n", bioscfg_drv.pending_reboot); +} +static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot); + +/* + * create_attributes_level_sysfs_files() - Creates pending_reboot attributes + */ +static int create_attributes_level_sysfs_files(void) +{ + int ret; + + ret = sysfs_create_file(&bioscfg_drv.main_dir_kset->kobj, &pending_reboot.attr); + if (ret) + return ret; + + return 0; +} + + +static void attr_name_release(struct kobject *kobj) +{ + kfree(kobj); +} + +static const struct kobj_type attr_name_ktype = { + .release = attr_name_release, + .sysfs_ops = &kobj_sysfs_ops, +}; + +/* + * get_wmiobj_pointer() - Get Content of WMI block for particular instance + * + * @instance_id: WMI instance ID + * @guid_string: WMI GUID (in str form) + * + * Fetches the content for WMI block (instance_id) under GUID (guid_string) + * Caller must kfree the return + */ +union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string) +{ + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + acpi_status status; + + status = wmi_query_block(guid_string, instance_id, &out); + return ACPI_SUCCESS(status) ? (union acpi_object *)out.pointer : NULL; +} + +/* + * get_instance_count() - Compute total number of instances under guid_string + * + * @guid_string: WMI GUID (in string form) + */ +int get_instance_count(const char *guid_string) +{ + union acpi_object *wmi_obj = NULL; + int i = 0; + + do { + kfree(wmi_obj); + wmi_obj = get_wmiobj_pointer(i, guid_string); + i++; + } while (wmi_obj); + + return i-1; +} + +/* + * alloc_attributes_data() - Allocate attributes data for a particular type + * + * @attr_type: Attribute type to allocate + */ +static int alloc_attributes_data(int attr_type) +{ + int retval = 0; + + switch (attr_type) { + case HPWMI_STRING_TYPE: + retval = alloc_string_data(); + break; + case HPWMI_INTEGER_TYPE: + retval = alloc_integer_data(); + break; + case HPWMI_ENUMERATION_TYPE: + retval = alloc_enumeration_data(); + break; + case HPWMI_ORDERED_LIST_TYPE: + retval = alloc_ordered_list_data(); + break; + case HPWMI_PASSWORD_TYPE: + retval = alloc_password_data(); + break; + default: + break; + } + + return retval; +} + +int convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *len) +{ + int ret = 0; + int new_len = 0; + char tmp[] = "0x00"; + char *new_str = NULL; + long ch; + int i; + + if (input_len <= 0 || input == NULL || str == NULL || len == NULL) + return -EINVAL; + + *len = 0; + *str = NULL; + + new_str = kmalloc(input_len, GFP_KERNEL); + if (!new_str) + return -ENOMEM; + + for (i = 0; i < input_len; i += 5) { + strncpy(tmp, input + i, strlen(tmp)); + if (kstrtol(tmp, 16, &ch) == 0) { + // escape char + if (ch == '\\' || ch == '\r' || ch == '\n' || ch == '\t') { + if (ch == '\r') + ch = 'r'; + else if (ch == '\n') + ch = 'n'; + else if (ch == '\t') + ch = 't'; + new_str[new_len++] = '\\'; + } + new_str[new_len++] = ch; + if (ch == '\0') + break; + } + } + + if (new_len) { + new_str[new_len] = '\0'; + *str = krealloc(new_str, (new_len + 1) * sizeof(char), GFP_KERNEL); + if (*str) + *len = new_len; + else + ret = -ENOMEM; + } else { + ret = -EFAULT; + } + + if (ret) + kfree(new_str); + return ret; +} + +/* map output size to the corresponding WMI method id */ +int 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 friendly_user_name_update(char *path, const char *attr_name, + char *attr_display, int attr_size) +{ + char *found = NULL; + + found = strstr(path, SCHEDULE_POWER_ON); + if (found) + snprintf(attr_display, + attr_size, + "%s - %s", + SCHEDULE_POWER_ON, + attr_name); + else + strscpy(attr_display, attr_name, attr_size); +} + +/* + * update_attribute_permissions() - Update attributes permissions when + * isReadOnly value is 1 + * + * @isReadOnly: ReadOnly value + * @current_val: kobj_attribute corresponding to attribute. + * + */ +void update_attribute_permissions(u32 isReadOnly, struct kobj_attribute *current_val) +{ + if (isReadOnly) + current_val->attr.mode = (umode_t)0444; + else + current_val->attr.mode = (umode_t)0644; +} + + +/** + * destroy_attribute_objs() - Free a kset of kobjects + * @kset: The kset to destroy + * + * Fress kobjects created for each attribute_name under attribute type kset + */ +static void destroy_attribute_objs(struct kset *kset) +{ + struct kobject *pos, *next; + + list_for_each_entry_safe(pos, next, &kset->list, entry) + kobject_put(pos); +} + +/** + * release_attributes_data() - Clean-up all sysfs directories and files created + */ +static void release_attributes_data(void) +{ + mutex_lock(&bioscfg_drv.mutex); + + exit_string_attributes(); + exit_integer_attributes(); + exit_enumeration_attributes(); + exit_ordered_list_attributes(); + exit_password_attributes(); + exit_sure_start_attributes(); + exit_secure_platform_attributes(); + + if (bioscfg_drv.authentication_dir_kset) { + destroy_attribute_objs(bioscfg_drv.authentication_dir_kset); + kset_unregister(bioscfg_drv.authentication_dir_kset); + bioscfg_drv.authentication_dir_kset = NULL; + } + if (bioscfg_drv.main_dir_kset) { + sysfs_remove_file(&bioscfg_drv.main_dir_kset->kobj, &pending_reboot.attr); + destroy_attribute_objs(bioscfg_drv.main_dir_kset); + kset_unregister(bioscfg_drv.main_dir_kset); + bioscfg_drv.main_dir_kset = NULL; + } + mutex_unlock(&bioscfg_drv.mutex); +} + + +/* + * hp_add_other_attributes - Initialize HP custom attributes not reported by + * BIOS and required to support Secure Platform, Sure Start, and Sure + * Admin. + * @attr_type: Custom HP attribute not reported by BIOS + * + * Initialiaze all 3 types of attributes: Platform, Sure Start, and Sure + * Admin object. Populates each attrbute types respective properties + * under sysfs files. + * + * Returns zero(0) if successful. Otherwise, a negative value. + */ +static int hp_add_other_attributes(int attr_type) +{ + struct kobject *attr_name_kobj; + union acpi_object *obj = NULL; + int retval = 0; + u8 *attr_name; + + mutex_lock(&bioscfg_drv.mutex); + + attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + retval = -ENOMEM; + goto err_other_attr_init; + } + + /* Check if attribute type is supported */ + switch (attr_type) { + case HPWMI_SECURE_PLATFORM_TYPE: + attr_name_kobj->kset = bioscfg_drv.authentication_dir_kset; + attr_name = SPM_STR; + break; + + case HPWMI_SURE_START_TYPE: + attr_name_kobj->kset = bioscfg_drv.main_dir_kset; + attr_name = SURE_START_STR; + break; + + default: + pr_err("Error: Unknown attr_type: %d\n", attr_type); + retval = -EINVAL; + goto err_other_attr_init; + } + + retval = kobject_init_and_add(attr_name_kobj, &attr_name_ktype, + NULL, "%s", attr_name); + if (retval) { + pr_err("Error encountered [%d]\n", retval); + kobject_put(attr_name_kobj); + goto err_other_attr_init; + } + + /* Populate attribute data */ + switch (attr_type) { + case HPWMI_SECURE_PLATFORM_TYPE: + retval = populate_secure_platform_data(attr_name_kobj); + break; + + case HPWMI_SURE_START_TYPE: + retval = populate_sure_start_data(attr_name_kobj); + break; + + default: + goto err_other_attr_init; + } + + mutex_unlock(&bioscfg_drv.mutex); + return 0; + +err_other_attr_init: + mutex_unlock(&bioscfg_drv.mutex); + kfree(obj); + return retval; +} + +/* + * hp_init_bios_attributes - Initialize all attributes for a type + * @attr_type: The attribute type to initialize + * @guid: The WMI GUID associated with this type to initialize + * + * Initialiaze all 5 types of attributes: enumeration, integer, + * string, password, ordered list object. Populates each attrbute types + * respective properties under sysfs files + */ +static int hp_init_bios_attributes(int attr_type, const char *guid) +{ + struct kobject *attr_name_kobj; + union acpi_object *obj = NULL; + union acpi_object *elements; + struct kset *tmp_set; + int min_elements; + char str[MAX_BUFF]; + + char *temp_str = NULL; + char *str_value = NULL; + int str_len; + int ret = 0; + + u8 *buffer_ptr = NULL; + int buffer_size; + + + /* instance_id needs to be reset for each type GUID + * also, instance IDs are unique within GUID but not across + */ + int instance_id = 0; + int retval = 0; + + retval = alloc_attributes_data(attr_type); + if (retval) + return retval; + + switch (attr_type) { + case HPWMI_STRING_TYPE: + min_elements = 12; + break; + case HPWMI_INTEGER_TYPE: + min_elements = 13; + break; + case HPWMI_ENUMERATION_TYPE: + min_elements = 13; + break; + case HPWMI_ORDERED_LIST_TYPE: + min_elements = 12; + break; + case HPWMI_PASSWORD_TYPE: + min_elements = 15; + break; + default: + pr_err("Error: Unknown attr_type: %d\n", attr_type); + return -EINVAL; + } + + /* need to use specific instance_id and guid combination to get right data */ + obj = get_wmiobj_pointer(instance_id, guid); + if (!obj) + return -ENODEV; + + mutex_lock(&bioscfg_drv.mutex); + while (obj) { + if (obj->type != ACPI_TYPE_PACKAGE && obj->type != ACPI_TYPE_BUFFER) { + pr_err("Error: Expected ACPI-package or buffer type, got: %d\n", obj->type); + retval = -EIO; + goto err_attr_init; + } + + /* Take action appropriate to each ACPI TYPE */ + if (obj->type == ACPI_TYPE_PACKAGE) { + if (obj->package.count < min_elements) { + pr_err("ACPI-package does not have enough elements: %d < %d\n", + obj->package.count, min_elements); + goto nextobj; + } + + elements = obj->package.elements; + + /* sanity checking */ + if (elements[NAME].type != ACPI_TYPE_STRING) { + pr_debug("incorrect element type\n"); + goto nextobj; + } + if (strlen(elements[NAME].string.pointer) == 0) { + pr_debug("empty attribute found\n"); + goto nextobj; + } + + if (attr_type == HPWMI_PASSWORD_TYPE) + tmp_set = bioscfg_drv.authentication_dir_kset; + else + tmp_set = bioscfg_drv.main_dir_kset; + + /* convert attribute name to string */ + retval = convert_hexstr_to_str(elements[NAME].string.pointer, + elements[NAME].string.length, + &str_value, &str_len); + + if (retval) { + pr_debug("Failed to populate integer package data. Error [0%0x]\n", ret); + kfree(str_value); + return ret; + } + + if (kset_find_obj(tmp_set, str_value)) { + pr_debug("Duplicate attribute name found - %s\n", + str_value); + goto nextobj; + } + + /* build attribute */ + attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + retval = -ENOMEM; + goto err_attr_init; + } + + attr_name_kobj->kset = tmp_set; + + retval = kobject_init_and_add(attr_name_kobj, &attr_name_ktype, + NULL, "%s", str_value); + + if (retval) { + kobject_put(attr_name_kobj); + goto err_attr_init; + } + + /* enumerate all of these attributes */ + switch (attr_type) { + case HPWMI_STRING_TYPE: + retval = populate_string_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_INTEGER_TYPE: + retval = populate_integer_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_ENUMERATION_TYPE: + retval = populate_enumeration_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_ORDERED_LIST_TYPE: + retval = populate_ordered_list_package_data(elements, + instance_id, + attr_name_kobj); + break; + case HPWMI_PASSWORD_TYPE: + retval = populate_password_package_data(elements, + instance_id, + attr_name_kobj); + break; + default: + break; + } + + kfree(str_value); + } + + if (obj->type == ACPI_TYPE_BUFFER) { + + buffer_size = obj->buffer.length; + buffer_ptr = obj->buffer.pointer; + + retval = get_string_from_buffer(&buffer_ptr, &buffer_size, str, MAX_BUFF); + if (retval < 0) + goto err_attr_init; + + if (attr_type == HPWMI_PASSWORD_TYPE || attr_type == HPWMI_SECURE_PLATFORM_TYPE) + tmp_set = bioscfg_drv.authentication_dir_kset; + else + tmp_set = bioscfg_drv.main_dir_kset; + + if (kset_find_obj(tmp_set, str)) { + pr_warn("Duplicate attribute name found - %s\n", str); + goto nextobj; + } + + /* build attribute */ + attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL); + if (!attr_name_kobj) { + retval = -ENOMEM; + goto err_attr_init; + } + + attr_name_kobj->kset = tmp_set; + + temp_str = str; + if (attr_type == HPWMI_SECURE_PLATFORM_TYPE) + temp_str = "SPM"; + + retval = kobject_init_and_add(attr_name_kobj, + &attr_name_ktype, NULL, "%s", + temp_str); + if (retval) { + kobject_put(attr_name_kobj); + goto err_attr_init; + } + + /* enumerate all of these attributes */ + switch (attr_type) { + case HPWMI_STRING_TYPE: + retval = populate_string_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_INTEGER_TYPE: + retval = populate_integer_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_ENUMERATION_TYPE: + retval = populate_enumeration_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_ORDERED_LIST_TYPE: + retval = populate_ordered_list_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + case HPWMI_PASSWORD_TYPE: + retval = populate_password_buffer_data(buffer_ptr, + &buffer_size, + instance_id, + attr_name_kobj); + break; + default: + break; + } + } +nextobj: + kfree(str_value); + kfree(obj); + instance_id++; + obj = get_wmiobj_pointer(instance_id, guid); + } + mutex_unlock(&bioscfg_drv.mutex); + return 0; + +err_attr_init: + mutex_unlock(&bioscfg_drv.mutex); + kfree(obj); + return retval; +} + +static int __init bioscfg_init(void) +{ + int ret = 0; + int bios_capable = wmi_has_guid(HP_WMI_BIOS_GUID); + + if (!bios_capable) { + pr_err("Unable to run on non-HP system\n"); + return -ENODEV; + } + + ret = init_bios_attr_set_interface(); + if (ret) + return ret; + + ret = init_bios_attr_pass_interface(); + if (ret) + goto err_exit_bios_attr_set_interface; + + if (!bioscfg_drv.bios_attr_wdev || !bioscfg_drv.password_attr_wdev) { + pr_debug("Failed to find set or pass interface\n"); + ret = -ENODEV; + goto err_exit_bios_attr_pass_interface; + } + + ret = fw_attributes_class_get(&fw_attr_class); + if (ret) + goto err_exit_bios_attr_pass_interface; + + bioscfg_drv.class_dev = device_create(fw_attr_class, NULL, MKDEV(0, 0), + NULL, "%s", DRIVER_NAME); + if (IS_ERR(bioscfg_drv.class_dev)) { + ret = PTR_ERR(bioscfg_drv.class_dev); + goto err_unregister_class; + } + + bioscfg_drv.main_dir_kset = kset_create_and_add("attributes", NULL, + &bioscfg_drv.class_dev->kobj); + if (!bioscfg_drv.main_dir_kset) { + ret = -ENOMEM; + pr_debug("Failed to create and add attributes\n"); + goto err_destroy_classdev; + } + + bioscfg_drv.authentication_dir_kset = kset_create_and_add("authentication", NULL, + &bioscfg_drv.class_dev->kobj); + if (!bioscfg_drv.authentication_dir_kset) { + ret = -ENOMEM; + pr_debug("Failed to create and add authentication\n"); + goto err_release_attributes_data; + } + + /* + * sysfs level attributes. + * - pending_reboot + */ + ret = create_attributes_level_sysfs_files(); + if (ret) + pr_debug("Failed to create sysfs level attributes\n"); + + ret = hp_init_bios_attributes(HPWMI_STRING_TYPE, HP_WMI_BIOS_STRING_GUID); + if (ret) + pr_debug("Failed to populate string type attributes\n"); + + ret = hp_init_bios_attributes(HPWMI_INTEGER_TYPE, HP_WMI_BIOS_INTEGER_GUID); + if (ret) + pr_debug("Failed to populate integer type attributes\n"); + + ret = hp_init_bios_attributes(HPWMI_ENUMERATION_TYPE, HP_WMI_BIOS_ENUMERATION_GUID); + if (ret) + pr_debug("Failed to populate enumeration type attributes\n"); + + ret = hp_init_bios_attributes(HPWMI_ORDERED_LIST_TYPE, HP_WMI_BIOS_ORDERED_LIST_GUID); + if (ret) + pr_debug("Failed to populate ordered list object type attributes\n"); + + ret = hp_init_bios_attributes(HPWMI_PASSWORD_TYPE, HP_WMI_BIOS_PASSWORD_GUID); + if (ret) + pr_debug("Failed to populate password object type attributes\n"); + + bioscfg_drv.spm_data.attr_name_kobj = NULL; + ret = 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 = NULL; + ret = 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(); + +err_exit_bios_attr_pass_interface: + exit_bios_attr_pass_interface(); + +err_exit_bios_attr_set_interface: + exit_bios_attr_set_interface(); + + return ret; +} + +static void __exit bioscfg_exit(void) +{ + release_attributes_data(); + device_destroy(fw_attr_class, MKDEV(0, 0)); + + fw_attributes_class_put(); + exit_bios_attr_set_interface(); + exit_bios_attr_pass_interface(); +} + +module_init(bioscfg_init); +module_exit(bioscfg_exit); From patchwork Thu Apr 20 16:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219004 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 E1451C77B72 for ; Thu, 20 Apr 2023 16:55:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjDTQzJ (ORCPT ); Thu, 20 Apr 2023 12:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbjDTQzF (ORCPT ); Thu, 20 Apr 2023 12:55:05 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE572D78; Thu, 20 Apr 2023 09:55:01 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6a5f6349ec3so491353a34.0; Thu, 20 Apr 2023 09:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009701; x=1684601701; 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=gT36Agbu21+vDf9VnVykQzz3eSgEq82FyIGTKTVofkg=; b=YjTK974qtbxeUJo8a31DNFQl/E+VNJm7IeHSYZsgIymsCsdQKI/Igqg6zroidp/LLG 7GLBauRSotRfzm84S/UNWjMS9wiJRdZ5SJRyxgopJXV3nnNvXicWY22JEol7JiHRZXIv VLemFmqbo3hc3gKMoU8udkFuoz5RSo8j1tsmRd3fyaY6Fno9T5FwG9tkgnnrb7vUiTl+ DCQ8dlZgUhDW3PPI9kpa7nIj8zcLRoW/OpsLf2Ssqj97jKnplbIKwddb0WE0KfNWU5Tn 6VRtbGS/OMYTJ0cowQut8qofIFbyuODWJtURjNWzZrxKDsK65pJsJYIVX6k+rTmeQQHm rWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009701; x=1684601701; 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=gT36Agbu21+vDf9VnVykQzz3eSgEq82FyIGTKTVofkg=; b=eXz0g633cs2qNwZH+/sB42n/a0NZPkTGmD3jdgqTm+/W0n4HRXqwAR3Cbfy021wUmK UUgJulLwwYZ6gN+Ab4G9sM0Gjz3WkQZgM1qSfrsGDly3aoEFFyXiBaKsC2f0xYrztH99 op+GsRscADAFZgAOT5Vlvp0azxsI7OWnW4ADUAG4OQBaS0KmDIZaUKBfQPrN9SDnJNrs BavsB2cMvxFgwsmKJq4hv9t+UfoU4oEHB33532XZ/t8QJD5x+aMTv7Rou0DH7W0LuOgZ keUciC5Mf7Zms2WjWZUrdUmQP2t3CDEbSUjZDWYIOj2eg+u7B4E+eROQ9Ey1XCF1Y3qd PGJw== X-Gm-Message-State: AAQBX9fO90t00jVvwIRFM+Hkdt13utkiGxjuX2wAKMn80dlFaExbSQBr mjfRe9ib+V+HiKweP3BCPQHhg+rl2kE= X-Google-Smtp-Source: AKy350bjMnQ0jpsNvTLsH6CrGWdSR+rprTY08dpr387wpS9E14EwveughMqJUcRsZ3zgpU0YvdGbTA== X-Received: by 2002:a05:6870:1fcf:b0:177:b64e:517f with SMTP id gp15-20020a0568701fcf00b00177b64e517fmr1558299oac.20.1682009700983; Thu, 20 Apr 2023 09:55:00 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:00 -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 Subject: [PATCH v11 04/14] HP BIOSCFG driver - int-attributes Date: Thu, 20 Apr 2023 11:54:44 -0500 Message-Id: <20230420165454.9517-5-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 474 ++++++++++++++++++ 1 file changed, 474 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..d8ee39dac3f9 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c @@ -0,0 +1,474 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to integer type attributes under + * BIOS Enumeration GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 Hewlett-Packard Inc. + */ + +#include "bioscfg.h" + +GET_INSTANCE_ID(integer); + +static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + int instance_id = get_integer_instance_id(kobj); + + if (instance_id < 0) + return instance_id; + + 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; + + + /* BIOS treats it as a read only attribute */ + if (bioscfg_drv.integer_data[instance_id].common.is_readonly) + return -EIO; + + ret = kstrtoint(buf, 10, &in_val); + if (ret < 0) + return ret; + + + if (in_val < bioscfg_drv.integer_data[instance_id].lower_bound || + in_val > bioscfg_drv.integer_data[instance_id].upper_bound) + return -ERANGE; + + /* + * set pending reboot flag depending on + * "RequiresPhysicalPresence" value + */ + if (bioscfg_drv.integer_data[instance_id].common.requires_physical_presence) + bioscfg_drv.pending_reboot = true; + return 0; +} + +static void update_integer_value(int instance_id, char *attr_value) +{ + int in_val; + int ret; + + ret = kstrtoint(attr_value, 10, &in_val); + if (ret == 0) + bioscfg_drv.integer_data[instance_id].current_value = in_val; +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, integer); +static struct kobj_attribute integer_display_langcode = + __ATTR_RO(display_name_language_code); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, integer); +static struct kobj_attribute integer_display_name = + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, integer); +static struct kobj_attribute integer_current_val = + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_N_PROPERTY_SHOW(lower_bound, integer); +static struct kobj_attribute integer_lower_bound = + __ATTR_RO(lower_bound); + +ATTRIBUTE_N_PROPERTY_SHOW(upper_bound, integer); +static struct kobj_attribute integer_upper_bound = + __ATTR_RO(upper_bound); + +ATTRIBUTE_N_COMMON_PROPERTY_SHOW(prerequisites_size, integer); +static struct kobj_attribute integer_prerequisites_size_val = + __ATTR_RO(prerequisites_size); + +ATTRIBUTE_V_COMMON_PROPERTY_SHOW(prerequisites, integer); +static struct kobj_attribute integer_prerequisites_val = + __ATTR_RO(prerequisites); + +ATTRIBUTE_N_PROPERTY_SHOW(scalar_increment, integer); +static struct kobj_attribute integer_scalar_increment = + __ATTR_RO(scalar_increment); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "integer\n"); +} +static struct kobj_attribute integer_type = + __ATTR_RO(type); + +static struct attribute *integer_attrs[] = { + &integer_display_langcode.attr, + &integer_display_name.attr, + &integer_current_val.attr, + &integer_lower_bound.attr, + &integer_upper_bound.attr, + &integer_scalar_increment.attr, + &integer_prerequisites_size_val.attr, + &integer_prerequisites_val.attr, + &integer_type.attr, + NULL +}; + +static const struct attribute_group integer_attr_group = { + .attrs = integer_attrs, +}; + +int alloc_integer_data(void) +{ + int ret = 0; + + bioscfg_drv.integer_instances_count = get_instance_count(HP_WMI_BIOS_INTEGER_GUID); + bioscfg_drv.integer_data = kcalloc(bioscfg_drv.integer_instances_count, + sizeof(struct integer_data), GFP_KERNEL); + + if (!bioscfg_drv.integer_data) { + bioscfg_drv.integer_instances_count = 0; + ret = -ENOMEM; + } + return ret; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_integer_types[] = { + [NAME] = ACPI_TYPE_STRING, + [VALUE] = ACPI_TYPE_STRING, + [PATH] = ACPI_TYPE_STRING, + [IS_READONLY] = ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER, + [SEQUENCE] = ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER, + [PREREQUISITES] = ACPI_TYPE_STRING, + [SECURITY_LEVEL] = ACPI_TYPE_INTEGER, + [INT_LOWER_BOUND] = ACPI_TYPE_INTEGER, + [INT_UPPER_BOUND] = ACPI_TYPE_INTEGER, + [INT_SCALAR_INCREMENT] = ACPI_TYPE_INTEGER +}; + +/* + * populate_int_data() - + * Populate all properties of an instance under integer attribute + * + * @integer_obj: ACPI object with integer data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int populate_integer_package_data(union acpi_object *integer_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.integer_data[instance_id].attr_name_kobj = attr_name_kobj; + populate_integer_elements_from_package(integer_obj, + integer_obj->package.count, + instance_id); + update_attribute_permissions(bioscfg_drv.integer_data[instance_id].common.is_readonly, + &integer_current_val); + friendly_user_name_update(bioscfg_drv.integer_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.integer_data[instance_id].common.display_name, + sizeof(bioscfg_drv.integer_data[instance_id].common.display_name)); + return sysfs_create_group(attr_name_kobj, &integer_attr_group); +} + +int populate_integer_elements_from_package(union acpi_object *integer_obj, + int integer_obj_count, + int instance_id) +{ + char *str_value = NULL; + int value_len; + int ret = 0; + u32 size = 0; + u32 int_value; + int elem = 0; + int reqs; + int eloc; + + if (!integer_obj) + return -EINVAL; + + strscpy(bioscfg_drv.integer_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.integer_data[instance_id].common.display_name_language_code)); + + for (elem = 1, eloc = 1; elem < integer_obj_count; elem++, eloc++) { + + /* ONLY look at the first INTEGER_ELEM_CNT elements */ + if (eloc == INTEGER_ELEM_CNT) + goto exit_integer_package; + + switch (integer_obj[elem].type) { + case ACPI_TYPE_STRING: + + if (elem != PREREQUISITES) { + ret = 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 = (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] != 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 = kstrtoint(str_value, 10, &int_value); + if (ret) + continue; + + bioscfg_drv.integer_data[instance_id].current_value = int_value; + break; + case PATH: + strscpy(bioscfg_drv.integer_data[instance_id].common.path, str_value, + sizeof(bioscfg_drv.integer_data[instance_id].common.path)); + break; + case IS_READONLY: + bioscfg_drv.integer_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.integer_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.integer_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.integer_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.integer_data[instance_id].common.prerequisites_size = int_value; + + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites 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. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + case PREREQUISITES: + size = bioscfg_drv.integer_data[instance_id].common.prerequisites_size; + + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + if (elem >= integer_obj_count) { + pr_err("Error elem-objects package is too small\n"); + return -EINVAL; + } + + ret = convert_hexstr_to_str(integer_obj[elem + reqs].string.pointer, + integer_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(bioscfg_drv.integer_data[instance_id].common.prerequisites[reqs], + str_value, + sizeof(bioscfg_drv.integer_data[instance_id].common.prerequisites[reqs])); + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.integer_data[instance_id].common.security_level = int_value; + break; + case INT_LOWER_BOUND: + bioscfg_drv.integer_data[instance_id].lower_bound = int_value; + break; + case INT_UPPER_BOUND: + bioscfg_drv.integer_data[instance_id].upper_bound = int_value; + break; + case INT_SCALAR_INCREMENT: + bioscfg_drv.integer_data[instance_id].scalar_increment = int_value; + break; + default: + pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem); + break; + } + } +exit_integer_package: + kfree(str_value); + return 0; +} + + +/* + * 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 populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.integer_data[instance_id].attr_name_kobj = attr_name_kobj; + + /* Populate integer elements */ + populate_integer_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + update_attribute_permissions(bioscfg_drv.integer_data[instance_id].common.is_readonly, + &integer_current_val); + friendly_user_name_update(bioscfg_drv.integer_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.integer_data[instance_id].common.display_name, + sizeof(bioscfg_drv.integer_data[instance_id].common.display_name)); + + return sysfs_create_group(attr_name_kobj, &integer_attr_group); +} + +int populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id) +{ + char *dst = NULL; + int elem; + int reqs; + int integer; + int size = 0; + int ret; + int dst_size = *buffer_size / sizeof(u16); + + dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + elem = 0; + strscpy(bioscfg_drv.integer_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.integer_data[instance_id].common.display_name_language_code)); + + for (elem = 1; elem < 3; elem++) { + + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + switch (elem) { + case VALUE: + ret = kstrtoint(dst, 10, &integer); + if (ret) + continue; + + bioscfg_drv.integer_data[instance_id].current_value = integer; + break; + case PATH: + strscpy(bioscfg_drv.integer_data[instance_id].common.path, dst, + sizeof(bioscfg_drv.integer_data[instance_id].common.path)); + break; + default: + pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem); + break; + } + } + + for (elem = 3; elem < INTEGER_ELEM_CNT; elem++) { + + if (elem != PREREQUISITES) { + ret = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer); + if (ret < 0) + continue; + } + + switch (elem) { + + case IS_READONLY: + bioscfg_drv.integer_data[instance_id].common.is_readonly = integer; + break; + case DISPLAY_IN_UI: + bioscfg_drv.integer_data[instance_id].common.display_in_ui = integer; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.integer_data[instance_id].common.requires_physical_presence = integer; + break; + case SEQUENCE: + bioscfg_drv.integer_data[instance_id].common.sequence = integer; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.integer_data[instance_id].common.prerequisites_size = integer; + size = integer; + if (size > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // PREREQUISITES: + elem++; + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.integer_data[instance_id].common.prerequisites[reqs], + dst, + sizeof(bioscfg_drv.integer_data[instance_id].common.prerequisites[reqs])); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.integer_data[instance_id].common.security_level = integer; + break; + case INT_LOWER_BOUND: + bioscfg_drv.integer_data[instance_id].lower_bound = integer; + break; + case INT_UPPER_BOUND: + bioscfg_drv.integer_data[instance_id].upper_bound = integer; + break; + case INT_SCALAR_INCREMENT: + bioscfg_drv.integer_data[instance_id].scalar_increment = integer; + break; + + default: + pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem); + break; + } + } + kfree(dst); + + return 0; +} + +/* + * exit_integer_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void exit_integer_attributes(void) +{ + int instance_id; + + for (instance_id = 0; instance_id < bioscfg_drv.integer_instances_count; instance_id++) { + + struct kobject *attr_name_kobj = 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 = 0; + + kfree(bioscfg_drv.integer_data); + bioscfg_drv.integer_data = NULL; +} From patchwork Thu Apr 20 16:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219003 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 7C379C77B7C for ; Thu, 20 Apr 2023 16:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbjDTQzK (ORCPT ); Thu, 20 Apr 2023 12:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbjDTQzH (ORCPT ); Thu, 20 Apr 2023 12:55:07 -0400 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285B74221; Thu, 20 Apr 2023 09:55:03 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id bb7-20020a056820160700b00546d9935668so830016oob.8; Thu, 20 Apr 2023 09:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009702; x=1684601702; 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=I0MN3rmC2Cti4f4qVv8lFeF+tvj8v0RUpECBbW/4GFg=; b=deH7FOyY31CM0n5o0pz6bFBR91hNGcPJos7XSjBHrF3i+Z25ls1hrwnwrIDUrk3seQ 6p4hV+lXFyjWunw+eD2+gOzEhmJzY034WlV1qjqe0RiJTZAoEdg7kMRig/x0zQRfKFqW 7GM9ZOtHH9yDWHys3diY91PATwSpp6K/X8FjMOnKcvXNRr+N3b1Y1z3BKqrQw+gd4e7p jQyY6XMovs4Y8gG+m8zGQiZZvBe40B5SfInd34KyEGQvvhipIspms7rFsY/auTcL+2/f 21M+mNnN8w1zeiylFzE506NNbyQ4Btsb/ok4JGWdk6tpjTz/bcsBSsuVR+7kEDcm7g4J qbSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009702; x=1684601702; 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=I0MN3rmC2Cti4f4qVv8lFeF+tvj8v0RUpECBbW/4GFg=; b=fNGLlzeMvNs5z77E5DCoEef3raahHbeS1qG+H7W2GlZzTKaFpU9Zzl9Hg8hYqNSJUD OoQmT7znt8dgxjvGx7qwPSn5yaya5geNnjb+6Wv7Ck5wEl01Vv97btrCkHbTU1yiYnUF sG+IqjTiMA+VcbSiqm+sWJDGUXCpbn4VFk/ONiPVDAssZoWxexcOvFRCqJFtzP8xA7DT BmN9b0bs+hgAOlERGnrjCEjRfhhmcw5hXOPRa+AN8E06Jos8CD7naA0IJ/jUomD85NLk 4ylrcRKHrf15uruO944vVuR5fh6Q4qY6YwmO+PVmmSQc+nJ2Sr7N5o/LxleooksPAeDB j1Ng== X-Gm-Message-State: AAQBX9fNVcYKN0Cxow1FsZzHGvyBV15z5L7byanZ9w3x4Vb1A18o6070 wPbfYftRSoFtDrHJGeB74FUoYQXXyDg= X-Google-Smtp-Source: AKy350bYDCyPnhV8HDe3Xxk3uPIb2u/NJBtmSDGUVJwOnNp1IioPuJ6LxloOsaeT50hPgloUZKxhgg== X-Received: by 2002:a4a:2c58:0:b0:546:3aa4:3dba with SMTP id o85-20020a4a2c58000000b005463aa43dbamr1193770ooo.7.1682009702398; Thu, 20 Apr 2023 09:55:02 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55: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 Subject: [PATCH v11 05/14] HP BIOSCFG driver - ordered-attributes Date: Thu, 20 Apr 2023 11:54:45 -0500 Message-Id: <20230420165454.9517-6-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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/ordered-attributes.c | 563 ++++++++++++++++++ 1 file changed, 563 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c new file mode 100644 index 000000000000..5e5d540f728d --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/ordered-attributes.c @@ -0,0 +1,563 @@ +// 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_attribute *attr, char *buf) +{ + + int instance_id = 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); +} + +/* + * validate_ordered_list_value - + * Validate input of current_value against possible values + * + * @instance_id: The instance on which input is validated + * @buf: Input value + */ +static int validate_ordered_list_values(int instance_id, const char *buf) +{ + int ret = 0; + int found = 0; + char *new_values = NULL; + char *value; + int elem; + int elem_found = 0; + + /* Is it a read only attribute */ + if (bioscfg_drv.ordered_list_data[instance_id].common.is_readonly) + return -EIO; + + new_values = kstrdup(buf, GFP_KERNEL); + + /* + * Changes to ordered list values require checking that new + * values are found in the list of elements. + */ + elem_found = 0; + while (elem_found < bioscfg_drv.ordered_list_data[instance_id].elements_size) { + + value = strsep(&new_values, ","); + if (value != NULL) { + if (!*value) + continue; + elem_found++; + } + + found = 0; + for (elem = 0; elem < bioscfg_drv.ordered_list_data[instance_id].elements_size; elem++) { + if (!strcasecmp(bioscfg_drv.ordered_list_data[instance_id].elements[elem], value)) { + found = 1; + break; + } + } + + + if (!found) { + ret = -EINVAL; + goto out_list_value; + } + } + + if (elem_found == bioscfg_drv.ordered_list_data[instance_id].elements_size) { + pr_warn("Number of new values is not equal to number of ordered list elements (%d)\n", + bioscfg_drv.ordered_list_data[instance_id].elements_size); + ret = -EINVAL; + goto out_list_value; + } + +out_list_value: + kfree(new_values); + return ret; +} + +/* + * validate_ordered_input() - + * Validate input of current_value against possible values + * + * @instance_id: The instance on which input is validated + * @buf: Input value + */ +static int validate_ordered_list_input(int instance_id, const char *buf) +{ + int ret = 0; + + ret = validate_ordered_list_values(instance_id, buf); + if (ret < 0) + return -EINVAL; + + /* + * set pending reboot flag depending on + * "RequiresPhysicalPresence" value + */ + if (bioscfg_drv.ordered_list_data[instance_id].common.requires_physical_presence) + bioscfg_drv.pending_reboot = true; + + return ret; +} + +static void update_ordered_list_value(int instance_id, char *attr_value) +{ + strscpy(bioscfg_drv.ordered_list_data[instance_id].current_value, + attr_value, + sizeof(bioscfg_drv.ordered_list_data[instance_id].current_value)); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, ordered_list); +static struct kobj_attribute ordered_list_display_langcode = + __ATTR_RO(display_name_language_code); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, ordered_list); +static struct kobj_attribute ordered_list_display_name = + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, ordered_list); +static struct kobj_attribute ordered_list_current_val = + __ATTR_RW_MODE(current_value, 0644); + + +ATTRIBUTE_N_COMMON_PROPERTY_SHOW(prerequisites_size, ordered_list); +static struct kobj_attribute ordered_list_prerequisites_size_val = + __ATTR_RO(prerequisites_size); + +ATTRIBUTE_V_COMMON_PROPERTY_SHOW(prerequisites, ordered_list); +static struct kobj_attribute ordered_list_prerequisites_val = + __ATTR_RO(prerequisites); + +ATTRIBUTE_N_PROPERTY_SHOW(elements_size, ordered_list); +static struct kobj_attribute ordered_list_elements_size_val = + __ATTR_RO(elements_size); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(elements, ordered_list); +static struct kobj_attribute ordered_list_elements_val = + __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 = + __ATTR_RO(type); + +static struct attribute *ordered_list_attrs[] = { + &ordered_list_display_langcode.attr, + &ordered_list_display_name.attr, + &ordered_list_current_val.attr, + &ordered_list_prerequisites_size_val.attr, + &ordered_list_prerequisites_val.attr, + &ordered_list_elements_val.attr, + &ordered_list_elements_size_val.attr, + &ordered_list_type.attr, + NULL +}; + +static const struct attribute_group ordered_list_attr_group = { + .attrs = ordered_list_attrs, +}; + +int alloc_ordered_list_data(void) +{ + int ret = 0; + + bioscfg_drv.ordered_list_instances_count = + get_instance_count(HP_WMI_BIOS_ORDERED_LIST_GUID); + bioscfg_drv.ordered_list_data = kcalloc(bioscfg_drv.ordered_list_instances_count, + sizeof(struct ordered_list_data), GFP_KERNEL); + if (!bioscfg_drv.ordered_list_data) { + bioscfg_drv.ordered_list_instances_count = 0; + ret = -ENOMEM; + } + return ret; +} + +/* + * 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 populate_ordered_list_package_data(union acpi_object *order_obj, int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.ordered_list_data[instance_id].attr_name_kobj = attr_name_kobj; + + populate_ordered_list_elements_from_package(order_obj, + order_obj->package.count, + instance_id); + update_attribute_permissions(bioscfg_drv.ordered_list_data[instance_id].common.is_readonly, + &ordered_list_current_val); + friendly_user_name_update(bioscfg_drv.ordered_list_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.ordered_list_data[instance_id].common.display_name, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.display_name)); + return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group); +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_order_types[] = { + [NAME] = ACPI_TYPE_STRING, + [VALUE] = ACPI_TYPE_STRING, + [PATH] = ACPI_TYPE_STRING, + [IS_READONLY] = ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER, + [SEQUENCE] = ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER, + [PREREQUISITES] = ACPI_TYPE_STRING, + [SECURITY_LEVEL] = ACPI_TYPE_INTEGER, + [ORD_LIST_SIZE] = ACPI_TYPE_INTEGER, + [ORD_LIST_ELEMENTS] = ACPI_TYPE_STRING +}; + + +int populate_ordered_list_elements_from_package(union acpi_object *order_obj, + int order_obj_count, + int instance_id) +{ + char *str_value = NULL; + int value_len; + int ret = 0; + u32 size = 0; + u32 int_value; + int elem = 0; + int reqs; + int eloc; + char *tmpstr = NULL; + char *part_tmp = NULL; + int tmp_len = 0; + char *part = NULL; + + if (!order_obj) + return -EINVAL; + + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.display_name_language_code)); + + for (elem = 1, eloc = 1; elem < order_obj_count; elem++, eloc++) { + + /* ONLY look at the first ORDERED_ELEM_CNT elements */ + if (eloc == ORDERED_ELEM_CNT) + goto exit_list_package; + + switch (order_obj[elem].type) { + case ACPI_TYPE_STRING: + + if (elem != PREREQUISITES && elem != ORD_LIST_ELEMENTS) { + ret = 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 = (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] != 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(bioscfg_drv.ordered_list_data[instance_id].current_value, + str_value, sizeof(bioscfg_drv.ordered_list_data[instance_id].current_value)); + break; + case PATH: + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.path, str_value, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.path)); + break; + case IS_READONLY: + bioscfg_drv.ordered_list_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.ordered_list_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.ordered_list_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.ordered_list_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.ordered_list_data[instance_id].common.prerequisites_size = int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites 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. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + case PREREQUISITES: + size = bioscfg_drv.ordered_list_data[instance_id].common.prerequisites_size; + + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + ret = convert_hexstr_to_str(order_obj[elem + reqs].string.pointer, + order_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.prerequisites[reqs], + str_value, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.prerequisites[reqs])); + + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.ordered_list_data[instance_id].common.security_level = int_value; + break; + + case ORD_LIST_SIZE: + bioscfg_drv.ordered_list_data[instance_id].elements_size = int_value; + if (int_value > MAX_ELEMENTS_SIZE) + pr_warn("Ordered List 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. ORD_LIST_ELEMENTS + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + case ORD_LIST_ELEMENTS: + size = bioscfg_drv.ordered_list_data[instance_id].elements_size; + + /* + * Ordered list data is stored in hex and comma separated format + * Convert the data and split it to show each element + */ + ret = convert_hexstr_to_str(str_value, value_len, &tmpstr, &tmp_len); + if (ret) + goto exit_list_package; + + part_tmp = tmpstr; + part = strsep(&part_tmp, ","); + if (!part) + strscpy(bioscfg_drv.ordered_list_data[instance_id].elements[0], + tmpstr, + sizeof(bioscfg_drv.ordered_list_data[instance_id].elements[0])); + + for (elem = 1; elem < MAX_ELEMENTS_SIZE && part; elem++) { + strscpy(bioscfg_drv.ordered_list_data[instance_id].elements[elem], + part, + sizeof(bioscfg_drv.ordered_list_data[instance_id].elements[elem])); + part = strsep(&part_tmp, ","); + } + + kfree(tmpstr); + break; + default: + pr_warn("Invalid element: %d found in Ordered_List attribute or data may be malformed\n", elem); + break; + } + kfree(tmpstr); + kfree(str_value); + } + +exit_list_package: + kfree(tmpstr); + kfree(str_value); + return 0; +} + +/* + * populate_ordered_list_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 + * @enum_property_count: Total properties count under ordered list type + */ +int populate_ordered_list_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id, + struct kobject *attr_name_kobj) +{ + + bioscfg_drv.ordered_list_data[instance_id].attr_name_kobj = attr_name_kobj; + + /* Populate ordered list elements */ + populate_ordered_list_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + update_attribute_permissions(bioscfg_drv.ordered_list_data[instance_id].common.is_readonly, + &ordered_list_current_val); + friendly_user_name_update(bioscfg_drv.ordered_list_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.ordered_list_data[instance_id].common.display_name, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.display_name)); + + return sysfs_create_group(attr_name_kobj, &ordered_list_attr_group); +} + +int populate_ordered_list_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id) +{ + int ret; + char *dst = NULL; + int elem; + int reqs; + int integer; + int size = 0; + int values; + int dst_size = *buffer_size / sizeof(u16); + + dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + elem = 0; + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.display_name_language_code)); + + for (elem = 1; elem < 3; elem++) { + + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + switch (elem) { + case VALUE: + strscpy(bioscfg_drv.ordered_list_data[instance_id].current_value, + dst, sizeof(bioscfg_drv.ordered_list_data[instance_id].current_value)); + break; + case PATH: + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.path, dst, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.path)); + break; + default: + pr_warn("Invalid element: %d found in Ordered list attribute or data may be malformed\n", elem); + break; + } + } + for (elem = 3; elem < ORDERED_ELEM_CNT; elem++) { + + if (elem != PREREQUISITES && elem != ORD_LIST_ELEMENTS) { + ret = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer); + if (ret < 0) + continue; + } + + switch (elem) { + + case IS_READONLY: + bioscfg_drv.ordered_list_data[instance_id].common.is_readonly = integer; + break; + case DISPLAY_IN_UI: + bioscfg_drv.ordered_list_data[instance_id].common.display_in_ui = integer; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.ordered_list_data[instance_id].common.requires_physical_presence = integer; + break; + case SEQUENCE: + bioscfg_drv.ordered_list_data[instance_id].common.sequence = integer; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.ordered_list_data[instance_id].common.prerequisites_size = integer; + if (integer > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // PREREQUISITES: + elem++; + size = bioscfg_drv.ordered_list_data[instance_id].common.prerequisites_size; + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.ordered_list_data[instance_id].common.prerequisites[reqs], + dst, + sizeof(bioscfg_drv.ordered_list_data[instance_id].common.prerequisites[reqs])); + } + break; + case SECURITY_LEVEL: + bioscfg_drv.ordered_list_data[instance_id].common.security_level = integer; + break; + case ORD_LIST_SIZE: + bioscfg_drv.ordered_list_data[instance_id].elements_size = integer; + if (integer > MAX_ELEMENTS_SIZE) + pr_warn("Ordered List size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // ORD_LIST_ELEMENTS: + elem++; + size = bioscfg_drv.ordered_list_data[instance_id].elements_size; + for (values = 0; values < size && values < MAX_ELEMENTS_SIZE; values++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.ordered_list_data[instance_id].elements[values], + dst, + sizeof(bioscfg_drv.ordered_list_data[instance_id].elements)[values]); + } + break; + default: + pr_warn("Invalid element: %d found in Ordered list attribute or data may be malformed\n", elem); + break; + } + } + kfree(dst); + + return 0; +} + + +/* + * exit_ordered_list_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void exit_ordered_list_attributes(void) +{ + int instance_id; + + for (instance_id = 0; instance_id < bioscfg_drv.ordered_list_instances_count; instance_id++) { + struct kobject *attr_name_kobj = 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 = 0; + + kfree(bioscfg_drv.ordered_list_data); + bioscfg_drv.ordered_list_data = NULL; +} From patchwork Thu Apr 20 16:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219006 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 7EA47C77B72 for ; Thu, 20 Apr 2023 16:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbjDTQz2 (ORCPT ); Thu, 20 Apr 2023 12:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbjDTQzI (ORCPT ); Thu, 20 Apr 2023 12:55:08 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E372F46BB; Thu, 20 Apr 2023 09:55:04 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-38e3a1a07c8so758785b6e.0; Thu, 20 Apr 2023 09:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009704; x=1684601704; 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=oJzFd9DQWnocycMGXpRDKiH/Hn/0E4Pxo0xVt+mEMjI=; b=CDLnGTlTwb6iNIynJI3na7P9nYsHriBHHntRryLfAZjJYk26v9slJ8ULQOWs5xnZIX qS80D1mxOWwMZzdlfAUvWuN/Zv/BlA1AQybpH5x11pgDwofdWA6ad0M7FCV+QKoquYR5 C0ejJbJ8iEq9+tdWhOBlku3d8JIz8ylPoKwB6tpOuiYYpMI5P/Tp+0ENf13phjuNjmvL W6AtrO8gMbMjSNBzmx7iTK1zZUAO4uMa6LCMJp3WFGj+6H/EW2yduDEuJ0Jgn0Ev1AVP VLEuiirs2GxXGbDw166mSKfL4/Y2nbYZgKMTscX+YUi+5eyqmvuvSoORh+GEjMjgEZQe A/bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009704; x=1684601704; 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=oJzFd9DQWnocycMGXpRDKiH/Hn/0E4Pxo0xVt+mEMjI=; b=FIbWGUNilWmP/Xo0k9sNjAsx/w5Z1b1NuiHSTFjbuf8WAxPzeo8cncT68ImM8cUEEr vAQpLTdoQC02H2lgxCoUUxOhqMQdphvLsOjHWn4bSaH1ZNc7qCYXdZKYbCTC3FR5Jfpq 3Dkrw6N+iE1S+CKZL9yEwtmdtecoj+Y4tCK9XxV1E0k7G039szz0HO4NITMaRyWVsOfQ WOtC0Ok6QL9XSJyY72MbLX5eG/Q+5SfTcNKcFTT+pxUzdHqlb8YKwv7a/T3hhH8sf8gd AFm/hFXgSUYJagjVWxR+qvaCvbHriOkHKpKOdTde8yMlGQvMbUS+3xhK7tJ2cvXv2ba6 ttxQ== X-Gm-Message-State: AAQBX9cjWDnmiWLRxzMkwbZvwMrBowaO4SHFDyh2CAA4wQO495UigRG5 VhuYD/pZcomsCs3yONekzIYGnNlL1sw= X-Google-Smtp-Source: AKy350aabNy0z6fJQSQeRDA/1E10toSYg9AqECxhh/Fv1a3Suye0O/A3+QgkzAMKveAu1zaVmHwTgQ== X-Received: by 2002:a54:4383:0:b0:38d:e9b3:e671 with SMTP id u3-20020a544383000000b0038de9b3e671mr1343001oiv.10.1682009703695; Thu, 20 Apr 2023 09:55:03 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55: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 Subject: [PATCH v11 06/14] HP BIOSCFG driver - passwdobj-attributes Date: Thu, 20 Apr 2023 11:54:46 -0500 Message-Id: <20230420165454.9517-7-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 669 ++++++++++++++++++ 1 file changed, 669 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/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c new file mode 100644 index 000000000000..c03b3a71e9c4 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c @@ -0,0 +1,669 @@ +// 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 + */ +int clear_passwords(const int instance) +{ + if (!bioscfg_drv.password_data[instance].is_enabled) + return 0; + + memset(bioscfg_drv.password_data[instance].current_password, + 0, sizeof(bioscfg_drv.password_data[instance].current_password)); + memset(bioscfg_drv.password_data[instance].new_password, + 0, sizeof(bioscfg_drv.password_data[instance].new_password)); + + return 0; +} + +/* + * Clear all credentials copied to memory for both Power-ON and Setup + * BIOS instances + */ +int clear_all_credentials(void) +{ + int instance; + + /* clear all passwords */ + for (instance = 0; instance < bioscfg_drv.password_instances_count; instance++) + clear_passwords(instance); + + /* clear auth_token */ + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token = NULL; + + return 0; +} + +int get_password_instance_for_type(const char *name) +{ + int count = bioscfg_drv.password_instances_count; + int instance; + + for (instance = 0; instance < count; instance++) { + if (strcmp(bioscfg_drv.password_data[instance].common.display_name, name) == 0) + return instance; + } + return -EINVAL; +} + +int validate_password_input(int instance_id, const char *buf) +{ + int length; + + length = strlen(buf); + if (buf[length-1] == '\n') + length--; + + if (length > MAX_PASSWD_SIZE) + return INVALID_BIOS_AUTH; + + if (bioscfg_drv.password_data[instance_id].min_password_length > length || + bioscfg_drv.password_data[instance_id].max_password_length < length) + return INVALID_BIOS_AUTH; + return SUCCESS; +} + +int password_is_set(const char *name) +{ + int id; + + id = get_password_instance_for_type(name); + if (id < 0) + return 0; + + return bioscfg_drv.password_data[id].is_enabled; +} + +ATTRIBUTE_N_PROPERTY_SHOW(is_enabled, password); +static struct kobj_attribute password_is_password_set = __ATTR_RO(is_enabled); + +static ssize_t current_password_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + char *p, *buf_cp; + int id, ret = 0; + + buf_cp = kstrdup(buf, GFP_KERNEL); + if (!buf_cp) { + ret = -ENOMEM; + goto exit_password; + } + + p = memchr(buf_cp, '\n', count); + + if (p != NULL) + *p = '\0'; + + id = get_password_instance_id(kobj); + + if (id >= 0) + ret = validate_password_input(id, buf_cp); + + if (!ret) { + strscpy(bioscfg_drv.password_data[id].current_password, + buf_cp, + sizeof(bioscfg_drv.password_data[id].current_password)); + /* + * set pending reboot flag depending on + * "RequiresPhysicalPresence" value + */ + if (bioscfg_drv.password_data[id].common.requires_physical_presence) + bioscfg_drv.pending_reboot = true; + } + +exit_password: + kfree(buf_cp); + return ret ? ret : count; +} +static struct kobj_attribute password_current_password = __ATTR_WO(current_password); + +static ssize_t new_password_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + char *p, *buf_cp = NULL; + int id = 0; + int ret = -EIO; + + buf_cp = kstrdup(buf, GFP_KERNEL); + if (!buf_cp) { + ret = -ENOMEM; + goto exit_password; + } + + p = memchr(buf_cp, '\n', count); + + if (p != NULL) + *p = '\0'; + + id = get_password_instance_id(kobj); + + if (id >= 0) + ret = validate_password_input(id, buf_cp); + + if (!ret) + strscpy(bioscfg_drv.password_data[id].new_password, + buf_cp, + sizeof(bioscfg_drv.password_data[id].new_password)); + + if (!ret) + ret = hp_set_attribute(kobj->name, buf_cp); + +exit_password: + /* + * Regardless of the results both new and current passwords + * will be set to zero and avoid security issues + */ + clear_passwords(id); + + kfree(buf_cp); + return ret ? ret : count; +} + +static struct kobj_attribute password_new_password = __ATTR_WO(new_password); + + +ATTRIBUTE_N_PROPERTY_SHOW(min_password_length, password); +static struct kobj_attribute password_min_password_length = __ATTR_RO(min_password_length); + +ATTRIBUTE_N_PROPERTY_SHOW(max_password_length, password); +static struct kobj_attribute password_max_password_length = __ATTR_RO(max_password_length); + +static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + if (strcmp(kobj->name, SETUP_PASSWD) == 0) + return sysfs_emit(buf, "%s\n", BIOS_ADMIN); + + if (strcmp(kobj->name, POWER_ON_PASSWD) == 0) + return sysfs_emit(buf, "%s\n", POWER_ON); + + return -EIO; +} +static struct kobj_attribute password_role = __ATTR_RO(role); + +static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + int i = get_password_instance_id(kobj); + + if (i < 0) + return i; + + if (bioscfg_drv.password_data[i].mechanism != PASSWORD) + return -EINVAL; + + return sysfs_emit(buf, "%s\n", PASSWD_MECHANISM_TYPES); +} +static struct kobj_attribute password_mechanism = __ATTR_RO(mechanism); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "password\n"); +} +static struct kobj_attribute password_type = __ATTR_RO(type); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, password); +static struct kobj_attribute password_display_name = + __ATTR_RO(display_name); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, password); +static struct kobj_attribute password_display_langcode = + __ATTR_RO(display_name_language_code); + +ATTRIBUTE_N_COMMON_PROPERTY_SHOW(prerequisites_size, password); +static struct kobj_attribute password_prerequisites_size_val = + __ATTR_RO(prerequisites_size); + +ATTRIBUTE_V_COMMON_PROPERTY_SHOW(prerequisites, password); +static struct kobj_attribute password_prerequisites_val = + __ATTR_RO(prerequisites); + +ATTRIBUTE_N_PROPERTY_SHOW(encodings_size, password); +static struct kobj_attribute password_encodings_size_val = + __ATTR_RO(encodings_size); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(encodings, password); +static struct kobj_attribute password_encodings_val = + __ATTR_RO(encodings); + + +static struct attribute *password_attrs[] = { + &password_is_password_set.attr, + &password_min_password_length.attr, + &password_max_password_length.attr, + &password_current_password.attr, + &password_new_password.attr, + &password_role.attr, + &password_mechanism.attr, + &password_type.attr, + &password_display_name.attr, + &password_display_langcode.attr, + &password_prerequisites_size_val.attr, + &password_prerequisites_val.attr, + &password_encodings_val.attr, + &password_encodings_size_val.attr, + NULL +}; + +static const struct attribute_group bios_password_attr_group = { + .attrs = password_attrs +}; + +static const struct attribute_group system_password_attr_group = { + .attrs = password_attrs +}; + +int alloc_password_data(void) +{ + int ret = 0; + + bioscfg_drv.password_instances_count = get_instance_count(HP_WMI_BIOS_PASSWORD_GUID); + bioscfg_drv.password_data = kcalloc(bioscfg_drv.password_instances_count, + sizeof(struct password_data), GFP_KERNEL); + if (!bioscfg_drv.password_data) { + bioscfg_drv.password_instances_count = 0; + ret = -ENOMEM; + } + + return ret; +} + +/* + * populate_password_package_data - + * Populate all properties for an instance under password attribute + * + * @password_obj: ACPI object with password data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int populate_password_package_data(union acpi_object *password_obj, int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.password_data[instance_id].attr_name_kobj = attr_name_kobj; + + populate_password_elements_from_package(password_obj, + password_obj->package.count, + instance_id); + + if (strcmp(attr_name_kobj->name, "Setup Password") == 0) { + /* Save system authentication instance for easy access */ + return sysfs_create_group(attr_name_kobj, &bios_password_attr_group); + } + + return sysfs_create_group(attr_name_kobj, &system_password_attr_group); +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_password_types[] = { + [NAME] = ACPI_TYPE_STRING, + [VALUE] = ACPI_TYPE_STRING, + [PATH] = ACPI_TYPE_STRING, + [IS_READONLY] = ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER, + [SEQUENCE] = ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER, + [PREREQUISITES] = ACPI_TYPE_STRING, + [SECURITY_LEVEL] = ACPI_TYPE_INTEGER, + [PSWD_MIN_LENGTH] = ACPI_TYPE_INTEGER, + [PSWD_MAX_LENGTH] = ACPI_TYPE_INTEGER, + [PSWD_SIZE] = ACPI_TYPE_INTEGER, + [PSWD_ENCODINGS] = ACPI_TYPE_STRING, + [PSWD_IS_SET] = ACPI_TYPE_INTEGER +}; + + +int populate_password_elements_from_package(union acpi_object *password_obj, + int password_obj_count, + int instance_id) +{ + char *str_value = NULL; + int value_len; + int ret = 0; + u32 size = 0; + u32 int_value; + int elem = 0; + int reqs; + int eloc; + int pos_values; + + + if (!password_obj) + return -EINVAL; + + strscpy(bioscfg_drv.password_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.password_data[instance_id].common.display_name_language_code)); + + for (elem = 1, eloc = 1; elem < password_obj_count; elem++, eloc++) { + + /* ONLY look at the first PASSWORD_ELEM_CNT elements */ + if (eloc == PASSWORD_ELEM_CNT) + goto exit_package; + + switch (password_obj[elem].type) { + case ACPI_TYPE_STRING: + + if (PREREQUISITES != elem && PSWD_ENCODINGS != elem) { + ret = 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 = (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] != 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(bioscfg_drv.password_data[instance_id].common.path, str_value, + sizeof(bioscfg_drv.password_data[instance_id].common.path)); + break; + case IS_READONLY: + bioscfg_drv.password_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.password_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.password_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.password_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.password_data[instance_id].common.prerequisites_size = int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites 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. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + case PREREQUISITES: + size = bioscfg_drv.password_data[instance_id].common.prerequisites_size; + + for (reqs = 0; reqs < size; reqs++) { + ret = convert_hexstr_to_str(password_obj[elem + reqs].string.pointer, + password_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + break; + + strscpy(bioscfg_drv.password_data[instance_id].common.prerequisites[reqs], + str_value, + sizeof(bioscfg_drv.password_data[instance_id].common.prerequisites[reqs])); + + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.password_data[instance_id].common.security_level = int_value; + break; + + case PSWD_MIN_LENGTH: + bioscfg_drv.password_data[instance_id].min_password_length = int_value; + break; + case PSWD_MAX_LENGTH: + bioscfg_drv.password_data[instance_id].max_password_length = int_value; + break; + case PSWD_SIZE: + bioscfg_drv.password_data[instance_id].encodings_size = int_value; + if (int_value > MAX_ENCODINGS_SIZE) + pr_warn("Password Encoding 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. PSWD_ENCODINGS + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + + case PSWD_ENCODINGS: + size = bioscfg_drv.password_data[instance_id].encodings_size; + + for (pos_values = 0; pos_values < size && pos_values < MAX_ENCODINGS_SIZE; pos_values++) { + ret = convert_hexstr_to_str(password_obj[elem + pos_values].string.pointer, + password_obj[elem + pos_values].string.length, + &str_value, &value_len); + if (ret) + break; + + strscpy(bioscfg_drv.password_data[instance_id].encodings[pos_values], + str_value, + sizeof(bioscfg_drv.password_data[instance_id].encodings[pos_values])); + kfree(str_value); + } + break; + case PSWD_IS_SET: + bioscfg_drv.password_data[instance_id].is_enabled = int_value; + break; + + default: + pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem); + break; + } + kfree(str_value); + } + +exit_package: + kfree(str_value); + return 0; +} + +/* + * 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 populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size, int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.password_data[instance_id].attr_name_kobj = attr_name_kobj; + + /* Populate Password attributes */ + populate_password_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + friendly_user_name_update(bioscfg_drv.password_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.password_data[instance_id].common.display_name, + sizeof(bioscfg_drv.password_data[instance_id].common.display_name)); + if (strcmp(attr_name_kobj->name, "Setup Password") == 0) + return sysfs_create_group(attr_name_kobj, &bios_password_attr_group); + + return sysfs_create_group(attr_name_kobj, &system_password_attr_group); +} + +int populate_password_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id) +{ + int ret; + char *dst = NULL; + int elem; + int reqs; + int integer; + int size = 0; + int values; + int dst_size = *buffer_size / sizeof(u16); + + dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + elem = 0; + strscpy(bioscfg_drv.password_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.password_data[instance_id].common.display_name_language_code)); + + for (elem = 1; elem < 3; elem++) { + + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + switch (elem) { + case VALUE: + strscpy(bioscfg_drv.password_data[instance_id].current_password, + dst, sizeof(bioscfg_drv.password_data[instance_id].current_password)); + break; + case PATH: + strscpy(bioscfg_drv.password_data[instance_id].common.path, dst, + sizeof(bioscfg_drv.password_data[instance_id].common.path)); + break; + default: + pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem); + break; + } + } + + for (elem = 3; elem < PASSWORD_ELEM_CNT; elem++) { + + if (elem != PREREQUISITES && elem != PSWD_ENCODINGS) { + ret = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer); + if (ret) + continue; + } + + switch (elem) { + case IS_READONLY: + bioscfg_drv.password_data[instance_id].common.is_readonly = integer; + break; + case DISPLAY_IN_UI: + bioscfg_drv.password_data[instance_id].common.display_in_ui = integer; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.password_data[instance_id].common.requires_physical_presence = integer; + break; + case SEQUENCE: + bioscfg_drv.password_data[instance_id].common.sequence = integer; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.password_data[instance_id].common.prerequisites_size = integer; + if (integer > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // PREREQUISITES: + elem++; + size = bioscfg_drv.password_data[instance_id].common.prerequisites_size; + for (reqs = 0; reqs < size && reqs > MAX_PREREQUISITES_SIZE; reqs++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.password_data[instance_id].common.prerequisites[reqs], + dst, + sizeof(bioscfg_drv.password_data[instance_id].common.prerequisites[reqs])); + } + break; + case SECURITY_LEVEL: + bioscfg_drv.password_data[instance_id].common.security_level = integer; + break; + + case PSWD_MIN_LENGTH: + bioscfg_drv.password_data[instance_id].min_password_length = integer; + break; + case PSWD_MAX_LENGTH: + bioscfg_drv.password_data[instance_id].max_password_length = integer; + break; + case PSWD_SIZE: + bioscfg_drv.password_data[instance_id].encodings_size = integer; + if (integer > MAX_ENCODINGS_SIZE) + pr_warn("Password Encoding size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // PSWD_ENCODINGS: + elem++; + size = bioscfg_drv.password_data[instance_id].encodings_size; + for (values = 0; values < size && values < MAX_ENCODINGS_SIZE; values++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.password_data[instance_id].encodings[values], + dst, + sizeof(bioscfg_drv.password_data[instance_id].encodings[values])); + + } + break; + case PSWD_IS_SET: + bioscfg_drv.password_data[instance_id].is_enabled = integer; + break; + default: + pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem); + break; + } + } + kfree(dst); + return 0; +} + +/* + * exit_password_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void exit_password_attributes(void) +{ + int instance_id; + + for (instance_id = 0; instance_id < bioscfg_drv.password_instances_count; instance_id++) { + struct kobject *attr_name_kobj = bioscfg_drv.password_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) { + if (strcmp(attr_name_kobj->name, SETUP_PASSWD) == 0) + sysfs_remove_group(attr_name_kobj, + &bios_password_attr_group); + else + sysfs_remove_group(attr_name_kobj, + &system_password_attr_group); + } + } + bioscfg_drv.password_instances_count = 0; + kfree(bioscfg_drv.password_data); + bioscfg_drv.password_data = NULL; +} From patchwork Thu Apr 20 16:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219005 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 ED1C2C77B73 for ; Thu, 20 Apr 2023 16:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbjDTQz3 (ORCPT ); Thu, 20 Apr 2023 12:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjDTQzI (ORCPT ); Thu, 20 Apr 2023 12:55:08 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FCCA1FDA; Thu, 20 Apr 2023 09:55:05 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-38e4c98e5ceso370875b6e.1; Thu, 20 Apr 2023 09:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009705; x=1684601705; 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=Ozalp3KCLsv/1XGFew3iV1PCSC100UuMGxEjJVQkDCM=; b=atX6UvW1ZWbrYKhgGpV3/DpUyizU5uqFeQXb7sA4fSsetzauNRt40i4YqbokKviqC6 GdBEBXOV0e8BxeB1/NGacBleXGFmCGUQ6up8IL7dMYgl6TRva9i6zxWm5c1pzhGGTcuF mXwKvh/jn3WRfWEjxUnZdvp9LbDF2AyTo1WvH67H0YSk4obTF+c+D4DbrONAiqX5PlcL 5GFEBCYXOtc0JLT2InsNy1hx+OW6rFF25un1QeN6ro2Cj+v2uCfiquGKQHLRRl1dgBPk BGEeJp+OleGd+isf2MLn8LbtTCvpVALtnvjRf6IYHi7qvwtI15/RuOvNKdCq661MX4jQ jdlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009705; x=1684601705; 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=Ozalp3KCLsv/1XGFew3iV1PCSC100UuMGxEjJVQkDCM=; b=ayDxCgYGkdqRb+sBUmozWci6Pmj4NNyBaFm4dE8j9LrXA2pxWGloFnFx5dsR5QLVQv q1MkUomfwOMOmcay4zBZhzzq8cYF+Ysk+KWGD1NL+v/3cC583d++dyJoAp45YVRXAGDU +h0CjG2PMwjrI775Mw19LvEalDQ9KkhwjFoJ/DHuBBcc03U82YbHgn1ykrrvE4laMhHR X2XreijMfat6hy3SBokF8kVmDzMh6TNGqCPg5VUtP2w5siwCfA/qJ2K9Wb51g8eYZk6e Yuiol8c6JltZJvqNvjaVigXcGuy9ihV8n5A/t7ykoLk+5UB3C3EFX8rAiNCbh2y9VRVP p1Nw== X-Gm-Message-State: AAQBX9d9yUQDfeJfTsXxuoLsj6AtbL+UdPaBzN93wNqY+iyNgdn2w0yc mYeVuzdQwYMMkG/0RXLl92Y= X-Google-Smtp-Source: AKy350Z2qb9vgScbo+BcEjBoU2aq6doiSXoFdtELDie2C7eXsY3KOaA36mw7b+IBR4A+46MGm/s9aw== X-Received: by 2002:a05:6808:198d:b0:38d:eb0e:7b15 with SMTP id bj13-20020a056808198d00b0038deb0e7b15mr1580994oib.17.1682009704805; Thu, 20 Apr 2023 09:55:04 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:04 -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 Subject: [PATCH v11 07/14] HP BIOSCFG driver - string-attributes Date: Thu, 20 Apr 2023 11:54:47 -0500 Message-Id: <20230420165454.9517-8-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 451 ++++++++++++++++++ 1 file changed, 451 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/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c new file mode 100644 index 000000000000..7a14585d5506 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c @@ -0,0 +1,451 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to string type attributes under + * HP_WMI_BIOS_STRING_GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" + +#define WMI_STRING_TYPE "HPBIOS_BIOSString" + +GET_INSTANCE_ID(string); + +static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + int instance_id = get_string_instance_id(kobj); + + 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 = strlen(buf); + + /* BIOS treats it as a read only attribute */ + if (bioscfg_drv.string_data[instance_id].common.is_readonly) + return -EIO; + + if ((in_len < bioscfg_drv.string_data[instance_id].min_length) || + (in_len > bioscfg_drv.string_data[instance_id].max_length)) + return -ERANGE; + + /* + * set pending reboot flag depending on + * "RequiresPhysicalPresence" value + */ + if (bioscfg_drv.string_data[instance_id].common.requires_physical_presence) + bioscfg_drv.pending_reboot = true; + return 0; +} + +static void update_string_value(int instance_id, char *attr_value) +{ + /* Write settings to BIOS */ + strscpy(bioscfg_drv.string_data[instance_id].current_value, + attr_value, + sizeof(bioscfg_drv.string_data[instance_id].current_value)); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, string); +static struct kobj_attribute string_display_langcode = + __ATTR_RO(display_name_language_code); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, string); +static struct kobj_attribute string_display_name = + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, string); +static struct kobj_attribute string_current_val = + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_N_PROPERTY_SHOW(min_length, string); +static struct kobj_attribute string_min_length = + __ATTR_RO(min_length); + +ATTRIBUTE_N_PROPERTY_SHOW(max_length, string); +static struct kobj_attribute string_max_length = + __ATTR_RO(max_length); + +ATTRIBUTE_N_COMMON_PROPERTY_SHOW(prerequisites_size, string); +static struct kobj_attribute string_prerequisites_size_val = + __ATTR_RO(prerequisites_size); + +ATTRIBUTE_V_COMMON_PROPERTY_SHOW(prerequisites, string); +static struct kobj_attribute string_prerequisites_val = + __ATTR_RO(prerequisites); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "string\n"); +} +static struct kobj_attribute string_type = + __ATTR_RO(type); + +static struct attribute *string_attrs[] = { + &string_display_langcode.attr, + &string_display_name.attr, + &string_current_val.attr, + &string_min_length.attr, + &string_max_length.attr, + &string_prerequisites_size_val.attr, + &string_prerequisites_val.attr, + &string_type.attr, + NULL +}; + +static const struct attribute_group string_attr_group = { + .attrs = string_attrs, +}; + +int alloc_string_data(void) +{ + int ret = 0; + + bioscfg_drv.string_instances_count = get_instance_count(HP_WMI_BIOS_STRING_GUID); + bioscfg_drv.string_data = kcalloc(bioscfg_drv.string_instances_count, + sizeof(struct string_data), GFP_KERNEL); + if (!bioscfg_drv.string_data) { + bioscfg_drv.string_instances_count = 0; + ret = -ENOMEM; + } + return ret; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_string_types[] = { + [NAME] = ACPI_TYPE_STRING, + [VALUE] = ACPI_TYPE_STRING, + [PATH] = ACPI_TYPE_STRING, + [IS_READONLY] = ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER, + [SEQUENCE] = ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER, + [PREREQUISITES] = ACPI_TYPE_STRING, + [SECURITY_LEVEL] = ACPI_TYPE_INTEGER, + [STR_MIN_LENGTH] = ACPI_TYPE_INTEGER, + [STR_MAX_LENGTH] = ACPI_TYPE_INTEGER +}; + +/* + * 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 populate_string_package_data(union acpi_object *string_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.string_data[instance_id].attr_name_kobj = attr_name_kobj; + + populate_string_elements_from_package(string_obj, + string_obj->package.count, + instance_id); + + update_attribute_permissions(bioscfg_drv.string_data[instance_id].common.is_readonly, + &string_current_val); + friendly_user_name_update(bioscfg_drv.string_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.string_data[instance_id].common.display_name, + sizeof(bioscfg_drv.string_data[instance_id].common.display_name)); + return sysfs_create_group(attr_name_kobj, &string_attr_group); +} + +int populate_string_elements_from_package(union acpi_object *string_obj, + int string_obj_count, + int instance_id) +{ + char *str_value = NULL; + int value_len; + int ret = 0; + u32 size = 0; + u32 int_value; + int elem = 0; + int reqs; + int eloc; + + if (!string_obj) + return -EINVAL; + + strscpy(bioscfg_drv.string_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.string_data[instance_id].common.display_name_language_code)); + + for (elem = 1, eloc = 1; elem < string_obj_count; elem++, eloc++) { + + /* ONLY look at the first STRING_ELEM_CNT elements */ + if (eloc == STRING_ELEM_CNT) + goto exit_string_package; + + switch (string_obj[elem].type) { + case ACPI_TYPE_STRING: + + if (elem != PREREQUISITES) { + ret = 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 = (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] != 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(bioscfg_drv.string_data[instance_id].current_value, + str_value, sizeof(bioscfg_drv.string_data[instance_id].current_value)); + break; + case PATH: + strscpy(bioscfg_drv.string_data[instance_id].common.path, str_value, + sizeof(bioscfg_drv.string_data[instance_id].common.path)); + break; + case IS_READONLY: + bioscfg_drv.string_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.string_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.string_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.string_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.string_data[instance_id].common.prerequisites_size = int_value; + if (size > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites 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. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + case PREREQUISITES: + size = bioscfg_drv.string_data[instance_id].common.prerequisites_size; + + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + if (elem >= string_obj_count) { + pr_err("Error elem-objects package is too small\n"); + return -EINVAL; + } + + ret = convert_hexstr_to_str(string_obj[elem + reqs].string.pointer, + string_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + continue; + + strscpy(bioscfg_drv.string_data[instance_id].common.prerequisites[reqs], + str_value, + sizeof(bioscfg_drv.string_data[instance_id].common.prerequisites[reqs])); + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.string_data[instance_id].common.security_level = int_value; + break; + case STR_MIN_LENGTH: + bioscfg_drv.string_data[instance_id].min_length = int_value; + break; + case STR_MAX_LENGTH: + bioscfg_drv.string_data[instance_id].max_length = int_value; + break; + default: + pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem); + break; + } + + kfree(str_value); + } + +exit_string_package: + kfree(str_value); + return 0; +} + +/* + * populate_string_data() - + * Populate all properties of an instance under string attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.string_data[instance_id].attr_name_kobj = attr_name_kobj; + + populate_string_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + + update_attribute_permissions(bioscfg_drv.string_data[instance_id].common.is_readonly, + &string_current_val); + friendly_user_name_update(bioscfg_drv.string_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.string_data[instance_id].common.display_name, + sizeof(bioscfg_drv.string_data[instance_id].common.display_name)); + + return sysfs_create_group(attr_name_kobj, &string_attr_group); +} + +int populate_string_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id) +{ + int ret; + char *dst = NULL; + int elem; + int reqs; + int int_value; + int size = 0; + int dst_size = *buffer_size / sizeof(u16); + + dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + strscpy(bioscfg_drv.string_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.string_data[instance_id].common.display_name_language_code)); + + for (elem = 1; elem < 3; elem++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + /* Ignore. Zero length string values */ + if (ret < 0) + continue; + + switch (elem) { + case VALUE: + strscpy(bioscfg_drv.string_data[instance_id].current_value, + dst, sizeof(bioscfg_drv.string_data[instance_id].current_value)); + break; + case PATH: + strscpy(bioscfg_drv.string_data[instance_id].common.path, dst, + sizeof(bioscfg_drv.string_data[instance_id].common.path)); + break; + default: + pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem); + break; + } + } + + for (elem = 3; elem < STRING_ELEM_CNT; elem++) { + if (elem != PREREQUISITES) { + ret = get_integer_from_buffer((int **)&buffer_ptr, + buffer_size, + (int *)&int_value); + if (ret < 0) + continue; + } + + switch (elem) { + case IS_READONLY: + bioscfg_drv.string_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.string_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.string_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.string_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.string_data[instance_id].common.prerequisites_size = int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n"); + break; + + case PREREQUISITES: + size = bioscfg_drv.string_data[instance_id].common.prerequisites_size; + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + /* Ignore. Zero length string values */ + if (ret < 0) + continue; + strscpy(bioscfg_drv.string_data[instance_id].common.prerequisites[reqs], + dst, + sizeof(bioscfg_drv.string_data[instance_id].common.prerequisites[reqs])); + } + break; + case SECURITY_LEVEL: + bioscfg_drv.string_data[instance_id].common.security_level = int_value; + break; + case STR_MIN_LENGTH: + bioscfg_drv.string_data[instance_id].min_length = int_value; + break; + case STR_MAX_LENGTH: + bioscfg_drv.string_data[instance_id].max_length = int_value; + break; + default: + pr_warn("Invalid element: %d found in String attribute or data may be malformed\n", elem); + break; + } + } + kfree(dst); + return 0; +} + +/* + * exit_string_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void exit_string_attributes(void) +{ + int instance_id; + + for (instance_id = 0; instance_id < bioscfg_drv.string_instances_count; instance_id++) { + + struct kobject *attr_name_kobj = 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 = 0; + + kfree(bioscfg_drv.string_data); + bioscfg_drv.string_data = NULL; +} From patchwork Thu Apr 20 16:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219008 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 37560C77B7C for ; Thu, 20 Apr 2023 16:55:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbjDTQz3 (ORCPT ); Thu, 20 Apr 2023 12:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbjDTQzK (ORCPT ); Thu, 20 Apr 2023 12:55:10 -0400 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33004682; Thu, 20 Apr 2023 09:55:06 -0700 (PDT) Received: by mail-oo1-xc33.google.com with SMTP id bb7-20020a056820160700b00546d9935668so830082oob.8; Thu, 20 Apr 2023 09:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009706; x=1684601706; 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=P3WSGLSiykBs/xoevfiIDFdUQDdXJS9RPPYkkqgdmg8=; b=iqKViKeA60OYeaPjSrmcEDwL/LZouBcJLo9kukMIws69NZEkFIoa1HnAaZedt9PEC1 hE48TIqvTYxo0zPtYlzCZt5jGBovIzMLR9+fhVgckoVxw6rQ7Uvgr+V58XKspOvAFOKZ ejaIzk2TcdLvhocKTbWM7r+JURCPit0ZHDcU5mLw1oSAdOw8vdRjZtfCXRHgOYL/2erd BpbA5bj9cQa8wqqi1T9phvn/OSqHJf0p0x1UZJemwGOBiy3Vt4hUwfNWgMeo13iw1WTe Hvunbo1eIeSfI3aKadadAh4S1Dkc8MIIokcPdVTqLSFcMvBVlbKYequzEDnPx6chBYb+ vnQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009706; x=1684601706; 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=P3WSGLSiykBs/xoevfiIDFdUQDdXJS9RPPYkkqgdmg8=; b=JlhNVlSmGJG8sDrj5w+VsySonPU+mfS9OBG//8qnUg3n21stjxDvuS3Izc70NXmPpb bJimHli/YiyWEUqk1IPFWGLXqbEY8gLkofDw570bbEO+wOajheryWvPWUIzD8U3zewpT dY19cHAVPKPnWlPW69SpDtUhwFKqDghmRUhISrsNWeYzb20xNzQThRFBA1dEZRskSVDJ lpVo7S99kaK2uhR/Yy/h/dpt+c2/kxWfFuh4vEsNiqcWqovNzComyUTFVNGE6Q8zenMa 6lGXICOmPNPS36SHpKQqSspF3W5ee+4BM4Z2o40SnWWCYocj3FKpWP7ZlOs8m+4bKaj7 jRSQ== X-Gm-Message-State: AAQBX9dWWsJ0Tm8L3wEcBsAow6dHuZhQCnpIO9yyNd2Oz9L93ERfaqhI efzQt+DmzgEgxphx1VABIFo= X-Google-Smtp-Source: AKy350bTga/7DHu9MqGEXcZXGCQTWlKnOX5Pv1vqg/u+ZNCMgAjrxHPhTCmpZhSUUmGdZ3vQJ1P42g== X-Received: by 2002:a4a:95ce:0:b0:525:1903:5a70 with SMTP id p14-20020a4a95ce000000b0052519035a70mr1203827ooi.4.1682009706144; Thu, 20 Apr 2023 09:55:06 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:05 -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 Subject: [PATCH v11 08/14] HP BIOSCFG driver - bioscfg-h Date: Thu, 20 Apr 2023 11:54:48 -0500 Message-Id: <20230420165454.9517-9-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 613 +++++++++++++++++++ 1 file changed, 613 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/platform/x86/hp/hp-bioscfg/bioscfg.h new file mode 100644 index 000000000000..3f7d33b1b032 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.h @@ -0,0 +1,613 @@ +/* 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 +#include +#include + + +#define DRIVER_NAME "hp-bioscfg" + +#define MAX_BUFF 512 +#define MAX_KEY_MOD 256 +#define MAX_PASSWD_SIZE 64 +#define MAX_MESSAGE_SIZE 256 +#define 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" + +/* Sure Admin Functions */ + +#define UTF_PREFIX "" +#define BEAM_PREFIX "" + +/* mechanism - Authentication attribute */ + +#define MAX_MECHANISM_TYPES 3 + +enum mechanism_values { + PASSWORD = 0x00, + NOT_PROVISION = 0x00, + SIGNING_KEY = 0x01, + ENDORSEMENT_KEY = 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-7045CB4DA745" +#define HP_WMI_BIOS_PASSWORD_GUID "322F2028-0F84-4901-988E-015176049E2D" +#define HP_WMI_SET_BIOS_SETTING_GUID "1F4C91EB-DC5C-460b-951D-C7CB9B4B8D5E" + +enum hp_wmi_spm_commandtype { + HPWMI_SECUREPLATFORM_GET_STATE = 0x10, + HPWMI_SECUREPLATFORM_SET_KEK = 0x11, + HPWMI_SECUREPLATFORM_SET_SK = 0x12 +}; + +enum hp_wmi_surestart_commandtype { + HPWMI_SURESTART_GET_LOG_COUNT = 0x01, + HPWMI_SURESTART_GET_LOG = 0x02 +}; + +enum hp_wmi_command { + HPWMI_READ = 0x01, + HPWMI_WRITE = 0x02, + HPWMI_ODM = 0x03, + HPWMI_SURESTART = 0x20006, + HPWMI_GM = 0x20008, + HPWMI_SECUREPLATFORM = 0x20010 +}; + +struct bios_return { + u32 sigpass; + u32 return_code; +}; + +enum hp_return_value { + HPWMI_RET_WRONG_SIGNATURE = 0x02, + HPWMI_RET_UNKNOWN_COMMAND = 0x03, + HPWMI_RET_UNKNOWN_CMDTYPE = 0x04, + HPWMI_RET_INVALID_PARAMETERS = 0x05 +}; + +enum wmi_error_values { + SUCCESS = 0x00, + CMD_FAILED = 0x01, + INVALID_SIGN = 0x02, + INVALID_CMD_VALUE = 0x03, + INVALID_CMD_TYPE = 0x04, + INVALID_DATA_SIZE = 0x05, + INVALID_CMD_PARAM = 0x06, + ENCRYP_CMD_REQUIRED = 0x07, + NO_SECURE_SESSION = 0x08, + SECURE_SESSION_FOUND = 0x09, + SECURE_SESSION_FAILED = 0x0A, + AUTH_FAILED = 0x0B, + INVALID_BIOS_AUTH = 0x0E, + NONCE_DID_NOT_MATCH = 0x18, + GENERIC_ERROR = 0x1C, + BIOS_ADMIN_POLICY_NOT_MET = 0x28, + BIOS_ADMIN_NOT_SET = 0x38, + P21_NO_PROVISIONED = 0x1000, + P21_PROVISION_IN_PROGRESS = 0x1001, + P21_IN_USE = 0x1002, + HEP_NOT_ACTIVE = 0x1004, + HEP_ALREADY_SET = 0x1006, + HEP_CHECK_STATE = 0x1007 +}; + +enum spm_features { + HEP_ENABLED = 0x01, + PLATFORM_RECOVERY = 0x02, + ENHANCED_BIOS_AUTH_MODE = 0x04 +}; + +#define MAX_KEK_BLOB_SIZE 4160 +#define MAX_SK_BLOB_SIZE 516 + +enum spm_states_values { + NOT_PROVISIONED = 0x00, + PROVISIONED = 0x01, + PROVISIONING_IN_PROGRESS = 0x02 +}; + + + +/* + * struct bios_args buffer is dynamically allocated. New WMI command types + * were introduced that exceeds 128-byte data size. Changes to handle + * the data size allocation scheme were kept in hp_wmi_perform_qurey function. + */ +struct bios_args { + u32 signature; + u32 command; + u32 commandtype; + u32 datasize; + u8 data[]; +}; + +struct secureplatform_provisioning_data { + u8 state; + u8 version[2]; + u8 reserved1; + u32 features; + u32 nonce; + u8 reserved2[28]; + u8 sk_mod[MAX_KEY_MOD]; + u8 kek_mod[MAX_KEY_MOD]; +}; + +struct common_data { + u8 display_name[MAX_BUFF]; + u8 path[MAX_BUFF]; + u32 is_readonly; + u32 display_in_ui; + u32 requires_physical_presence; + u32 sequence; + u32 prerequisites_size; + u8 prerequisites[MAX_PREREQUISITES_SIZE][MAX_BUFF]; + u32 security_level; + u8 display_name_language_code[MAX_BUFF]; +}; + + +struct string_data { + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF]; + u8 new_value[MAX_BUFF]; + u32 min_length; + u32 max_length; + struct common_data common; +}; + +struct integer_data { + struct kobject *attr_name_kobj; + u32 current_value; + u32 new_value; + u32 lower_bound; + u32 upper_bound; + u32 scalar_increment; + struct common_data common; +}; + +struct enumeration_data { + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF]; + u8 new_value[MAX_BUFF]; + u32 possible_values_size; + u8 possible_values[MAX_VALUES_SIZE][MAX_BUFF]; + struct common_data common; +}; + +struct ordered_list_data { + struct kobject *attr_name_kobj; + u8 current_value[MAX_BUFF]; + u8 new_value[MAX_BUFF]; + u32 elements_size; + u8 elements[MAX_ELEMENTS_SIZE][MAX_BUFF]; + struct common_data common; +}; + +struct password_data { + 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]; + u32 is_enabled; + + // 'bios-admin' 'power-on' + u32 role; + + //'password' + u32 mechanism; + + struct common_data common; +}; + +struct secure_platform_data { + struct kobject *attr_name_kobj; + u8 attribute_name[MAX_BUFF]; + u8 display_name[MAX_BUFF]; + + u8 *endorsement_key; + u8 *signing_key; + u8 *auth_token; + + u32 is_enabled; + u32 mechanism; +}; + +struct bioscfg_priv { + struct wmi_device *password_attr_wdev; + struct wmi_device *bios_attr_wdev; + struct kset *authentication_dir_kset; + struct kset *main_dir_kset; + struct device *class_dev; + struct string_data *string_data; + u32 string_instances_count; + struct integer_data *integer_data; + u32 integer_instances_count; + struct enumeration_data *enumeration_data; + u32 enumeration_instances_count; + struct ordered_list_data *ordered_list_data; + u32 ordered_list_instances_count; + struct password_data *password_data; + u32 password_instances_count; + + struct kobject *sure_start_attr_kobj; + struct secure_platform_data spm_data; + + bool pending_reboot; + struct mutex mutex; +}; + +/* global structure used by multiple WMI interfaces */ +extern struct bioscfg_priv bioscfg_drv; + +enum hp_wmi_data_type { + HPWMI_STRING_TYPE = 0x00, + HPWMI_INTEGER_TYPE = 0x01, + HPWMI_ENUMERATION_TYPE = 0x02, + HPWMI_ORDERED_LIST_TYPE = 0x03, + HPWMI_PASSWORD_TYPE = 0x04, + HPWMI_SECURE_PLATFORM_TYPE = 0x05, + HPWMI_SURE_START_TYPE = 0x06 +}; + +enum hp_wmi_data_elements { + + /* Common elements */ + NAME = 0, + VALUE = 1, + PATH = 2, + IS_READONLY = 3, + DISPLAY_IN_UI = 4, + REQUIRES_PHYSICAL_PRESENCE = 5, + SEQUENCE = 6, + PREREQUISITES_SIZE = 7, + PREREQUISITES = 8, + SECURITY_LEVEL = 9, + + /* String elements */ + STR_MIN_LENGTH = 10, + STR_MAX_LENGTH = 11, + + /* Integer elements */ + INT_LOWER_BOUND = 10, + INT_UPPER_BOUND = 11, + INT_SCALAR_INCREMENT = 12, + + /* Enumeration elements */ + ENUM_CURRENT_VALUE = 10, + ENUM_SIZE = 11, + ENUM_POSSIBLE_VALUES = 12, + + /* Ordered list elements */ + ORD_LIST_SIZE = 10, + ORD_LIST_ELEMENTS = 11, + + /* Password elements */ + PSWD_MIN_LENGTH = 10, + PSWD_MAX_LENGTH = 11, + PSWD_SIZE = 12, + PSWD_ENCODINGS = 13, + PSWD_IS_SET = 14 +}; + + +enum hp_wmi_elements_count { + STRING_ELEM_CNT = 12, + INTEGER_ELEM_CNT = 13, + ENUM_ELEM_CNT = 13, + ORDERED_ELEM_CNT = 12, + PASSWORD_ELEM_CNT = 15 +}; + +#define GET_INSTANCE_ID(type) \ + static int get_##type##_instance_id(struct kobject *kobj) \ + { \ + int i; \ + \ + for (i = 0; i <= bioscfg_drv.type##_instances_count; i++) { \ + if (!(strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name))) \ + return i; \ + } \ + return -EIO; \ + } + +#define ATTRIBUTE_S_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ + char *buf) \ + { \ + int i = get_##type##_instance_id(kobj); \ + if (i >= 0) \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].name); \ + return -EIO; \ + } + +#define ATTRIBUTE_N_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ + char *buf) \ + { \ + int i = get_##type##_instance_id(kobj); \ + if (i >= 0) \ + return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].name); \ + return -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 *p = NULL; \ + char *attr_value = NULL; \ + int i; \ + int ret = -EIO; \ + \ + attr_value = kstrdup(buf, GFP_KERNEL); \ + if (!attr_value) \ + return -ENOMEM; \ + \ + p = memchr(attr_value, '\n', count); \ + if (p != NULL) \ + *p = '\0'; \ + \ + i = get_##type##_instance_id(kobj); \ + if (i >= 0) \ + ret = validate_##type##_input(i, attr_value); \ + if (!ret) \ + ret = hp_set_attribute(kobj->name, attr_value); \ + if (!ret) \ + update_##type##_value(i, attr_value); \ + \ + 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 *attr, char *buf) \ + { \ + return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data.name); \ + } + +#define ATTRIBUTE_SPM_S_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ + { \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data.name); \ + } + +#define ATTRIBUTE_VALUES_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + int i; \ + int len = 0; \ + int instance_id = get_##type##_instance_id(kobj); \ + \ + if (instance_id < 0) \ + return 0; \ + \ + for (i = 0; i < bioscfg_drv.type##_data[instance_id].name##_size; i++) { \ + if (i) \ + len += sysfs_emit_at(buf, len, "%s", ";"); \ + \ + len += sysfs_emit_at(buf, len, "%s", \ + bioscfg_drv.type##_data[instance_id].name[i]); \ + } \ + len += 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 *attr, \ + char *buf) \ + { \ + int i = get_##type##_instance_id(kobj); \ + if (i >= 0) \ + return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].common.name); \ + return -EIO; \ + } + +#define ATTRIBUTE_N_COMMON_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ + char *buf) \ + { \ + int i = get_##type##_instance_id(kobj); \ + if (i >= 0) \ + return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].common.name); \ + return -EIO; \ + } + +#define ATTRIBUTE_V_COMMON_PROPERTY_SHOW(name, type) \ + static ssize_t name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + int i; \ + int len = 0; \ + int instance_id = get_##type##_instance_id(kobj); \ + \ + if (instance_id < 0) \ + return 0; \ + \ + for (i = 0; i < bioscfg_drv.type##_data[instance_id].common.name##_size; i++) { \ + if (i) \ + len += sysfs_emit_at(buf, len, "%s", ";"); \ + \ + len += sysfs_emit_at(buf, len, "%s", \ + bioscfg_drv.type##_data[instance_id].common.name[i]); \ + } \ + len += sysfs_emit_at(buf, len, "\n"); \ + return len; \ + } + + +/* + * Prototypes + */ +union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string); +int get_instance_count(const char *guid_string); +void update_attribute_permissions(u32 isReadOnly, struct kobj_attribute *current_val); +void friendly_user_name_update(char *path, const char *attr_name, + char *attr_display, int attr_size); +int bioscfg_wmi_error_and_message(int error_code); + +/* String attributes */ +int populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); + +int populate_string_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id); + +//enum hp_wmi_data_type type); +int alloc_string_data(void); +void exit_string_attributes(void); +int populate_string_package_data(union acpi_object *str_obj, + int instance_id, + struct kobject *attr_name_kobj); +int populate_string_elements_from_package(union acpi_object *str_obj, + int str_obj_count, + int instance_id); + +/* Integer attributes */ +int populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id); +int alloc_integer_data(void); +void exit_integer_attributes(void); +int populate_integer_package_data(union acpi_object *integer_obj, + int instance_id, + struct kobject *attr_name_kobj); +int populate_integer_elements_from_package(union acpi_object *integer_obj, + int integer_obj_count, + int instance_id); + +/* Enumeration attributes */ +int populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int populate_enumeration_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id); +int alloc_enumeration_data(void); +void exit_enumeration_attributes(void); +int populate_enumeration_package_data(union acpi_object *enum_obj, + int instance_id, + struct kobject *attr_name_kobj); +int populate_enumeration_elements_from_package(union acpi_object *enum_obj, + int enum_obj_count, + int instance_id); + +/* Ordered list */ +int populate_ordered_list_buffer_data(u8 *buffer_ptr, + u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int populate_ordered_list_elements_from_buffer(u8 *buffer_ptr, + u32 *buffer_size, + int instance_id); +int alloc_ordered_list_data(void); +void exit_ordered_list_attributes(void); +int populate_ordered_list_package_data(union acpi_object *order_obj, + int instance_id, + struct kobject *attr_name_kobj); +int populate_ordered_list_elements_from_package(union acpi_object *order_obj, + int order_obj_count, + int instance_id); + +/* Password authentication attributes */ +int populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj); +int populate_password_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id); +int populate_password_package_data(union acpi_object *password_obj, + int instance_id, + struct kobject *attr_name_kobj); +int populate_password_elements_from_package(union acpi_object *password_obj, + int password_obj_count, + int instance_id); +int alloc_password_data(void); +int alloc_secure_platform_data(void); +void exit_password_attributes(void); +void exit_secure_platform_attributes(void); +int populate_secure_platform_data(struct kobject *attr_name_kobj); +int password_is_set(const char *auth); +int check_spm_is_enabled(void); +int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size); +int hp_wmi_perform_query(int query, enum hp_wmi_command command, + void *buffer, int insize, int outsize); +int validate_password_input(int instance_id, const char *buf); + +/* Sure Start attributes */ +void exit_sure_start_attributes(void); +int populate_sure_start_data(struct kobject *attr_name_kobj); + +int set_bios_defaults(u8 defType); +int get_password_instance_for_type(const char *name); +int clear_all_credentials(void); +int clear_passwords(const int instance); +void exit_bios_attr_set_interface(void); +int init_bios_attr_set_interface(void); +size_t bioscfg_calculate_string_buffer(const char *str); +size_t calculate_security_buffer(const char *authentication); +void populate_security_buffer(u16 *buffer, const char *authentication); +int set_new_password(const char *password_type, const char *new_password); +int init_bios_attr_pass_interface(void); +void exit_bios_attr_pass_interface(void); +void *ascii_to_utf16_unicode(u16 *p, const u8 *str); +int get_integer_from_buffer(int **buffer, u32 *buffer_size, int *integer); +int get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_size); +int convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *len); +int encode_outsize_for_pvsz(int outsize); +int hp_set_attribute(const char *a_name, const char *a_value); + +/* SPM Attributes */ +ssize_t update_spm_state(void); +ssize_t statusbin(struct kobject *kobj, struct kobj_attribute *attr, char *buf); +ssize_t statusbin_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); +ssize_t status_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); + +#endif From patchwork Thu Apr 20 16:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219007 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 F33DCC77B7F for ; Thu, 20 Apr 2023 16:55:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjDTQza (ORCPT ); Thu, 20 Apr 2023 12:55:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230257AbjDTQzL (ORCPT ); Thu, 20 Apr 2023 12:55:11 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DEA02D78; Thu, 20 Apr 2023 09:55:08 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-38c35975545so832351b6e.1; Thu, 20 Apr 2023 09:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009707; x=1684601707; 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=W8MDowcdCyHRBFtM9QJqVy9DUXrPddSgYQvuHIZ0L1A=; b=izji5BqFI8xkY8RxRQvBsHds8dnkgnxCouJ4HPlI1uSY0AUKELl9BfoTCZbW/2M2yN yFbIOWRhBSrXYvKxUj39LRft2yQxG3TgX95wi4DjP5h8wqvH+iMDhV9i1lExZr7d2jEf cgCpAuI96Vgh7aCNdgohAaXuOuAcoSgYiaqnSBezUgvJWJx82oBE0PMN3F8ZqKX5ZYiK K2Bp91iRciww7J0iBY8somz9ByubaT+4bofNs8D/+wRs2cX+6tzzfolC/Rogfpc+SPXH HBbm6iLpy6JB3jAwinXSgHpfWvrse85JPU5lHCIbz3fILXf+OdWrkfDpCjMwXkrPjBjD JBtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009707; x=1684601707; 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=W8MDowcdCyHRBFtM9QJqVy9DUXrPddSgYQvuHIZ0L1A=; b=ihr2isGXqi94Rz/H1LMf6vVj+DIY6Dai64gCYmxbcKIvVMiMmwFtgGRiU/oaSULQmX nINUjBj7ekneksTp3cUaqrdBM+gMjwuryFyZdXcziD2jAf6VELjW4pXPGnILK5+IoOVH BmHHflRn3HA3xKywlBTdHhVAA6HGfSoonNKphtzSmvVM3NtkMOwKmM2OCiYZTJydDjEH JdLxrxD9b7QgIsurAJzSQ71u3N2jEyH4yH5F35VB3ZTKS1cV/lw29siCCGIxPapNH9p+ vZCih4gej4H5+aJrnB70E7qBn2IeUAAZQb9L+LAC242NH9hPCJyChe6QfLeqLL0pRjCX /dyg== X-Gm-Message-State: AAQBX9emClbUIeR0KnVSIhzQYC5LjTkPfiML45QLw/lTtKLN5gqaZrlw onGTvKfDL3f8PFv03tsss0TvcdafVhE= X-Google-Smtp-Source: AKy350bir62Gkkf02Zkm2wdFlc3BUeHuzRK2ZDOZOFx7r8b9a6Q+Jp/Z8IVbiYOvyulyeJ/2XomBEQ== X-Received: by 2002:aca:a856:0:b0:38e:6ba9:6491 with SMTP id r83-20020acaa856000000b0038e6ba96491mr1303371oie.50.1682009707248; Thu, 20 Apr 2023 09:55:07 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:06 -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 Subject: [PATCH v11 09/14] HP BIOSCFG driver - enum-attributes Date: Thu, 20 Apr 2023 11:54:49 -0500 Message-Id: <20230420165454.9517-10-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 543 ++++++++++++++++++ 1 file changed, 543 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..20defa92da6f --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c @@ -0,0 +1,543 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to enumeration type attributes under + * BIOS Enumeration GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 HP Development Company, L.P. + */ + +#include "bioscfg.h" + +GET_INSTANCE_ID(enumeration); + +static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + int instance_id = get_enumeration_instance_id(kobj); + + 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 ret = 0; + int found = 0; + int i; + int possible_values; + + /* Is it a read only attribute */ + if (bioscfg_drv.enumeration_data[instance_id].common.is_readonly) + return -EIO; + + possible_values = bioscfg_drv.enumeration_data[instance_id].possible_values_size; + for (i = 0; i < possible_values && !found; i++) + if (!strcasecmp(bioscfg_drv.enumeration_data[instance_id].possible_values[i], buf)) + found = 1; + + if (!found) { + ret = -EINVAL; + goto exit_enum_input; + } + + /* + * set pending reboot flag depending on + * "RequiresPhysicalPresence" value + */ + if (bioscfg_drv.enumeration_data[instance_id].common.requires_physical_presence) + bioscfg_drv.pending_reboot = true; + +exit_enum_input: + return ret; +} + +static void update_enumeration_value(int instance_id, char *attr_value) +{ + strscpy(bioscfg_drv.enumeration_data[instance_id].current_value, + attr_value, + sizeof(bioscfg_drv.enumeration_data[instance_id].current_value)); +} + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name_language_code, enumeration); +static struct kobj_attribute enumeration_display_langcode = + __ATTR_RO(display_name_language_code); + +ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, enumeration); +static struct kobj_attribute enumeration_display_name = + __ATTR_RO(display_name); + +ATTRIBUTE_PROPERTY_STORE(current_value, enumeration); +static struct kobj_attribute enumeration_current_val = + __ATTR_RW_MODE(current_value, 0644); + +ATTRIBUTE_N_COMMON_PROPERTY_SHOW(prerequisites_size, enumeration); +static struct kobj_attribute enumeration_prerequisites_size_val = + __ATTR_RO(prerequisites_size); + +ATTRIBUTE_V_COMMON_PROPERTY_SHOW(prerequisites, enumeration); +static struct kobj_attribute enumeration_prerequisites_val = + __ATTR_RO(prerequisites); + +ATTRIBUTE_N_PROPERTY_SHOW(possible_values_size, enumeration); +static struct kobj_attribute enumeration_possible_values_size_val = + __ATTR_RO(possible_values_size); + +ATTRIBUTE_VALUES_PROPERTY_SHOW(possible_values, enumeration); +static struct kobj_attribute enumeration_poss_val = + __ATTR_RO(possible_values); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "enumeration\n"); +} +static struct kobj_attribute enumeration_type = + __ATTR_RO(type); + +static struct attribute *enumeration_attrs[] = { + &enumeration_display_langcode.attr, + &enumeration_display_name.attr, + &enumeration_current_val.attr, + &enumeration_prerequisites_size_val.attr, + &enumeration_prerequisites_val.attr, + &enumeration_possible_values_size_val.attr, + &enumeration_poss_val.attr, + &enumeration_type.attr, + NULL +}; + +static const struct attribute_group enumeration_attr_group = { + .attrs = enumeration_attrs, +}; + +int alloc_enumeration_data(void) +{ + int ret = 0; + + bioscfg_drv.enumeration_instances_count = + get_instance_count(HP_WMI_BIOS_ENUMERATION_GUID); + + bioscfg_drv.enumeration_data = kcalloc(bioscfg_drv.enumeration_instances_count, + sizeof(struct enumeration_data), GFP_KERNEL); + if (!bioscfg_drv.enumeration_data) { + bioscfg_drv.enumeration_instances_count = 0; + ret = -ENOMEM; + } + return ret; +} + +/* Expected Values types associated with each element */ +static const acpi_object_type expected_enum_types[] = { + [NAME] = ACPI_TYPE_STRING, + [VALUE] = ACPI_TYPE_STRING, + [PATH] = ACPI_TYPE_STRING, + [IS_READONLY] = ACPI_TYPE_INTEGER, + [DISPLAY_IN_UI] = ACPI_TYPE_INTEGER, + [REQUIRES_PHYSICAL_PRESENCE] = ACPI_TYPE_INTEGER, + [SEQUENCE] = ACPI_TYPE_INTEGER, + [PREREQUISITES_SIZE] = ACPI_TYPE_INTEGER, + [PREREQUISITES] = ACPI_TYPE_STRING, + [SECURITY_LEVEL] = ACPI_TYPE_INTEGER, + [ENUM_CURRENT_VALUE] = ACPI_TYPE_STRING, + [ENUM_SIZE] = ACPI_TYPE_INTEGER, + [ENUM_POSSIBLE_VALUES] = ACPI_TYPE_STRING +}; + +/* + * populate_enumeration_package_data() - + * Populate all properties of an instance under enumeration attribute + * + * @enum_obj: ACPI object with enumeration data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + */ +int populate_enumeration_package_data(union acpi_object *enum_obj, + int instance_id, + struct kobject *attr_name_kobj) +{ + bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj; + + populate_enumeration_elements_from_package(enum_obj, + enum_obj->package.count, + instance_id); + update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].common.is_readonly, + &enumeration_current_val); + /* + * Several attributes have names such "MONDAY". Friendly + * user nane is generated to make the name more descriptive + */ + friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.enumeration_data[instance_id].common.display_name, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.display_name)); + return sysfs_create_group(attr_name_kobj, &enumeration_attr_group); +} + +int populate_enumeration_elements_from_package(union acpi_object *enum_obj, + int enum_obj_count, + int instance_id) +{ + char *str_value = NULL; + int value_len; + u32 size = 0; + u32 int_value; + int elem = 0; + int reqs; + int pos_values; + int ret; + int eloc; + + strscpy(bioscfg_drv.enumeration_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.display_name_language_code)); + + for (elem = 1, eloc = 1; elem < enum_obj_count; elem++, eloc++) { + + /* ONLY look at the first ENUM_ELEM_CNT elements */ + if (eloc == ENUM_ELEM_CNT) + goto exit_enumeration_package; + + switch (enum_obj[elem].type) { + case ACPI_TYPE_STRING: + + if (PREREQUISITES != elem && ENUM_POSSIBLE_VALUES != elem) { + ret = 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 = (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] != 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(bioscfg_drv.enumeration_data[instance_id].common.path, str_value, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.path)); + break; + case IS_READONLY: + bioscfg_drv.enumeration_data[instance_id].common.is_readonly = int_value; + break; + case DISPLAY_IN_UI: + bioscfg_drv.enumeration_data[instance_id].common.display_in_ui = int_value; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.enumeration_data[instance_id].common.requires_physical_presence = int_value; + break; + case SEQUENCE: + bioscfg_drv.enumeration_data[instance_id].common.sequence = int_value; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.enumeration_data[instance_id].common.prerequisites_size = int_value; + if (int_value > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites 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. PREREQUISITES + * object is omitted by BIOS when the size is + * zero. + */ + if (int_value == 0) + eloc++; + break; + + case PREREQUISITES: + + size = bioscfg_drv.enumeration_data[instance_id].common.prerequisites_size; + + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + if (elem >= enum_obj_count) { + pr_err("Error enum-objects package is too small\n"); + return -EINVAL; + } + + ret = convert_hexstr_to_str(enum_obj[elem + reqs].string.pointer, + enum_obj[elem + reqs].string.length, + &str_value, &value_len); + + if (ret) + return -EINVAL; + + strlcpy(bioscfg_drv.enumeration_data[instance_id].common.prerequisites[reqs], + str_value, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.prerequisites[reqs])); + + kfree(str_value); + } + break; + + case SECURITY_LEVEL: + bioscfg_drv.enumeration_data[instance_id].common.security_level = int_value; + break; + + case ENUM_CURRENT_VALUE: + strscpy(bioscfg_drv.enumeration_data[instance_id].current_value, + str_value, sizeof(bioscfg_drv.enumeration_data[instance_id].current_value)); + break; + case ENUM_SIZE: + bioscfg_drv.enumeration_data[instance_id].possible_values_size = 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 == 0) + eloc++; + break; + + case ENUM_POSSIBLE_VALUES: + size = bioscfg_drv.enumeration_data[instance_id].possible_values_size; + + for (pos_values = 0; pos_values < size && pos_values < MAX_VALUES_SIZE; pos_values++) { + if (elem >= enum_obj_count) { + pr_err("Error enum-objects package is too small\n"); + return -EINVAL; + } + + ret = convert_hexstr_to_str(enum_obj[elem + pos_values].string.pointer, + 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) + strlcpy(bioscfg_drv.enumeration_data[instance_id].possible_values[pos_values], + str_value, + sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values[pos_values])); + + kfree(str_value); + } + 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; +} + +/* + * populate_enumeration_buffer_data() - + * Populate all properties of an instance under enumeration attribute + * + * @buffer_ptr: Buffer pointer + * @buffer_size: Buffer size + * @enum_obj: ACPI object with enumeration data + * @instance_id: The instance to enumerate + * @attr_name_kobj: The parent kernel object + * @enumeration_property_count: Total properties count under enumeration type + */ +int populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size, + int instance_id, + struct kobject *attr_name_kobj) +{ + + bioscfg_drv.enumeration_data[instance_id].attr_name_kobj = attr_name_kobj; + + /* Populate enumeration elements */ + populate_enumeration_elements_from_buffer(buffer_ptr, buffer_size, + instance_id); + + update_attribute_permissions(bioscfg_drv.enumeration_data[instance_id].common.is_readonly, + &enumeration_current_val); + /* + * Several attributes have names such "MONDAY". A Friendlier + * user nane is generated to make the name more descriptive + */ + friendly_user_name_update(bioscfg_drv.enumeration_data[instance_id].common.path, + attr_name_kobj->name, + bioscfg_drv.enumeration_data[instance_id].common.display_name, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.display_name)); + + return sysfs_create_group(attr_name_kobj, &enumeration_attr_group); +} + +int populate_enumeration_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size, + int instance_id) +{ + char *dst = NULL; + int elem; + int reqs; + int integer; + int size = 0; + int values; + int ret; + int dst_size = *buffer_size / sizeof(u16); + + dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL); + if (!dst) + return -ENOMEM; + + elem = 0; + + strscpy(bioscfg_drv.enumeration_data[instance_id].common.display_name_language_code, + LANG_CODE_STR, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.display_name_language_code)); + + for (elem = 1; elem < 3; elem++) { + + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + /* Ignore. Zero length string values */ + if (ret < 0) + continue; + + switch (elem) { + case VALUE: + /* Skip 'Value' since 'CurrentValue' is reported. */ + break; + case PATH: + strscpy(bioscfg_drv.enumeration_data[instance_id].common.path, + dst, sizeof(bioscfg_drv.enumeration_data[instance_id].common.path)); + break; + default: + pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem); + break; + } + } + + for (elem = 3; elem < ENUM_ELEM_CNT; elem++) { + if (PREREQUISITES != elem && ENUM_CURRENT_VALUE != elem && ENUM_POSSIBLE_VALUES != elem) { + ret = get_integer_from_buffer((int **)&buffer_ptr, buffer_size, (int *)&integer); + if (ret < 0) + continue; + } + + switch (elem) { + case IS_READONLY: + bioscfg_drv.enumeration_data[instance_id].common.is_readonly = integer; + break; + case DISPLAY_IN_UI: + bioscfg_drv.enumeration_data[instance_id].common.display_in_ui = integer; + break; + case REQUIRES_PHYSICAL_PRESENCE: + bioscfg_drv.enumeration_data[instance_id].common.requires_physical_presence = integer; + break; + case SEQUENCE: + bioscfg_drv.enumeration_data[instance_id].common.sequence = integer; + break; + case PREREQUISITES_SIZE: + bioscfg_drv.enumeration_data[instance_id].common.prerequisites_size = integer; + if (integer > MAX_PREREQUISITES_SIZE) + pr_warn("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // PREREQUISITES: + elem++; + + size = bioscfg_drv.enumeration_data[instance_id].common.prerequisites_size; + for (reqs = 0; reqs < size && reqs < MAX_PREREQUISITES_SIZE; reqs++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + /* Ignore. expect zero length strings at the end of prerequisite values */ + if (ret < 0) + continue; + + strscpy(bioscfg_drv.enumeration_data[instance_id].common.prerequisites[reqs], + dst, + sizeof(bioscfg_drv.enumeration_data[instance_id].common.prerequisites[reqs])); + } + break; + case SECURITY_LEVEL: + bioscfg_drv.enumeration_data[instance_id].common.security_level = integer; + break; + case ENUM_CURRENT_VALUE: + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + if (ret < 0) + continue; + + strscpy(bioscfg_drv.enumeration_data[instance_id].current_value, + dst, + sizeof(bioscfg_drv.enumeration_data[instance_id].current_value)); + break; + case ENUM_SIZE: + bioscfg_drv.enumeration_data[instance_id].possible_values_size = integer; + if (integer > MAX_VALUES_SIZE) + pr_warn("Possible size value exceeded the maximum number of elements supported or data may be malformed\n"); + + // ENUM_POSSIBLE_VALUES: + elem++; + + size = bioscfg_drv.enumeration_data[instance_id].possible_values_size; + for (values = 0; values < size && values < MAX_VALUES_SIZE; values++) { + ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size); + /* Ignore expect zero size strings at the end of all possible values */ + if (ret < 0) + continue; + + strscpy(bioscfg_drv.enumeration_data[instance_id].possible_values[values], + dst, + sizeof(bioscfg_drv.enumeration_data[instance_id].possible_values[values])); + } + break; + default: + pr_warn("Invalid element: %d found in Enumeration attribute or data may be malformed\n", elem); + break; + } + } + + kfree(dst); + + return 0; +} + +/** + * exit_enumeration_attributes() - Clear all attribute data + * + * Clears all data allocated for this group of attributes + */ +void exit_enumeration_attributes(void) +{ + int instance_id; + + for (instance_id = 0; instance_id < bioscfg_drv.enumeration_instances_count; instance_id++) { + struct kobject *attr_name_kobj = bioscfg_drv.enumeration_data[instance_id].attr_name_kobj; + + if (attr_name_kobj) + sysfs_remove_group(attr_name_kobj, &enumeration_attr_group); + } + bioscfg_drv.enumeration_instances_count = 0; + + kfree(bioscfg_drv.enumeration_data); + bioscfg_drv.enumeration_data = NULL; +} From patchwork Thu Apr 20 16:54:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219009 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 805DBC7EE20 for ; Thu, 20 Apr 2023 16:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbjDTQze (ORCPT ); Thu, 20 Apr 2023 12:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjDTQz2 (ORCPT ); Thu, 20 Apr 2023 12:55:28 -0400 Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2284691; Thu, 20 Apr 2023 09:55:09 -0700 (PDT) Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-546ec98b2e2so703131eaf.2; Thu, 20 Apr 2023 09:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009708; x=1684601708; 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=eTgLrtH5EQklN+ftHi/JTGVVI8xgKYuNkrSNqoJEWrE=; b=RQZ3OgX5w+xtVLaqAVlPgLOaWpIRgRduFTrKGAr4II/N9L1GuqUdpabi2r+NnSjVAh FdZ/rNaO5lUwTzzrrMwmfrmgpUeDUE7sSI1+ZR4VHxdkKrhFLe7j6sM1I6GRszySvYnt RqrKCh5uyofC+L9XrAEt9ziafbHvCNW87lmOBkvksZ+RgbjZynUpfPeGhr+SnaYFTNWl qxeeTAQIuw6LW3qvDjn8q/d6FJmoJole7oC9z1sAcMlWOqh+MGSK5OuwQDYc6QYD4uRJ 8x7b84yVj8+SXDOev3c384GxlEk13qa1tiHktogfyp+dGwyyzod5qBHI4wx3UxXBm4O5 AaFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009708; x=1684601708; 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=eTgLrtH5EQklN+ftHi/JTGVVI8xgKYuNkrSNqoJEWrE=; b=FCEBq134ldYJ8FyvBDc9gQNWfX4UmbXEnL18zAPGupxMVQMEhd/AANdq9NaExT4pIr 1JOuIPbJ1bTqE38LWVppDW/2gziqy84WMyp1Kz/DNNvAAc2ThEzmAdfOmjYu5z2Ow5zC zh2hmoUqn8T4ICU0B2JqrZPJrBmyliowb/80r+FG42xwnihqSpX8pp/kMoiE+dg/FG33 /rMR28cx3Mvnc3Ht+D/PYbyDDC6iYqACrD99KqTHym2wnVDzhzYOa/ETV9gsAOTvQ3Wa +hXzpKm2b9s3FFSBa98Hi4w9urv9Att13biP9+SKwdK7yJR2yWJMpnuSGeaaqYSfb/uF 67HA== X-Gm-Message-State: AAQBX9fExrdqJZR2gO0o2pBO+shLcsV/wESNVjKaW8IZLYc2VY4d4PiZ K4tg5NCpg57j6Meyv/YRaczXJVLoaWo= X-Google-Smtp-Source: AKy350YADkzlgw6IS/BEZ+HO2h01NrEkDGHNPEAc+Go6YEKx2zNXjZSTqqV0EthqAQrvqw8dxgKAkw== X-Received: by 2002:a05:6808:9a4:b0:38b:ceab:7de7 with SMTP id e4-20020a05680809a400b0038bceab7de7mr1215322oig.32.1682009708612; Thu, 20 Apr 2023 09:55:08 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:08 -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 Subject: [PATCH v11 10/14] HP BIOSCFG driver - passwdattr-interface Date: Thu, 20 Apr 2023 11:54:50 -0500 Message-Id: <20230420165454.9517-11-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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/passwdattr-interface.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c diff --git a/drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c b/drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c new file mode 100644 index 000000000000..02fc766eb3cf --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/passwdattr-interface.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Functions corresponding to SET password methods under + * HP_WMI_SET_BIOS_SETTING_GUID for use with hp-bioscfg driver. + * + * Copyright (c) 2022 Hewlett-Packard Inc. + */ + +#include +#include "bioscfg.h" + +static int bios_attr_pass_interface_probe(struct wmi_device *wdev, + const void *context) +{ + mutex_lock(&bioscfg_drv.mutex); + bioscfg_drv.password_attr_wdev = wdev; + mutex_unlock(&bioscfg_drv.mutex); + return 0; +} + +static void bios_attr_pass_interface_remove(struct wmi_device *wdev) +{ + mutex_lock(&bioscfg_drv.mutex); + bioscfg_drv.password_attr_wdev = NULL; + mutex_unlock(&bioscfg_drv.mutex); +} + +static const struct wmi_device_id bios_attr_pass_interface_id_table[] = { + { .guid_string = HP_WMI_SET_BIOS_SETTING_GUID }, + { }, +}; +static struct wmi_driver bios_attr_pass_interface_driver = { + .driver = { + .name = DRIVER_NAME"-password" + }, + .probe = bios_attr_pass_interface_probe, + .remove = bios_attr_pass_interface_remove, + .id_table = bios_attr_pass_interface_id_table, +}; + +int init_bios_attr_pass_interface(void) +{ + return wmi_driver_register(&bios_attr_pass_interface_driver); +} + +void exit_bios_attr_pass_interface(void) +{ + wmi_driver_unregister(&bios_attr_pass_interface_driver); +} + +MODULE_DEVICE_TABLE(wmi, bios_attr_pass_interface_id_table); From patchwork Thu Apr 20 16:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219010 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 4C9C4C77B72 for ; Thu, 20 Apr 2023 16:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbjDTQzw (ORCPT ); Thu, 20 Apr 2023 12:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjDTQz3 (ORCPT ); Thu, 20 Apr 2023 12:55:29 -0400 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA31346BE; Thu, 20 Apr 2023 09:55:10 -0700 (PDT) Received: by mail-oo1-xc33.google.com with SMTP id bv13-20020a0568201b0d00b0053e3ccf739cso821130oob.10; Thu, 20 Apr 2023 09:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009710; x=1684601710; 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=Qc+D/j5g2E3uImTbtBWCoYCaBXxxKJHNTHXWvK8s1tk=; b=Oe3FGNHFGyxiplrhmBUdLDxLMMewPds2Du7vgqlGOzyiniP3i6dRU/NEMulyYJEm7g jxGcEbqT+WGaWOU5Zb5tH91phoGcdot9hY9m+fMLCqZTU7NscYmlNuXYOFJh3z7QvLLj SMtB2YjdiHrxWIhV1Fggz/r4tmhcUyWA/BUFonkWBw+2dEbAVjuyT0kI/csODoogs/cp JegNkVJwLP1SU3qVapngCUOmH7Kve8GGZxwr8r9qzaUpJf9A9GtEByWxU3Bt5vvrfR9w P4YftNrB7pA7afxtwHK1pJkQtj+VWXjn8wV3jV1GsdcUyan3xpoAe8eLus74RpLKmK2y o9pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009710; x=1684601710; 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=Qc+D/j5g2E3uImTbtBWCoYCaBXxxKJHNTHXWvK8s1tk=; b=Gz4Scgl1mB+gAZ066usNf0oR6a9OUGtV/3OgAVjwf14NyHlAEN7asqdWpDyl+3o45D rh4YI9EUNpypQ31qtLCKH0LHHDYqydaISGIO1IoCLUvJ9nvIxC0NaGmE4xqktZFnz4dw lUkuKCOPQ8lDzjZoMDHbCjRyOpIY43IGB82nSj0BeLmbDU06shVqL3PBgvi7IE3QXTaA sO3QDw0pvzCNcNRN1HdruizGCRRV/9Td9mo3y587OTqIOSsT0aPdQ9KgirnPVEoNgXq3 8dRWrdzagZwkGP7lKKJZhgmZf5f0G9RzjfCKvHK0umwCGTOW31wFQBZ5bfektOjULtGq +1AQ== X-Gm-Message-State: AAQBX9cbi6vrYrt/Mnr/+ql63cWVg7JTuet4xnpQgbTbZIFjSd/i+VbX j+VXWuCzzhmXf7mkF6aVlm/5LO3I2aM= X-Google-Smtp-Source: AKy350a9BfDEV/PmBeBOzVeQ0O8j+eQbofYuzCpS05GnIT4lHgnNV/8gxGv4URRNJtf7rUvmsOVGtA== X-Received: by 2002:a4a:ad04:0:b0:544:dc2c:9f78 with SMTP id r4-20020a4aad04000000b00544dc2c9f78mr1102111oon.6.1682009709877; Thu, 20 Apr 2023 09:55:09 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:09 -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 Subject: [PATCH v11 11/14] HP BIOSCFG driver - spmobj-attributes Date: Thu, 20 Apr 2023 11:54:51 -0500 Message-Id: <20230420165454.9517-12-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 405 ++++++++++++++++++ 1 file changed, 405 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/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c new file mode 100644 index 000000000000..78228f44c39b --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c @@ -0,0 +1,405 @@ +// 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[] = { + "not provisioned", + "provisioned", + "provisioning in progress" +}; + +static const char * const spm_mechanism_types[] = { + "not provision", + "signing-key", + "endorsement-key" +}; + + +int check_spm_is_enabled(void) +{ + /* do we need to check the admin password is also configured */ + return bioscfg_drv.spm_data.is_enabled; +} + +/* + * calculate_security_buffer() - determines size of security buffer + * for authentication scheme + * + * @authentication: the authentication content + * + * Currently only supported type is Admin password + */ +size_t calculate_security_buffer(const char *authentication) +{ + int size; + + if (authentication != NULL && strlen(authentication) > 0) { + + size = (sizeof(u16) + (strlen(authentication) * sizeof(u16))); + if (strncmp(authentication, BEAM_PREFIX, strlen(BEAM_PREFIX)) != 0) + size += (strlen(UTF_PREFIX) * sizeof(u16)); + + return size; + } + + size = sizeof(u16) * 2; + return size; +} + +/* + * populate_security_buffer() - builds a security buffer for + * authentication scheme + * + * @buffer: the buffer to populate + * @authentication: the authentication content + * + * Currently only supported type is PLAIN TEXT + */ +void populate_security_buffer(u16 *buffer, const char *authentication) +{ + u16 *auth = buffer; + char *strprefix = NULL; + + if (strncmp(authentication, BEAM_PREFIX, strlen(BEAM_PREFIX)) == 0) { + /* + * BEAM_PREFIX is append to buffer when a signature + * is provided and Sure Admin is enabled in BIOS + */ + // BEAM_PREFIX found, convert part to unicode + auth = ascii_to_utf16_unicode(auth, authentication); + } else { + /* + * UTF-16 prefix is append to the * buffer when a BIOS + * admin password is configured in BIOS + */ + + // append UTF_PREFIX to part and then convert it to unicode + strprefix = kasprintf(GFP_KERNEL, "%s%s", UTF_PREFIX, + authentication); + if (!strprefix) + goto out_buffer; + + auth = ascii_to_utf16_unicode(auth, strprefix); + } +out_buffer: + + kfree(strprefix); +} + +ssize_t update_spm_state(void) +{ + int ret; + struct secureplatform_provisioning_data *data = NULL; + + data = kmalloc(sizeof(struct secureplatform_provisioning_data), + GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto state_exit; + } + + ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE, + HPWMI_SECUREPLATFORM, data, 0, + sizeof(*data)); + if (ret < 0) + goto state_exit; + + bioscfg_drv.spm_data.mechanism = data->state; + if (bioscfg_drv.spm_data.mechanism) + bioscfg_drv.spm_data.is_enabled = 1; + +state_exit: + kfree(data); + + return ret; +} + +ssize_t statusbin(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_GET_STATE, + HPWMI_SECUREPLATFORM, buf, 0, + sizeof(struct secureplatform_provisioning_data)); + + return ret ? -ENODEV : sizeof(struct secureplatform_provisioning_data); +} + +/* + * status_show - Reads SPM status + */ +ssize_t status_show(struct kobject *kobj, struct kobj_attribute + *attr, char *buf) +{ + int ret, i; + struct secureplatform_provisioning_data *data = NULL; + + data = kmalloc(sizeof(struct secureplatform_provisioning_data), + GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto status_exit; + } + + ret = statusbin(kobj, attr, (char *)data); + if (ret < 0) + goto status_exit; + + sysfs_emit(buf, "%s{\n", buf); + sysfs_emit(buf, "%s\t\"State\": \"%s\",\n", buf, + spm_state_types[data->state]); + sysfs_emit(buf, "%s\t\"Version\": \"%d.%d\",\n", buf, data->version[0], + data->version[1]); + + /* + * state == 0 means secure platform management + * feature is not configured in BIOS. + */ + if (data->state == 0) + goto status_exit; + + sysfs_emit(buf, "%s\t\"Nonce\": %d,\n", buf, data->nonce); + sysfs_emit(buf, "%s\t\"FeaturesInUse\": %d,\n", buf, data->features); + sysfs_emit(buf, "%s\t\"EndorsementKeyMod\": \"", buf); + + for (i = 255; i >= 0; i--) + sysfs_emit(buf, "%s %u", buf, data->kek_mod[i]); + + sysfs_emit(buf, "%s \",\n", buf); + sysfs_emit(buf, "%s\t\"SigningKeyMod\": \"", buf); + + for (i = 255; i >= 0; i--) + sysfs_emit(buf, "%s %u", buf, data->sk_mod[i]); + + /* Return buf contents */ + + sysfs_emit(buf, "%s \"\n", buf); + sysfs_emit(buf, "%s}\n", buf); + +status_exit: + kfree(data); + + return strnlen(buf, PAGE_SIZE); +} + +static struct kobj_attribute password_spm_status = __ATTR_RO(status); + +ATTRIBUTE_SPM_N_PROPERTY_SHOW(is_enabled, spm); +static struct kobj_attribute password_spm_is_key_enabled = __ATTR_RO(is_enabled); + + +static ssize_t key_mechanism_show(struct kobject *kobj, struct kobj_attribute *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 = __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 = count; + if (buf[length-1] == '\n') + length--; + + /* allocate space and copy current signing key */ + bioscfg_drv.spm_data.signing_key = kmalloc(length, GFP_KERNEL); + if (!bioscfg_drv.spm_data.signing_key) { + ret = -ENOMEM; + goto exit_sk; + } + + memcpy(bioscfg_drv.spm_data.signing_key, buf, length); + bioscfg_drv.spm_data.signing_key[length] = '\0'; + + /* submit signing key payload */ + ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_SK, + HPWMI_SECUREPLATFORM, + (void *)bioscfg_drv.spm_data.signing_key, + length, 0); + + if (!ret) { + bioscfg_drv.spm_data.mechanism = SIGNING_KEY; + bioscfg_drv.pending_reboot = true; + } + +exit_sk: + kfree(bioscfg_drv.spm_data.signing_key); + bioscfg_drv.spm_data.signing_key = NULL; + + return ret ? ret : count; +} + +static struct kobj_attribute password_spm_signing_key = __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 = count; + if (buf[length-1] == '\n') + length--; + + /* allocate space and copy current signing key */ + bioscfg_drv.spm_data.endorsement_key = kmalloc(length, GFP_KERNEL); + if (!bioscfg_drv.spm_data.endorsement_key) { + ret = -ENOMEM; + goto exit_kek; + } + + memcpy(bioscfg_drv.spm_data.endorsement_key, buf, length); + bioscfg_drv.spm_data.endorsement_key[length] = '\0'; + + ret = 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 = ENDORSEMENT_KEY; + bioscfg_drv.pending_reboot = true; + } + +exit_kek: + kfree(bioscfg_drv.spm_data.endorsement_key); + bioscfg_drv.spm_data.endorsement_key = NULL; + + return ret ? ret : count; +} +static struct kobj_attribute password_spm_endorsement_key = __ATTR_WO(kek); + +static 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); +} + +static struct kobj_attribute password_spm_display_langcode = + __ATTR_RO(display_name_language_code); + + +static ssize_t display_name_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%s\n", SPM_STR_DESC); +} +static struct kobj_attribute password_spm_display_name = __ATTR_RO(display_name); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "secure-platform-management\n"); +} +static struct kobj_attribute password_spm_type = __ATTR_RO(type); + +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 = __ATTR_RO(role); + +static ssize_t auth_token_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int ret = 0; + int length; + + length = count; + if (buf[length-1] == '\n') + length--; + + /* allocate space and copy current auth token */ + bioscfg_drv.spm_data.auth_token = kmalloc(count, GFP_KERNEL); + if (!bioscfg_drv.spm_data.auth_token) { + ret = -ENOMEM; + goto exit_token; + } + + memcpy(bioscfg_drv.spm_data.auth_token, buf, count); + bioscfg_drv.spm_data.auth_token[length] = '\0'; + return count; + + +exit_token: + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token = NULL; + + return ret; + +} +static struct kobj_attribute password_spm_auth_token = __ATTR_WO(auth_token); + +static struct attribute *secure_platform_attrs[] = { + &password_spm_display_name.attr, + &password_spm_display_langcode.attr, + &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_type.attr, + &password_spm_role.attr, + &password_spm_auth_token.attr, + NULL, +}; + +static const struct attribute_group secure_platform_attr_group = { + .attrs = secure_platform_attrs, +}; + +void 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 = NULL; + + kfree(bioscfg_drv.spm_data.signing_key); + bioscfg_drv.spm_data.signing_key = NULL; + + kfree(bioscfg_drv.spm_data.auth_token); + bioscfg_drv.spm_data.auth_token = NULL; + + if (bioscfg_drv.spm_data.attr_name_kobj) + sysfs_remove_group(bioscfg_drv.spm_data.attr_name_kobj, + &secure_platform_attr_group); +} + +int populate_secure_platform_data(struct kobject *attr_name_kobj) +{ + /* Populate data for Secure Platform Management */ + bioscfg_drv.spm_data.attr_name_kobj = attr_name_kobj; + + strscpy(bioscfg_drv.spm_data.attribute_name, SPM_STR, + sizeof(bioscfg_drv.spm_data.attribute_name)); + strscpy(bioscfg_drv.spm_data.display_name, SPM_STR_DESC, + sizeof(bioscfg_drv.spm_data.display_name)); + + bioscfg_drv.spm_data.is_enabled = 0; + bioscfg_drv.spm_data.mechanism = 0; + bioscfg_drv.pending_reboot = false; + update_spm_state(); + + bioscfg_drv.spm_data.endorsement_key = NULL; + bioscfg_drv.spm_data.signing_key = NULL; + bioscfg_drv.spm_data.auth_token = NULL; + + return sysfs_create_group(attr_name_kobj, &secure_platform_attr_group); +} From patchwork Thu Apr 20 16:54:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219011 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 EFAFFC77B7C for ; Thu, 20 Apr 2023 16:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjDTQzy (ORCPT ); Thu, 20 Apr 2023 12:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230334AbjDTQza (ORCPT ); Thu, 20 Apr 2023 12:55:30 -0400 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14E04469E; Thu, 20 Apr 2023 09:55:11 -0700 (PDT) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-187d9c205e9so710720fac.3; Thu, 20 Apr 2023 09:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009711; x=1684601711; 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=Obe2vSVBXXici55JN5j0R09I4VIG8/7jWFwQnKEIzYc=; b=n32strS6mhAujrsaY1EeHfNtd2VqSI80/VYG4II3M82SRNe1Wkhpgd4nDvj+sjkfor +NAn5dXEnYZ4NncIRN8XNIMrhrBc+7BoVGFmMyhzQcxC85Zhw4+ZNcblIHSuvMrEGpFu rQR/LYGjt16Frd9+GInBz38LIdzl7IACGnGJKc9llUopKSlelisu++0u7hXtChNBFCHQ 3hBI4qovSs3qvb/HZ9OQOSWdq95oDUtnlc0vzxyyvR++iN50vaseDqnrPVv5qoxeIrb8 6yTEw33XtwOAQDTMKKgOO6NU2fUFoXEPduZjeTuY1m3KvlC0uA0T9oOZgp6VnfhEBFcV JusQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009711; x=1684601711; 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=Obe2vSVBXXici55JN5j0R09I4VIG8/7jWFwQnKEIzYc=; b=Ipv9aiy+z47P+PJvueRGX2y6FX1gOGA8s8rWLOavHaD2VlENVRwyZaEmsEpABP2nG6 oMGLYr+0NiAr1G6ifHfqPuac8PAVXO5Y2cQ5q2ZHCMxVLrdPgHrEmpB1FK4j0rN7BS1D rDqpHuSxqD8qEie+sg7Yx4sGausqVeWuNYwSTD6N1PYqhpqWBj/S+1iQyDdnFI9Kbmkv bEyU/H4iqP1HXcj0lvaAcJIdybfA2PBcHUBV11za2onDmImz65sRV6vA/tRvuup2hCD0 ZbxQ22LMivHLfqx1iIoyn3VKBbnlL3MSM7AGzwqm+1k5p1UnUI6YBxG3DaRN0ziMkSpG ju8g== X-Gm-Message-State: AAQBX9eEWyyow6ujmJCf0cMj+ehQp/QVqZZB2t7aOF/+LCL21JMEWEK7 cyksbWvqNxgBXybzxtFlR4SKGXAqmcI= X-Google-Smtp-Source: AKy350bImdjl+jIQnSG93LBi6Y2oiNc6MtUjjKPQ6gJJ738vcugTOzT9YS3EOcXJfANg/8cg5+bGvQ== X-Received: by 2002:a05:6871:54c:b0:184:95:b822 with SMTP id t12-20020a056871054c00b001840095b822mr1593875oal.25.1682009711013; Thu, 20 Apr 2023 09:55:11 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:10 -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 Subject: [PATCH v11 12/14] HP BIOSCFG driver - surestart-attributes Date: Thu, 20 Apr 2023 11:54:52 -0500 Message-Id: <20230420165454.9517-13-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 130 ++++++++++++++++++ 1 file changed, 130 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/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c new file mode 100644 index 000000000000..72952758ffe3 --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c @@ -0,0 +1,130 @@ +// 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 + +#define LOG_MAX_ENTRIES 254 +#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 = 0; + + ret = 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 = 0; + + // Get the number of event logs + ret = hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT, + HPWMI_SURESTART, + &count, 1, sizeof(count)); + + /* + * The show() api will not work if the audit logs ever go + * beyond 4KB + */ + if (count * LOG_ENTRY_SIZE > PAGE_SIZE) + return -EFAULT; + + if (ret < 0) + return ret; + + /* + * We are guaranteed the buffer is 4KB so today all the event + * logs will fit + */ + + for (i = 0; ((i < count) & (ret >= 0)); i++) { + *buf = (i + 1); + ret = hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG, + HPWMI_SURESTART, + buf, 1, 128); + if (ret >= 0) + buf += LOG_ENTRY_SIZE; + } + + return (count * LOG_ENTRY_SIZE); +} + +static struct kobj_attribute sure_start_audit_log_entry_count = __ATTR_RO(audit_log_entry_count); +static struct kobj_attribute sure_start_audit_log_entries = __ATTR_RO(audit_log_entries); + +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "sure-start\n"); +} +static struct kobj_attribute sure_start_type = __ATTR_RO(type); + +static 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); +} + +static struct kobj_attribute sure_start_display_langcode = + __ATTR_RO(display_name_language_code); + + +static ssize_t display_name_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%s\n", SURE_START_DESC); +} +static struct kobj_attribute sure_start_display_name = __ATTR_RO(display_name); + +static struct attribute *sure_start_attrs[] = { + &sure_start_display_name.attr, + &sure_start_display_langcode.attr, + &sure_start_audit_log_entry_count.attr, + &sure_start_audit_log_entries.attr, + &sure_start_type.attr, + NULL +}; + +static const struct attribute_group sure_start_attr_group = { + .attrs = sure_start_attrs, +}; + +void exit_sure_start_attributes(void) +{ + sysfs_remove_group(bioscfg_drv.sure_start_attr_kobj, + &sure_start_attr_group); +} + +int populate_sure_start_data(struct kobject *attr_name_kobj) +{ + bioscfg_drv.sure_start_attr_kobj = attr_name_kobj; + return sysfs_create_group(attr_name_kobj, &sure_start_attr_group); +} From patchwork Thu Apr 20 16:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219012 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 8CB07C77B73 for ; Thu, 20 Apr 2023 16:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbjDTQz4 (ORCPT ); Thu, 20 Apr 2023 12:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbjDTQza (ORCPT ); Thu, 20 Apr 2023 12:55:30 -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 E33424C0A; Thu, 20 Apr 2023 09:55:12 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-38be107e467so366903b6e.2; Thu, 20 Apr 2023 09:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009712; x=1684601712; 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=ERiuGLSSLt14Zm3/7WEsnxh0ydwhBcPd1KCXT7ReQ90=; b=DjBAOGFRa7uMiMhUhFUB8PPl8ch/83lLQzh/4ecUdFZlljeiCD9XUzsv++VDNrX4D8 oGQrdJdYTgzo7lmIAQhX3vFm/UT/O/96jU44MtiD+EXEzdUrmpjgS+qP7WO//S7BaII8 95e4bc2yzzMM4hVztyQvzkTUZWIxuq1a0qCXR8QoUUA/4bZZEOYbfht4SznSg+XoddzM HfnmrwWbVcuLa1Q8scoPqwDv4DBtidZfnqlQVg7dv3CTH6UEiorvDtQjJBnCUey1lDZe auH74v6n2sqUZhdwFHt6iTchCmF0hTbKVfvtCJ9SFgtY9v3/DIBTahXIl7D9sa1QMsjS 1VxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009712; x=1684601712; 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=ERiuGLSSLt14Zm3/7WEsnxh0ydwhBcPd1KCXT7ReQ90=; b=cqCaAVgDzP+aBsGSOzJCDJrHB2mymb2A1uF+oiyjPe/70/rgfF1OJvfy7kuQgWVACx 5zdjUv8gV+F8rSv0dfGm8rm1jenpVxaY+8jfW1e4r8b7QZp/vE/NiX/0hn5jyNH/31su 2tK6rVQVEkE4RoZe9mbKrmR6hQZfUqKeu1TjKOdY6JXKygYbHbv01qtCvVBVzx+L4Bws HkSx1MxjA3+/EG0Gi4nnHO/4yrUF9gn3X/v/LpdzGZuS/xA2mb/ar2Y9m0LmgBujVhHB 3KEu/PcN0AuydQvhUdB5fB6K6BTawQw9pykfpxu3olXEBCep9g0sKeBK+EOYyiZHm9Zl M+bQ== X-Gm-Message-State: AAQBX9eBBF/ApIBCDXkTnUlG7wuMWlt6HrtLdXG0/9uzHN37XQvTE1wT Sfyzk57KfnDePYYTDalo0qDdmz6XmPw= X-Google-Smtp-Source: AKy350aoddBkpZ+/HbSqG5gtSmwAvwFJiWs+U53YeExoxdWXSankEjLSBlGr0GmjcQpCeJx5Nid5wg== X-Received: by 2002:a05:6808:130e:b0:386:f961:4287 with SMTP id y14-20020a056808130e00b00386f9614287mr1446590oiv.18.1682009711982; Thu, 20 Apr 2023 09:55:11 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:11 -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 Subject: [PATCH v11 13/14] HP BIOSCFG driver - Makefile Date: Thu, 20 Apr 2023 11:54:53 -0500 Message-Id: <20230420165454.9517-14-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 drivers/platform/x86/hp/hp-bioscfg/Makefile diff --git a/drivers/platform/x86/hp/Kconfig b/drivers/platform/x86/hp/Kconfig 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. +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/Makefile index db1eed4cd7c7..e4f908a61acf 100644 --- a/drivers/platform/x86/hp/Makefile +++ b/drivers/platform/x86/hp/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_HP_ACCEL) += hp_accel.o obj-$(CONFIG_HP_WMI) += hp-wmi.o obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o +obj-$(CONFIG_HP_BIOSCFG) += hp-bioscfg/ diff --git a/drivers/platform/x86/hp/hp-bioscfg/Makefile b/drivers/platform/x86/hp/hp-bioscfg/Makefile new file mode 100644 index 000000000000..529eba6fa47f --- /dev/null +++ b/drivers/platform/x86/hp/hp-bioscfg/Makefile @@ -0,0 +1,13 @@ +obj-$(CONFIG_HP_BIOSCFG) := hp-bioscfg.o + +hp-bioscfg-objs := bioscfg.o \ + enum-attributes.o \ + int-attributes.o \ + string-attributes.o \ + passwdobj-attributes.o \ + biosattr-interface.o \ + passwdattr-interface.o \ + ordered-attributes.o \ + surestart-attributes.o \ + spmobj-attributes.o + From patchwork Thu Apr 20 16:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jorge Lopez X-Patchwork-Id: 13219013 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 9837CC77B73 for ; Thu, 20 Apr 2023 16:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbjDTQ4K (ORCPT ); Thu, 20 Apr 2023 12:56:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbjDTQzb (ORCPT ); Thu, 20 Apr 2023 12:55:31 -0400 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7603B5266; Thu, 20 Apr 2023 09:55:14 -0700 (PDT) Received: by mail-oo1-xc29.google.com with SMTP id c17-20020a4aa4d1000000b005418821052aso831485oom.6; Thu, 20 Apr 2023 09:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682009713; x=1684601713; 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=gpWRid5cmCr0SjsRhGTnuvLDk1kP0ktA07Mc2yuVwzg=; b=hrCkm3v0lPvEh5WcfNQ8A72ib23453Pklu0dKzjJ6OPLQQZNE9m1/O3Ba9pyWgO8bh AeEbyidca4tDwBPuhM9x46UHBhNmZgjN2cVb3Is7tup/xUO/4OLVcvr/cMP0n7rMOB8n qV2EWIkBV+Ya4JsuaeQZR0UtRWd3nMZWcvnHrYPxD9Mw9QZzWL+0mY6CI8aUsRcO+qQT 9nYuw13C144FzmPSpKAOpY2/D6w4qBDQR6lyx2PwN/sFdexXNKbJLqHeIAAWYRXelr6w cbTSwNgWrGfXXK5113BNEoTiI+OUmmqMJP+KYZqO0HiZVRoBcAPUimMSK7EkRxKybB4R XYYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682009713; x=1684601713; 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=gpWRid5cmCr0SjsRhGTnuvLDk1kP0ktA07Mc2yuVwzg=; b=fCJmWfaH3ZDXMIwTYJTMj3hQyzEm4AwVt7JceKtovv4NiHvSG8tYSbYa5rumIzt1uz H6CuhSwg0aIFikto8Zu5MkVtrMdxj2zYlt/P16T5J9clbiFuROhZRyzz4h0ky1kDkwsU KqEiKrtFuQx3qtr4kuUMhr3RKor5VqyeRTTn9/RiZ0AlLsk+SQVKf0g8A3RZrdd9H9rc kk+RvkBA+3ZthrbwDFHOBYEwynhYzHvJEraRlbM2isS6jr0UuvkmedcPtHntgUsywqT5 Nu5r7juyB3/Lpy7aL8vb/68XlxdVxs6d4MNYyNFDF8jrMwkMXwLnCziw2yWTnANL4ck5 gxpA== X-Gm-Message-State: AAQBX9dGbWDGypDPwn6bUwZcsNQSkED8k5ctgsIi0qz8gSrg125LVYhg bHCI0aonee1BsKQ6Enu6u6s= X-Google-Smtp-Source: AKy350Y1cDONqVLv8t632CLRxjrRwLeh1FZP4I/U+6wffWnW8ySXbVTBwC5DG//mLBp6F+wgFqEEAA== X-Received: by 2002:a4a:3315:0:b0:545:3076:9e6b with SMTP id q21-20020a4a3315000000b0054530769e6bmr1269076ooq.6.1682009712936; Thu, 20 Apr 2023 09:55:12 -0700 (PDT) Received: from grumpy-VECTOR.hsd1.tx.comcast.net ([2601:2c3:480:7390:d090:9746:e449:eb46]) by smtp.gmail.com with ESMTPSA id s129-20020a4a5187000000b005252e5b6604sm791913ooa.36.2023.04.20.09.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 09:55:12 -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 Subject: [PATCH v11 14/14] HP BIOSCFG driver - MAINTAINERS Date: Thu, 20 Apr 2023 11:54:54 -0500 Message-Id: <20230420165454.9517-15-jorge.lopez2@hp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420165454.9517-1-jorge.lopez2@hp.com> References: <20230420165454.9517-1-jorge.lopez2@hp.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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.’s commercial 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 0c9011f5fc17..7d1f261af539 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9367,6 +9367,12 @@ S: Obsolete W: http://w1.fi/hostap-driver.html F: drivers/net/wireless/intersil/hostap/ +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