Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4832215imw; Tue, 19 Jul 2022 14:16:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s/5TyENht/Ay/hz6CUNNdymMTpRnW1OR7RFh6G3TNKtiKtHCpbaRejTT94cD/rO57bOSSB X-Received: by 2002:a17:906:4fc4:b0:6da:b4c6:fadb with SMTP id i4-20020a1709064fc400b006dab4c6fadbmr32326698ejw.282.1658265418548; Tue, 19 Jul 2022 14:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658265418; cv=none; d=google.com; s=arc-20160816; b=B3o8zAtzO7dNlWPS0FbZr4murIHmPIL1k3KTE7dv2/1yfi2IDKYIRKfCO1/OuqRNTm Ljxl1XKPbXaIKVEEg4ynT3y1oJjsVas9ldxXA55zNQMWA+/Ynb7YaQW1oE6AT3Uyff7R D5A84aeXmrc+cXlWlLdc7ckInXCz6kNiAMoe6vBsHk1uurGAn1AWktAe9qDXywr0u7Co Qv/rEkVvNDF5RuQYcnFhCmsecfVmGKrbBXXcl6wIvfv0c8sMHneBz7C1iBnN+PWPjUYT 1ftCpybW9KyeN/Hlf/1HmIjfG2OAnTijbOb0pHuN2yqNtGLVNLwqqC7rHuguIc4NkgeK GByw== 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=coWOA6480NCzD24eULoVCvWnbM2/LDF1c5ZYnHUBxjk=; b=p1S4dXMNFw8r5ziTCbr+Co7EDZmAL8u9t8b0fldABC0KJ0n2ZirAYMctFd7CNtb4bp /EE3iMwJeQbXO+f/R0iFf4jh36JUyoY2SFr5rMVb53Jl2FcypwTenWdhPPTDlB8rNzOv N8Dg2ReUYLZS2xnEtcklwk2X2idntm5yiu/vVjORcV2eUJHyh3C4TPQqnw6IzHXPByiV /aPPqbjLSX0lcw09EEXiCTfz+i6X4IZWh9GIiAYcMX7NszDgr4wKQo7UwV1GIN+CWoPN +SYXVsCbsl9+oIIr+ZaFI+s65BkBouc7vS4/C5iUS49fvGslGFbN6F8h/uLOLL/3vUzu 9BBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Glo+YNud; 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 y11-20020a056402440b00b0043a59da51a0si24446864eda.95.2022.07.19.14.16.31; Tue, 19 Jul 2022 14:16:58 -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=Glo+YNud; 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 S240463AbiGSUxR (ORCPT + 99 others); Tue, 19 Jul 2022 16:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240390AbiGSUxI (ORCPT ); Tue, 19 Jul 2022 16:53:08 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 176DA606B1; Tue, 19 Jul 2022 13:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658263988; x=1689799988; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o8cpg+k/zcj8b9lEhm3BePNCqlmICcbckVvF0lSKjf0=; b=Glo+YNudwAETmbdIM3xd0qKsD0+uH4tSBnExVG25J6txg1otfHdbTXZ8 RCQS62B+GEZilxM5XXvbm7LQ5lHYmoVUyOdrQ6gtTUM7Bo4lPRLAX6MNj /p1mCdBwm+n0+eexO17L6xz01EFkMU9LSVIEP3TDOqRggNE28lpeKbtmJ 4rqtTJzyxqmu0KfeSdO4KNzPkW1LClkTGVUq8OdeWNVtRDoi617Ke+Hkf QhSJdPV6watLwLiJo3CayJ06ZmcYa+zVsHoWbffUM9ZHBixL/CrZmre/u nl5OIqfrijphNaX8av09jfLt8y71F30S9DKzPvzs4gRp6+J3kXYwOkRkO w==; X-IronPort-AV: E=McAfee;i="6400,9594,10413"; a="287751568" X-IronPort-AV: E=Sophos;i="5.92,285,1650956400"; d="scan'208";a="287751568" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2022 13:53:07 -0700 X-IronPort-AV: E=Sophos;i="5.92,285,1650956400"; d="scan'208";a="630492660" Received: from kscamus-mobl1.amr.corp.intel.com (HELO localhost) ([10.255.6.221]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2022 13:53:06 -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 V16 5/6] driver-core: Introduce BIN_ATTR_ADMIN_{RO,RW} Date: Tue, 19 Jul 2022 13:52:48 -0700 Message-Id: <20220719205249.566684-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220719205249.566684-1-ira.weiny@intel.com> References: <20220719205249.566684-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 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: Jonathan Cameron 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