From patchwork Thu Sep 28 04:02:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Limonciello, Mario" X-Patchwork-Id: 9975275 X-Patchwork-Delegate: dvhart@infradead.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5DA0B60365 for ; Thu, 28 Sep 2017 04:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DF5C2942E for ; Thu, 28 Sep 2017 04:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 430892943A; Thu, 28 Sep 2017 04:03:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA4062942E for ; Thu, 28 Sep 2017 04:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751754AbdI1EDJ (ORCPT ); Thu, 28 Sep 2017 00:03:09 -0400 Received: from esa3.dell-outbound.iphmx.com ([68.232.153.94]:30821 "EHLO esa3.dell-outbound.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751349AbdI1ECa (ORCPT ); Thu, 28 Sep 2017 00:02:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dell.com; i=@dell.com; q=dns/txt; s=smtpout; t=1506571217; x=1538107217; h=from:to:cc:subject:date:message-id; bh=zBJXsNvdz9zhcoyyfXxBeJnCHHcXt8jLD9IU2yQRK/s=; b=fN3JhZUR3Pwv9H3XPwdWPGZ+qQf4hIZ3SgMPotaa4qz4DPsnTpj+JTgT 4tw2k6GOrZ3GtWu/oaeaDMe1OHV1pS//LN03Zu57YgsCILEVGuypLSB3H NbeHaZqABeuJwdZWhBfnCt9H4zgqNSKL+3ds1lpeSf6qoDsfDxinsLgP3 A=; Received: from esa2.dell-outbound2.iphmx.com ([68.232.153.202]) by esa3.dell-outbound.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2017 23:00:17 -0500 Received: from ausxipps310.us.dell.com ([143.166.148.211]) by esa2.dell-outbound2.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2017 10:00:25 +0600 X-LoopCount0: from 10.208.86.39 X-IronPort-AV: E=Sophos;i="5.42,448,1500958800"; d="scan'208";a="66774566" X-DLP: DLP_GlobalPCIDSS From: Mario Limonciello To: dvhart@infradead.org, Andy Shevchenko Cc: LKML , platform-driver-x86@vger.kernel.org, Andy Lutomirski , quasisec@google.com, pali.rohar@gmail.com, Mario Limonciello Subject: [PATCH v3 6/8] platform/x86: dell-wmi-smbios: Add a sysfs interface for SMBIOS tokens Date: Wed, 27 Sep 2017 23:02:18 -0500 Message-Id: <64094c86a6083c3d4c34d1f005e8a71d07b61240.1506571188.git.mario.limonciello@dell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently userspace tools can access system tokens via the dcdbas kernel module and a SMI call that will cause the platform to execute SMM code. With a goal in mind of deprecating the dcdbas kernel module a different method for accessing these tokens from userspace needs to be created. This is intentionally marked to only be readable as root as it can contain sensitive information about the platform's configuration. Signed-off-by: Mario Limonciello --- .../ABI/testing/sysfs-platform-dell-wmi-smbios | 16 ++++++++++ drivers/platform/x86/dell-smbios.c | 36 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-smbios diff --git a/Documentation/ABI/testing/sysfs-platform-dell-wmi-smbios b/Documentation/ABI/testing/sysfs-platform-dell-wmi-smbios new file mode 100644 index 000000000000..4cbff5ffe380 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-dell-wmi-smbios @@ -0,0 +1,16 @@ +What: /sys/devices/platform//tokens +Date: October 2017 +KernelVersion: 4.15 +Contact: "Mario Limonciello" +Description: + A read-only description of Dell platform tokens + available on the machine. + + The tokens will be displayed in the following + machine readable format with each token on a + new line: + + ID Location value + + For example token: + 5 5 3 diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c index 4174afbade13..ac176953e46e 100644 --- a/drivers/platform/x86/dell-smbios.c +++ b/drivers/platform/x86/dell-smbios.c @@ -229,6 +229,34 @@ static void __init find_tokens(const struct dmi_header *dm, void *dummy) } } +static ssize_t tokens_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + size_t off = 0; + int i; + + for (i = 0; i < da_num_tokens; i++) { + if (off > PAGE_SIZE) + break; + off += scnprintf(buf+off, PAGE_SIZE-off, "%04x\t%04x\t%04x\n", + da_tokens[i].tokenID, da_tokens[i].location, + da_tokens[i].value); + } + + return off; +} + +DEVICE_ATTR(tokens, 0400, tokens_show, NULL); + +static struct attribute *smbios_attrs[] = { + &dev_attr_tokens.attr, + NULL +}; + +static const struct attribute_group smbios_attribute_group = { + .attrs = smbios_attrs, +}; + static int dell_wmi_smbios_open(struct inode *inode, struct file *file) { return nonseekable_open(inode, file); @@ -367,10 +395,16 @@ static int dell_smbios_wmi_probe(struct wmi_device *wdev) ret = -ENOMEM; goto fail_devfs_buffer; } + ret = sysfs_create_group(&wdev->dev.kobj, &smbios_attribute_group); + if (ret) + goto fail_create_group; wmi_dev = wdev; + kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE); return 0; +fail_create_group: + free_pages((unsigned long)devfs_buffer, 3); fail_devfs_buffer: free_pages((unsigned long)internal_buffer, 3); return ret; @@ -381,6 +415,8 @@ static int dell_smbios_wmi_remove(struct wmi_device *wdev) wmi_dev = NULL; free_pages((unsigned long)internal_buffer, 3); free_pages((unsigned long)devfs_buffer, 3); + sysfs_remove_group(&wdev->dev.kobj, &smbios_attribute_group); + kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE); return 0; }