From patchwork Fri Jun 17 22:54:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 9185123 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 E3D5A608A6 for ; Fri, 17 Jun 2016 22:56:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D370927EE2 for ; Fri, 17 Jun 2016 22:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C824927F07; Fri, 17 Jun 2016 22:56:52 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,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 7115827EED for ; Fri, 17 Jun 2016 22:56:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753594AbcFQWz3 (ORCPT ); Fri, 17 Jun 2016 18:55:29 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33159 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753501AbcFQWzW (ORCPT ); Fri, 17 Jun 2016 18:55:22 -0400 Received: by mail-wm0-f67.google.com with SMTP id r201so1053239wme.0; Fri, 17 Jun 2016 15:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qcZJp5MgTZGDXM9Jda7xK/1qahZULZIj9QsdcrfLLxA=; b=P3XiRqCXZpTMX3WdF67sCModGeSLLFU9iTBym25Ko4jXu4HrBVhiRcKMZZpZj0ZTm+ 7mG95vw4UGhps+bsRIgiAWCjhDoiukxnjDcct7WH2fUsh84SLY6bPaEOmSjLxXSddMG+ ZF3hl7g/j7ZxXxq7Gt96V2IF5ROpSI9sC/w0t1dgs2HLAZK7oXOrN234y6T5QstoqxrD wxHb/KkBuEhxfW9mXrKHiKVxhlAY1t+24sV075R12HWXN32IDHYuj0PT0L/sNaQ3YrhJ AdTKNFKPw5Ms1THFzj/QFLqRlXNwJF9NW5U8tcPp8JBWTu/IgmxhWz4FXnL3DRkQurEe cfyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qcZJp5MgTZGDXM9Jda7xK/1qahZULZIj9QsdcrfLLxA=; b=Kg1GHJaNSGWMvlpe4Raq4c4qv3APOS7Qa5+zCHP04sO5Wiwg/AnST+t40HufOlxZUU CVYCHaiXA/QatEVWUqxEnzijk397+eMLISkUAn8fychuqiDpOfTPTd3DCD5B4eUG9XVM hEEvDhuqcP+U5++uJX6Smi6yXb0uxr5EnB1pun3ten7WrN+42HGXhYtPr6A7KDI5iL6j Y6Zfd+xMkc7/HIwqFhDVjk0G31KhGqEVfFXoTNBVW8AQ6dwT2z1KrH1XOix3E3RYJ7pV 1sutJ4QzNCoKvXtjxFpq+V6z/53561TUHdviw/Ji1iZW4HyXCMUuYd8Z5NRsH75JUycf 6yBA== X-Gm-Message-State: ALyK8tKKyHVvqkNmitqHH2uXgItXyEq5KrK1+YX8Z5xvwpoa1sCDiJKdFmhzgNesQXg4rg== X-Received: by 10.194.203.226 with SMTP id kt2mr4270256wjc.75.1466204121057; Fri, 17 Jun 2016 15:55:21 -0700 (PDT) Received: from Pali-Latitude.lan (pali.kolej.mff.cuni.cz. [78.128.193.202]) by smtp.gmail.com with ESMTPSA id d137sm806128wmd.12.2016.06.17.15.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 15:55:20 -0700 (PDT) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Jean Delvare , Guenter Roeck , Jan C Peters , Thorsten Leemhuis , =?UTF-8?q?David=20Santamar=C3=ADa=20Rogado?= , Peter Saunderson , Tolga Cakir , "Austin S. Hemmelgarn" , Mario_Limonciello@dell.com, Gabriele Mazzotta , =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= , Dakota Whipple , Leon Yu Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 2/6] hwmon: (dell-smm) Restrict fan control and serial number to CAP_SYS_ADMIN by default Date: Sat, 18 Jun 2016 00:54:45 +0200 Message-Id: <1466204089-17030-3-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1466204089-17030-1-git-send-email-pali.rohar@gmail.com> References: <1466204089-17030-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For security reasons ordinary user must not be able to control fan speed via /proc/i8k by default. Some malicious software running under "nobody" user could be able to turn fan off and cause HW problems. So this patch changes default value of "restricted" parameter to 1. Also restrict reading of DMI_PRODUCT_SERIAL from /proc/i8k via "restricted" parameter. It is because non root user cannot read DMI_PRODUCT_SERIAL from sysfs file /sys/class/dmi/id/product_serial. Old non secure behaviour of file /proc/i8k can be achieved by loading this module with "restricted" parameter set to 0. Note that this patch has effects only for kernels compiled with CONFIG_I8K and only for file /proc/i8k. Hwmon interface provided by this driver was not changed and root access for setting fan speed was needed also before. Reported-by: Mario Limonciello Signed-off-by: Pali Rohár Cc: stable@vger.kernel.org # will need backport --- drivers/hwmon/dell-smm-hwmon.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 480b2fa..c8bd3fdd 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -67,6 +67,7 @@ static DEFINE_MUTEX(i8k_mutex); static char bios_version[4]; +static char bios_machineid[16]; static struct device *i8k_hwmon_dev; static u32 i8k_hwmon_flags; static uint i8k_fan_mult = I8K_FAN_MULT; @@ -95,13 +96,13 @@ module_param(ignore_dmi, bool, 0); MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match"); #if IS_ENABLED(CONFIG_I8K) -static bool restricted; +static bool restricted = true; module_param(restricted, bool, 0); -MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set"); +MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)"); static bool power_status; module_param(power_status, bool, 0600); -MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); +MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)"); #endif static uint fan_mult; @@ -397,9 +398,11 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg) break; case I8K_MACHINE_ID: - memset(buff, 0, 16); - strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), - sizeof(buff)); + if (restricted && !capable(CAP_SYS_ADMIN)) + return -EPERM; + + memset(buff, 0, sizeof(buff)); + strlcpy(buff, bios_machineid, sizeof(buff)); break; case I8K_FN_STATUS: @@ -516,7 +519,7 @@ static int i8k_proc_show(struct seq_file *seq, void *offset) seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", I8K_PROC_FMT, bios_version, - i8k_get_dmi_data(DMI_PRODUCT_SERIAL), + (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid, cpu_temp, left_fan, right_fan, left_speed, right_speed, ac_power, fn_key); @@ -985,6 +988,8 @@ static int __init i8k_probe(void) strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), sizeof(bios_version)); + strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), + sizeof(bios_machineid)); /* * Get SMM Dell signature