Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1422701imw; Tue, 5 Jul 2022 09:10:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1teykEy547Qbe9iEOmEArEoAXSLggczC1IW5bse4bxbHYs7QKH2/M2Na4LYxldi0fCfwX2H X-Received: by 2002:a17:907:160a:b0:726:40fa:36d3 with SMTP id hb10-20020a170907160a00b0072640fa36d3mr33377978ejc.694.1657037432156; Tue, 05 Jul 2022 09:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657037432; cv=none; d=google.com; s=arc-20160816; b=m6pTWb9wjLT6bqnv9ytakYwmAymCVIyZh47LI8k+TmfMaAzai/Cn21KTu4m2N5dUXz 7gGNacmY7qMx0KDW9urHk/p/yogEUoIdwaYDyXpnmlCrKx+jfE8iUG31rRfNdUyPwo5g Wbip5TzvLBcGF+lUW6FLkR/0rMnJgp2lXW/08C2baW2KtyXUqJU9YIp3NeBNYuWjETyi cOb22ArPNvK1CHWU7gR5CW8PqpHZDE3zX0juEsWuG3xtawmxsi/Bh+OxvTrQDvp5P8o6 iokkiw01c3vAzV+AJnXNhY+juUUgG752SHoVp0B5aegzeUnj0ebExbCa/3FUtxomFaTU V7NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=01B3EcgLMf7TyCNa7yJPWb4zA1eQYrwMXQrsozA+Reg=; b=U8sdtJ7nNVUv8CUv/lqhuvpE3EiWBmcd5VTDze+xnV0hcHzEZ6pNy0Nwv460/DK+7C Z0Obb+FOu9gBs3vZhpiZ9WAu/owj8roN/5JfXLdHzn+co3DzUNy2BXsgkNKwimRKBfbX Uq/fZ/y88sNVA8/Ii1JWRqx4BHAcwGIESPph0ahOHdk9OX4cKSs2ZDGjGczbMtmQDP+m zqMrtxd+63/3B/85rJynz3uzbkmv9TZptV8jzKHd/5+U2f0Ekx/JJbwh41v/Ge33Ts0y OfEj3Lt1eCefWcKrXn6Zspe0nZKL8Ms5ebVm9c9jseX2q/29OgnS/eMMW75f0ZOR5rmY UnHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BwdCA2jS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ej27-20020a056402369b00b00434fff6fe37si38859576edb.227.2022.07.05.09.10.07; Tue, 05 Jul 2022 09:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BwdCA2jS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233065AbiGEPv3 (ORCPT + 99 others); Tue, 5 Jul 2022 11:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbiGEPvA (ORCPT ); Tue, 5 Jul 2022 11:51:00 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 696471F605; Tue, 5 Jul 2022 08:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657036200; x=1688572200; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U3saHsgvYciwhLfxacVmiu3qWDreQ9A9gfZULUZztoM=; b=BwdCA2jSr9nVyKKJhKuDRlAA+/s+Mxt2UjWkOWCvKrs0cmgmt9QjiOXi GherXUgRmApQnimywSMMmOl73HTBuXet9WDDAIGnCXlJdcQbj0gW9n4b7 +fuceKb2kFj9B97NLAm/maA9gHLrsAYkwnOLz75RThrWNzRkL7KBqY0qS s0kFcHP6VNT3+kUlXMTj3KRTIGKtbTBy4IwpCw/l8qCl7wI9DdeqK/cuW FJyBEDIsPoDH0eessU1Da+Y9qunfqo75gXcvP0/24JkcEnjBJlTMzUsk9 T0x9f4yzjVQXvyeHtJ1leXbGW0yKt2S+xATaIxXXQ9zGkkXvpk7CtV4b6 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="282143208" X-IronPort-AV: E=Sophos;i="5.92,247,1650956400"; d="scan'208";a="282143208" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 08:49:59 -0700 X-IronPort-AV: E=Sophos;i="5.92,247,1650956400"; d="scan'208";a="650213996" Received: from amangla-mobl.amr.corp.intel.com (HELO localhost) ([10.255.0.184]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 08:49:57 -0700 From: ira.weiny@intel.com To: Dan Williams , Bjorn Helgaas , Jonathan Cameron Cc: Ira Weiny , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Greg Kroah-Hartman , Lukas Wunner , Alison Schofield , Vishal Verma , Dave Jiang , Ben Widawsky , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH V13 5/9] driver-core: Introduce BIN_ATTR_ADMIN_{RO,RW} Date: Tue, 5 Jul 2022 08:49:28 -0700 Message-Id: <20220705154932.2141021-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220705154932.2141021-1-ira.weiny@intel.com> References: <20220705154932.2141021-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny Many binary attributes need to limit access to CAP_SYS_ADMIN only; ie many binary attributes specify is_visible with 0400 or 0600. Make setting the permissions of such attributes more explicit by defining BIN_ATTR_ADMIN_{RO,RW}. Cc: Bjorn Helgaas Suggested-by: Dan Williams Suggested-by: Krzysztof WilczyƄski Reviewed-by: Greg Kroah-Hartman Signed-off-by: Ira Weiny --- Changes from V12: Pick up review tag Bjorn: NOTE: this has a lot of similarities to https://lore.kernel.org/all/20210416205856.3234481-7-kw@linux.com/ I'm not sure why that patch was not picked up. But I've added Krzysztof as a suggested by if that is ok? Changes from V11: New Patch --- include/linux/sysfs.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e3f1e8ac1f85..fd3fe5c8c17f 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -235,6 +235,22 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size) #define BIN_ATTR_RW(_name, _size) \ struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) + +#define __BIN_ATTR_ADMIN_RO(_name, _size) { \ + .attr = { .name = __stringify(_name), .mode = 0400 }, \ + .read = _name##_read, \ + .size = _size, \ +} + +#define __BIN_ATTR_ADMIN_RW(_name, _size) \ + __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size) + +#define BIN_ATTR_ADMIN_RO(_name, _size) \ +struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size) + +#define BIN_ATTR_ADMIN_RW(_name, _size) \ +struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size) + struct sysfs_ops { ssize_t (*show)(struct kobject *, struct attribute *, char *); ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); -- 2.35.3