Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp237356ybh; Mon, 20 Jul 2020 15:27:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5ua8O2jA41Pn3e3BLuRvKDHb3rDRvrPX0ReAoeotX3oDeFdyjwnhBOigjlzFaMRTqUnTC X-Received: by 2002:a05:6402:1d35:: with SMTP id dh21mr24141723edb.186.1595284048796; Mon, 20 Jul 2020 15:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595284048; cv=none; d=google.com; s=arc-20160816; b=n72HSX2TeEnynqeM/njzxj8wYihcsf3GCFTcUy7D1k9if8JtSOpqCrjZnZCcnH7N24 +tV6bQrnJVI2qhgskYrPLPkU3jRLKC3S6ZWtYSYx5HQQ37R8a0BFp+klNAZKcOyLv/dT K00dUnfl1vneI8Ad+dBfj2bx0K78N+R6YOBLk/wUczPNLfTlUczWycLqIxADgRqUVhYD WSiIMo72EGTQs7Sys2DQ5UQRKZ/JE+xQByA4Aq07h80/qycdFdem/KhS++UhgeSWF4n0 B7Id4j5x6hcaNahgfmBsr+8liYAHxHu4/mUWhZdlJ3F3I3XJG839wWUYMxd4LWBTAKoB GWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=B7lPvEzIl2g4euxdKtWefBNxUjClBlLveejfNQNFstw=; b=gTdNtUykA5PgkdAPHW3ldfyVDlwncGbYCE4kLC4PxJ9cUMklhS1p8l8C6PoCB48oZZ TkW9Q8r6+n//nh1pdK2MBlDNWOnxODq1XIYBwmkFOqaG+gqdRLjaOTQx+ePPiS86gjLK 2Zy5n7cUtvt8FBIf1T0K3dtEoFgKrluyDfYxKzzlN2mLU7AHkYNUfvl0Dli8B4kS2nS0 K+d3sl8po9Z+iPYH2yyFOuLCNsFXT4iOfCV6Xvew5lAIoYZ4262g6L2mWlXZi4rEP67N KAGLBsUxnh7VpOo0Avi8Lk8+doAv5X5Mw5zrV+BT0pxjSYZ0MQr19Pnfd5QAMsslnCb3 2i3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox25si11699273ejb.408.2020.07.20.15.27.06; Mon, 20 Jul 2020 15:27:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728162AbgGTWY0 (ORCPT + 99 others); Mon, 20 Jul 2020 18:24:26 -0400 Received: from mga11.intel.com ([192.55.52.93]:33768 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbgGTWYZ (ORCPT ); Mon, 20 Jul 2020 18:24:25 -0400 IronPort-SDR: o6TgkDfu2QLyI10ecnrGTMCAC58rCrVrPIjsJm1aR4yuEzg5ctE4W1X6XU6XGNeIeWGSfA2kR0 PA2a8YHzzsJw== X-IronPort-AV: E=McAfee;i="6000,8403,9688"; a="147966589" X-IronPort-AV: E=Sophos;i="5.75,375,1589266800"; d="scan'208";a="147966589" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2020 15:24:24 -0700 IronPort-SDR: 6FBNJWGcBCpI6Zitti5qkNj5ViUANRiDp9dki/pzUJ2cDoPQlHm56Ujj6bdgEFw/GG5LoCZKHw 9QAL2uhUPbXw== X-IronPort-AV: E=Sophos;i="5.75,375,1589266800"; d="scan'208";a="271553180" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2020 15:24:24 -0700 Subject: [PATCH v3 08/11] driver-core: Introduce DEVICE_ATTR_ADMIN_{RO,RW} From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , vishal.l.verma@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 20 Jul 2020 15:08:07 -0700 Message-ID: <159528288766.993790.5647904882591265970.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <159528284411.993790.11733759435137949717.stgit@dwillia2-desk3.amr.corp.intel.com> References: <159528284411.993790.11733759435137949717.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A common pattern for using plain DEVICE_ATTR() instead of DEVICE_ATTR_RO() and DEVICE_ATTR_RW() is for attributes that want to limit read to only root. I.e. many users of DEVICE_ATTR() are specifying 0400 or 0600 for permissions. Given the expectation that CAP_SYS_ADMIN is needed to access these sensitive attributes add an explicit helper with the _ADMIN_ identifier for DEVICE_ATTR_ADMIN_{RO,RW}. Reviewed-by: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Dan Williams --- include/linux/device.h | 4 ++++ include/linux/sysfs.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 15460a5ac024..d7c2570368fa 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -128,8 +128,12 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, __ATTR_PREALLOC(_name, _mode, _show, _store) #define DEVICE_ATTR_RW(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RW(_name) +#define DEVICE_ATTR_ADMIN_RW(_name) \ + struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600) #define DEVICE_ATTR_RO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RO(_name) +#define DEVICE_ATTR_ADMIN_RO(_name) \ + struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400) #define DEVICE_ATTR_WO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_WO(_name) #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 86067dbe7745..34e84122f635 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -123,6 +123,13 @@ struct attribute_group { .show = _name##_show, \ } +#define __ATTR_RW_MODE(_name, _mode) { \ + .attr = { .name = __stringify(_name), \ + .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ + .show = _name##_show, \ + .store = _name##_store, \ +} + #define __ATTR_WO(_name) { \ .attr = { .name = __stringify(_name), .mode = 0200 }, \ .store = _name##_store, \