From patchwork Mon Dec 2 19:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13891252 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A3C81DE3C0; Mon, 2 Dec 2024 19:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168320; cv=none; b=uBmKpDAUEqtzWxTVFe7t0dzXiHM5sFclXWEYcY78/ytg+MWJrOtwoe0s+WcYMc67mWBSDmkVv3oYcUBEm8EPuNbBydg2+RazZfFx/DEa3kYIBj55IJr80H0vaU3D3gunHr0SWEE5AMROy3fbhqDuVnikxxM8eBXPQrNMA0svIis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168320; c=relaxed/simple; bh=bXwjaMZPKYJqfzSnqgQCkzKi6u0bdbqGe9sH10KIhs4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mWx7IQOjc10Q6MT1OSIctgSpkPAZYCNbvMUc0ZuSjlNdaMpQNC1C8bp8+dlyGHwXRO9u0Dqv92xj2980QZ8FhpOjiUqwMvoqMASLSptn/EvdWihO2iBipu1nmCNIGFoPZ2NT74ddGLTbUK60Yr84q/FoPmXMi1wJ291tgpIfjEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=G/r5c3PZ; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="G/r5c3PZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168316; bh=bXwjaMZPKYJqfzSnqgQCkzKi6u0bdbqGe9sH10KIhs4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G/r5c3PZzuWfqzRo/c4UjVPrCv2Hc6wx/90Vf14fIwdZi1mnAVo+znnXrOMyEkmPu LVYLqXjVKlg/LwK9IPwQ82u4AVpwKxa61AHceic6iFHI8jS38yrxPYDpNjxqyWtluW 13LmY3bKxLxct7MeeosLShQTiri85+iwSwZu9hjs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:38:32 +0100 Subject: [PATCH 1/5] platform/x86: dell: dcdbas: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-pdx86-v1-1-9ab204c2a814@weissschuh.net> References: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> To: Stuart Hayes , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , Naveen Krishna Chatradhi , Carlos Bilbao Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733168316; l=2655; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=bXwjaMZPKYJqfzSnqgQCkzKi6u0bdbqGe9sH10KIhs4=; b=qlK8gtGb9pNa8t3MtuntUov7EtP4pBk8jm4vpiVItgItUx2t+rUIlBuPse0+uSH+r4aLhON5n HLV3OxZHlGcBWC6ZLnz9xGyxMuWwtl16/VfQiz5EP06mNibuRFiCeIE X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. While at it switch from the custom DCDBAS_BIN_ATTR_RW() to the identical BIN_ATTR_RW() macro. --- drivers/platform/x86/dell/dcdbas.c | 10 +++++----- drivers/platform/x86/dell/dcdbas.h | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/dell/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c index 0aeb8149c16bfcb5df3cad77b69d7e5978ce6536..8149be25fa267ca027d809c45fe1c3f47fcfd453 100644 --- a/drivers/platform/x86/dell/dcdbas.c +++ b/drivers/platform/x86/dell/dcdbas.c @@ -163,7 +163,7 @@ static ssize_t smi_data_buf_size_store(struct device *dev, } static ssize_t smi_data_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { ssize_t ret; @@ -176,7 +176,7 @@ static ssize_t smi_data_read(struct file *filp, struct kobject *kobj, } static ssize_t smi_data_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { ssize_t ret; @@ -636,9 +636,9 @@ static struct notifier_block dcdbas_reboot_nb = { .priority = INT_MIN }; -static DCDBAS_BIN_ATTR_RW(smi_data); +static const BIN_ATTR_ADMIN_RW(smi_data, 0); -static struct bin_attribute *dcdbas_bin_attrs[] = { +static const struct bin_attribute *const dcdbas_bin_attrs[] = { &bin_attr_smi_data, NULL }; @@ -662,7 +662,7 @@ static struct attribute *dcdbas_dev_attrs[] = { static const struct attribute_group dcdbas_attr_group = { .attrs = dcdbas_dev_attrs, - .bin_attrs = dcdbas_bin_attrs, + .bin_attrs_new = dcdbas_bin_attrs, }; static int dcdbas_probe(struct platform_device *dev) diff --git a/drivers/platform/x86/dell/dcdbas.h b/drivers/platform/x86/dell/dcdbas.h index 942a23ddded0592d2279da2dfee05113e8f4dbff..a05d7f667586310e379e38601309acdfad25645a 100644 --- a/drivers/platform/x86/dell/dcdbas.h +++ b/drivers/platform/x86/dell/dcdbas.h @@ -56,14 +56,6 @@ #define DCDBAS_DEV_ATTR_WO(_name) \ DEVICE_ATTR(_name,0200,NULL,_name##_store); -#define DCDBAS_BIN_ATTR_RW(_name) \ -struct bin_attribute bin_attr_##_name = { \ - .attr = { .name = __stringify(_name), \ - .mode = 0600 }, \ - .read = _name##_read, \ - .write = _name##_write, \ -} - struct smi_cmd { __u32 magic; __u32 ebx; From patchwork Mon Dec 2 19:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13891255 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EBF21DE3BC; Mon, 2 Dec 2024 19:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168321; cv=none; b=uU/z9btP3Q4Jx0mpCpx9sziWZAvMAlCw758hc98TlxlmZa/xDNFHxfRVZudVHPJ5aTNHx4sKVX0rX/dkyyMPwOXNiOmFRg9LHY1ghJ9yaFkdE76UWJrdsmuHsVaeBjYDvYfaKjpCZ4UYrvIeAPSDwxR0+4tzfOlY/BSrMEyo/Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168321; c=relaxed/simple; bh=YsbcgpRFOi+cY43e/Gwc75c9FlqZyz0+ZOwZ6DhkDSI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dX+UYtEymbuB0gMTXvpWp7fTWNaC5cm/qAItTTQvgM34YmgJj3Meofl3pYFzuquTnLTeuXWpRCKHSZ1TdwZpVns/yjOCA7nYu/envhFqulgZojiJc404p/WiH0S+uQgnLg7Hrr4Bq3/kjFFUlgW8pjhAl1pDshS4xRcSQEGBq9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=V3u6b9gg; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="V3u6b9gg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168316; bh=YsbcgpRFOi+cY43e/Gwc75c9FlqZyz0+ZOwZ6DhkDSI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V3u6b9ggz5UxbedruQ9U8mCgaUyqq/thMPo8C9kcwjSbkjjETaYTAnzNjeOpyMLz/ 126gqxxY3WhHelteRYnRz3sNzQUh1LFqLtCSIrDUlYi13CVXFcc/mec4FbkKI+PysA 9pIq22l2BfckIt5p29IxYKQi5rWzrqZA+gw/jAsI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:38:33 +0100 Subject: [PATCH 2/5] platform/x86: dell_rbu: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-pdx86-v1-2-9ab204c2a814@weissschuh.net> References: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> To: Stuart Hayes , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , Naveen Krishna Chatradhi , Carlos Bilbao Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733168316; l=3353; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=YsbcgpRFOi+cY43e/Gwc75c9FlqZyz0+ZOwZ6DhkDSI=; b=FzqPL1axoOZTDBRkK5+Wfehj/Z+2MZfHleJLbw9zuoeB4O4Jp3P2DWebZ0f4j0f3MFJvpsqtW oaIF99Yxm1aCBmsNsuvvP+8ESgB84DV2fweV3+t45OwkEBbN7+tuH5w X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/dell/dell_rbu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/dell/dell_rbu.c b/drivers/platform/x86/dell/dell_rbu.c index 9f51e0fcab04e1c61ce68b90b754b6b43a741b58..e30ca325938cb604560a810e7d63f65b4b70964b 100644 --- a/drivers/platform/x86/dell/dell_rbu.c +++ b/drivers/platform/x86/dell/dell_rbu.c @@ -475,7 +475,7 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count) } static ssize_t data_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { ssize_t ret_count = 0; @@ -492,7 +492,7 @@ static ssize_t data_read(struct file *filp, struct kobject *kobj, spin_unlock(&rbu_data.lock); return ret_count; } -static BIN_ATTR_RO(data, 0); +static const BIN_ATTR_RO(data, 0); static void callbackfn_rbu(const struct firmware *fw, void *context) { @@ -530,7 +530,7 @@ static void callbackfn_rbu(const struct firmware *fw, void *context) } static ssize_t image_type_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { int size = 0; @@ -540,7 +540,7 @@ static ssize_t image_type_read(struct file *filp, struct kobject *kobj, } static ssize_t image_type_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { int rc = count; @@ -597,10 +597,10 @@ static ssize_t image_type_write(struct file *filp, struct kobject *kobj, return rc; } -static BIN_ATTR_RW(image_type, 0); +static const BIN_ATTR_RW(image_type, 0); static ssize_t packet_size_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { int size = 0; @@ -613,7 +613,7 @@ static ssize_t packet_size_read(struct file *filp, struct kobject *kobj, } static ssize_t packet_size_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { unsigned long temp; @@ -626,9 +626,9 @@ static ssize_t packet_size_write(struct file *filp, struct kobject *kobj, spin_unlock(&rbu_data.lock); return count; } -static BIN_ATTR_RW(packet_size, 0); +static const BIN_ATTR_RW(packet_size, 0); -static struct bin_attribute *rbu_bin_attrs[] = { +static const struct bin_attribute *const rbu_bin_attrs[] = { &bin_attr_data, &bin_attr_image_type, &bin_attr_packet_size, @@ -636,7 +636,7 @@ static struct bin_attribute *rbu_bin_attrs[] = { }; static const struct attribute_group rbu_group = { - .bin_attrs = rbu_bin_attrs, + .bin_attrs_new = rbu_bin_attrs, }; static int __init dcdrbu_init(void) From patchwork Mon Dec 2 19:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13891253 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B49B51DE3C1; Mon, 2 Dec 2024 19:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168320; cv=none; b=r+yTAbWi1HMHSV+UbIDMcE0ePxr/Qy7iDg3P4FvHExMOIbMU/EXPci29WOue8I9R470bTDD2lU0I9l9zpOhMghUVSBonvkvdzgtLpuE8XvNhNzlrVGGRZLN1MLsU3s+5naBnfXYEzOGtsBpClQcD/dLoN/hHLYo9eL/65XOC7Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168320; c=relaxed/simple; bh=9BROW2GIlm3pIefGAozPxLR1ebj2V3j4iYVTr6HjxPg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k4HGgYdIO41Pyuj0bhvCkPxTeiCNd3o80CxDxBP7SDg7JAdRVt9oM9AXx5JPf6ObSOGqSHj6+S+ZmMQSFkLf+k37av+z0WkN/PZoDmeC1hAooPyJOuZmPFTFZ2x7H4ssOyZcDyZuiyxiBnab6I82Kl+c2wi29AHVUvRfD/YBB6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=DuZ6F0XQ; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="DuZ6F0XQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168316; bh=9BROW2GIlm3pIefGAozPxLR1ebj2V3j4iYVTr6HjxPg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DuZ6F0XQnTj4nCyp6QYk7tEm+WMEQVK1J4WxfEJAPwPk/ZDmZLaLqhgA+FLbit0nI Ivr+wjrWnUeAfTHMXE3rQycgRhdso0g1CJNwyzXUKBgO0fITZFtkxCtGbEExWWh1fw FlXdQfBzSCv43e+9CMpkm4+KWAztPrKizi1C4CG8= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:38:34 +0100 Subject: [PATCH 3/5] platform/x86/intel/sdsi: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-pdx86-v1-3-9ab204c2a814@weissschuh.net> References: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> To: Stuart Hayes , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , Naveen Krishna Chatradhi , Carlos Bilbao Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733168316; l=5102; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=9BROW2GIlm3pIefGAozPxLR1ebj2V3j4iYVTr6HjxPg=; b=LR3P52TCXRc1e6dFbve1Qi3MwTQzBmJ1YS3VaXvsR6vIig1lGRDMaOwdhOyDVz2VJAj6Lm/oQ PHijPHrojXNAxuMSgp2lYaafaLdy9v/v6ZD46utdAJMlMqDGepzwBTS X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/intel/sdsi.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c index 33f33b1070fdc949c1373251c3bca4234d9da119..30d1c2caf9842dbc355e7dea19f6446c56421228 100644 --- a/drivers/platform/x86/intel/sdsi.c +++ b/drivers/platform/x86/intel/sdsi.c @@ -398,8 +398,8 @@ static ssize_t sdsi_provision(struct sdsi_priv *priv, char *buf, size_t count, } static ssize_t provision_akc_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, - size_t count) + const struct bin_attribute *attr, char *buf, + loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); struct sdsi_priv *priv = dev_get_drvdata(dev); @@ -409,11 +409,11 @@ static ssize_t provision_akc_write(struct file *filp, struct kobject *kobj, return sdsi_provision(priv, buf, count, SDSI_CMD_PROVISION_AKC); } -static BIN_ATTR_WO(provision_akc, SDSI_SIZE_WRITE_MSG); +static const BIN_ATTR_WO(provision_akc, SDSI_SIZE_WRITE_MSG); static ssize_t provision_cap_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, - size_t count) + const struct bin_attribute *attr, char *buf, + loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); struct sdsi_priv *priv = dev_get_drvdata(dev); @@ -423,7 +423,7 @@ static ssize_t provision_cap_write(struct file *filp, struct kobject *kobj, return sdsi_provision(priv, buf, count, SDSI_CMD_PROVISION_CAP); } -static BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG); +static const BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG); static ssize_t certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv, @@ -469,7 +469,7 @@ certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv, static ssize_t state_certificate_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -477,11 +477,11 @@ state_certificate_read(struct file *filp, struct kobject *kobj, return certificate_read(SDSI_CMD_READ_STATE, 0, priv, buf, off, count); } -static BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG); +static const BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG); static ssize_t meter_certificate_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -489,11 +489,11 @@ meter_certificate_read(struct file *filp, struct kobject *kobj, return certificate_read(SDSI_CMD_READ_METER, 0, priv, buf, off, count); } -static BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG); +static const BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG); static ssize_t meter_current_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -502,11 +502,11 @@ meter_current_read(struct file *filp, struct kobject *kobj, return certificate_read(SDSI_CMD_READ_METER, CTRL_METER_ENABLE_DRAM, priv, buf, off, count); } -static BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG); +static const BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG); static ssize_t registers_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, - size_t count) + const struct bin_attribute *attr, char *buf, + loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); struct sdsi_priv *priv = dev_get_drvdata(dev); @@ -528,9 +528,9 @@ static ssize_t registers_read(struct file *filp, struct kobject *kobj, return count; } -static BIN_ATTR_ADMIN_RO(registers, SDSI_SIZE_REGS); +static const BIN_ATTR_ADMIN_RO(registers, SDSI_SIZE_REGS); -static struct bin_attribute *sdsi_bin_attrs[] = { +static const struct bin_attribute *const sdsi_bin_attrs[] = { &bin_attr_registers, &bin_attr_state_certificate, &bin_attr_meter_certificate, @@ -576,7 +576,7 @@ static struct attribute *sdsi_attrs[] = { static const struct attribute_group sdsi_group = { .attrs = sdsi_attrs, - .bin_attrs = sdsi_bin_attrs, + .bin_attrs_new = sdsi_bin_attrs, .is_bin_visible = sdsi_battr_is_visible, }; __ATTRIBUTE_GROUPS(sdsi); From patchwork Mon Dec 2 19:38:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13891254 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DE2C1DE4F0; Mon, 2 Dec 2024 19:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168321; cv=none; b=l7WE8vHzNZpF1oZ2m6dh0HQTGVtK7C3k/geFoniZ2G4iO3Qm7be+MuWCwlw6x8w1MieNDuI07y9Zi/Y/PtqZiiduUynHe40jME3uHGrRp2rIKSHluJSleFv4fi8lJiwWgXp1bqEiIG/VDYhh7Si+VXPorJPGIWdqqyUno4VpEfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168321; c=relaxed/simple; bh=dEUF5TC8DT2o+cQgIrRqLsxV/N2WvbGPEHszONyH3nU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kvYqYj2tmSa5xW+yZU4ZLsbxyS0zzkeWlqNgSZWkIoXH1ztVL+yvCwsNxbNJBjYeFYUn8+DIJ06st0A+7HvRwrIJ+Vh2uWuIOYGy2VnoPTSknNsDaXWvTUB4lmITUtvAUiUdAvT8E4cKXj9MIaf964VOoFZhIuQLusfZWPgiUTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=boOmRcJJ; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="boOmRcJJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168316; bh=dEUF5TC8DT2o+cQgIrRqLsxV/N2WvbGPEHszONyH3nU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=boOmRcJJNsSPppwl0cLoImXEfMsaUbNdaBPo+Kv12OxLmrtIYTfr2miYsPmdH7qYZ ZVk/tZdjWrL6s46+sgX10nZUzL6HnlOjtr7zfLyEw9pMmsv//MK0qavMg9QBWoZ8oE UCFGrwvQd2/dDB67ddxVfeKJ1dKkBBnSJs7baHoE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:38:35 +0100 Subject: [PATCH 4/5] platform/x86/intel/pmt: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-pdx86-v1-4-9ab204c2a814@weissschuh.net> References: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> To: Stuart Hayes , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , Naveen Krishna Chatradhi , Carlos Bilbao Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733168316; l=1434; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=dEUF5TC8DT2o+cQgIrRqLsxV/N2WvbGPEHszONyH3nU=; b=Ne4kYuRK7C3shiK6WjdCksksuRbZxHLWk2odkJkpBxlmn0ISdTSZY7frOFiqw34ebdLXj8Y7q 7zm7twrW957CMj+4sMfCl4308tRucp4Ubz1/lOctHbgylxooO8N73TU X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh --- drivers/platform/x86/intel/pmt/class.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c index 3c53cab033277bccc981310389f7dc47737825f4..65f26267ff49c39e3e143fa7eedb8df23d3ddc1d 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -81,7 +81,7 @@ EXPORT_SYMBOL_NS_GPL(pmt_telem_read_mmio, INTEL_PMT); */ static ssize_t intel_pmt_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct intel_pmt_entry *entry = container_of(attr, @@ -308,7 +308,7 @@ static int intel_pmt_dev_register(struct intel_pmt_entry *entry, entry->pmt_bin_attr.attr.name = ns->name; entry->pmt_bin_attr.attr.mode = 0440; entry->pmt_bin_attr.mmap = intel_pmt_mmap; - entry->pmt_bin_attr.read = intel_pmt_read; + entry->pmt_bin_attr.read_new = intel_pmt_read; entry->pmt_bin_attr.size = entry->size; ret = sysfs_create_bin_file(&dev->kobj, &entry->pmt_bin_attr); From patchwork Mon Dec 2 19:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13891257 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA7991DED73; Mon, 2 Dec 2024 19:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168324; cv=none; b=HuGqiIPUXRDBAMvUzMklCFWhdERPnRvRq/ygLp3GOCWf9t2dmfQrlfMl+bLiCYx5dFi4E63GKExlOz+7F2HhCMfZshJOoNrOaAwrBSeb8VrFu9MBX6fL8u7q/PS6Ed4XkGlvl89ORci1vnnNLzraQbHwbnJiLCmuVFLzv6DCU5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168324; c=relaxed/simple; bh=0vcuNhLRTgSihR2euTqOu3GUXYlgxvTzCrcLW+vJNFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xx3p+NlCa1aQM9E2YTU3ZtxY5+Wp6KCZ+ekLOilWs5jluq/Ozqpo/wNQ7fS2DZTtqEx9mG1b8Hw/SMb0uxRr8+N93f2SyZA5cDui9X3AS6QnEUG6nA+r2xfPTRwdw454ZR0lUPiRaiHY9FScR5fqAWUzRDNWBZfwJTFp7ShWw6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=ZM0A6z8z; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ZM0A6z8z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168317; bh=0vcuNhLRTgSihR2euTqOu3GUXYlgxvTzCrcLW+vJNFw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZM0A6z8zO3RMN0gIzDol8W2IO1RkNu3+aniBFzSvsdlBUqP92/Ch1vEOY38IV5gXA rkJvE8eJb/1dXWUMlWQofq+zd89+Z7I6VGHMV3qBQpEAsgUKLaKrKKziqPrid103Va 7ECLimINi+1cDFZLXqGn5xIkC3vPsHvdmdsWxFLA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:38:36 +0100 Subject: [PATCH 5/5] platform/x86/amd/hsmp: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-pdx86-v1-5-9ab204c2a814@weissschuh.net> References: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-pdx86-v1-0-9ab204c2a814@weissschuh.net> To: Stuart Hayes , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , Naveen Krishna Chatradhi , Carlos Bilbao Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733168316; l=3637; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=0vcuNhLRTgSihR2euTqOu3GUXYlgxvTzCrcLW+vJNFw=; b=aj5Sq7rt8w+1KN2yvaOHBP2H/fvqSILVCbbuG2+cF6IQtooZBHuxMIw3F4l0RXKZZNO1VP/kP pTR3002AdPCCkZjpUp4Lu4p3LVGS9u4FE8nA8s6EDErtPFd2FdQuo++ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh Acked-by: Naveen Krishna Chatradhi --- drivers/platform/x86/amd/hsmp/acpi.c | 12 ++++++------ drivers/platform/x86/amd/hsmp/plat.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c index dd5b5773328a9aff376a389cbd0109cb8cf0e385..7d802bfe206c73a4570dcd3752faee853bb81485 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -226,7 +226,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind) } static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); @@ -285,19 +285,19 @@ static int init_acpi(struct device *dev) return ret; } -static struct bin_attribute hsmp_metric_tbl_attr = { +static const struct bin_attribute hsmp_metric_tbl_attr = { .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444}, - .read = hsmp_metric_tbl_acpi_read, + .read_new = hsmp_metric_tbl_acpi_read, .size = sizeof(struct hsmp_metric_table), }; -static struct bin_attribute *hsmp_attr_list[] = { +static const struct bin_attribute *hsmp_attr_list[] = { &hsmp_metric_tbl_attr, NULL }; -static struct attribute_group hsmp_attr_grp = { - .bin_attrs = hsmp_attr_list, +static const struct attribute_group hsmp_attr_grp = { + .bin_attrs_new = hsmp_attr_list, .is_bin_visible = hsmp_is_sock_attr_visible, }; diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c index 748bbc35648474370275a80daf2c26e5d732f6ad..1fdcd65d398e6ceca154b804074cbba083f4b7f1 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -59,7 +59,7 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset, } static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct hsmp_socket *sock; @@ -97,13 +97,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, * is_bin_visible function is used to show / hide the necessary groups. */ #define HSMP_BIN_ATTR(index, _list) \ -static struct bin_attribute attr##index = { \ +static const struct bin_attribute attr##index = { \ .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444}, \ .private = (void *)index, \ - .read = hsmp_metric_tbl_plat_read, \ + .read_new = hsmp_metric_tbl_plat_read, \ .size = sizeof(struct hsmp_metric_table), \ }; \ -static struct bin_attribute _list[] = { \ +static const struct bin_attribute _list[] = { \ &attr##index, \ NULL \ } @@ -118,8 +118,8 @@ HSMP_BIN_ATTR(6, *sock6_attr_list); HSMP_BIN_ATTR(7, *sock7_attr_list); #define HSMP_BIN_ATTR_GRP(index, _list, _name) \ -static struct attribute_group sock##index##_attr_grp = { \ - .bin_attrs = _list, \ +static const struct attribute_group sock##index##_attr_grp = { \ + .bin_attrs_new = _list, \ .is_bin_visible = hsmp_is_sock_attr_visible, \ .name = #_name, \ }