From patchwork Mon Dec 16 11:29:08 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: 13909588 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 AFE66204C16; Mon, 16 Dec 2024 11:29:19 +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=1734348561; cv=none; b=McDFhcwLtgbUBbRMSQtvosHyQwetWUuwAYr/yOKXGfbI64JH0Op/11yaXmE6v9l+M/iH5uce9R8bIxb7E+v1Eg4mvXXirD0UrRST15nXP9BlgHKYpBhlAoDVB5IIFPVlT9rnM4A+SVj+JGVRz8AjILN6hSXnT+XxMw9XZR15VQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348561; c=relaxed/simple; bh=WaboRMSctLDNjMoiMP+WBKKWL22udYHg4PafZfmH3dE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aWU9NuP+SdCc6XES0AXn+YiDtpQpNBeMQGGXhawLOuwEYYCiTEis1rZSkrN9Cglf7XCKNp1HmtjS2mDj0i5Xcn0arTWm7zbdPG/usReQhS3qtgmX2mj/U180xrXx++KqQDKwXxfgG7HnNQpiwqK39JjAqIJqJvVlDzmoNF4h+Wo= 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=sN8K+/xC; 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="sN8K+/xC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348552; bh=WaboRMSctLDNjMoiMP+WBKKWL22udYHg4PafZfmH3dE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sN8K+/xCJ4sZCX8bmX7GVrAxYuOUqAJ6Kee5HVCDqDGMRkmSLuPh/Y6mYGSyXE0HG 99ljPEsa8JLb0GraBEi7Y0z46TqX2N5p5HP5IYyCVk53yWaeB9hqS5MQH/bqkzRJQg NY4lfT52/XIEK7EZzNjDbZBnu/AE2ELBiJDhOqxg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:08 +0100 Subject: [PATCH 01/11] scsi: core: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-1-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2829; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WaboRMSctLDNjMoiMP+WBKKWL22udYHg4PafZfmH3dE=; b=K189QbdH2CaN3ics6UBI9t1/D7hlarXbzYbn3lOIMhyJEb/UWOgCYM88r+iNuEVwcc/2FVc7b pEUwUoHctEGBLGTLnpDHiQ1gf4nRfSgOtBYhF1LFc6MprRLxTDq93bB 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/scsi/scsi_sysfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index f3a1ecb42128a2b221ca5c362e041eb59dba0f20..6ad859a4ec08f5a6773bb84bf899201eed1f468f 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -898,7 +898,7 @@ static DEVICE_ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field, #define sdev_vpd_pg_attr(_page) \ static ssize_t \ show_vpd_##_page(struct file *filp, struct kobject *kobj, \ - struct bin_attribute *bin_attr, \ + const struct bin_attribute *bin_attr, \ char *buf, loff_t off, size_t count) \ { \ struct device *dev = kobj_to_dev(kobj); \ @@ -914,10 +914,10 @@ show_vpd_##_page(struct file *filp, struct kobject *kobj, \ rcu_read_unlock(); \ return ret; \ } \ -static struct bin_attribute dev_attr_vpd_##_page = { \ +static const struct bin_attribute dev_attr_vpd_##_page = { \ .attr = {.name = __stringify(vpd_##_page), .mode = S_IRUGO }, \ .size = 0, \ - .read = show_vpd_##_page, \ + .read_new = show_vpd_##_page, \ }; sdev_vpd_pg_attr(pg83); @@ -930,7 +930,7 @@ sdev_vpd_pg_attr(pgb7); sdev_vpd_pg_attr(pg0); static ssize_t show_inquiry(struct file *filep, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -943,13 +943,13 @@ static ssize_t show_inquiry(struct file *filep, struct kobject *kobj, sdev->inquiry_len); } -static struct bin_attribute dev_attr_inquiry = { +static const struct bin_attribute dev_attr_inquiry = { .attr = { .name = "inquiry", .mode = S_IRUGO, }, .size = 0, - .read = show_inquiry, + .read_new = show_inquiry, }; static ssize_t @@ -1348,7 +1348,7 @@ static struct attribute *scsi_sdev_attrs[] = { NULL }; -static struct bin_attribute *scsi_sdev_bin_attrs[] = { +static const struct bin_attribute *const scsi_sdev_bin_attrs[] = { &dev_attr_vpd_pg0, &dev_attr_vpd_pg83, &dev_attr_vpd_pg80, @@ -1362,7 +1362,7 @@ static struct bin_attribute *scsi_sdev_bin_attrs[] = { }; static struct attribute_group scsi_sdev_attr_group = { .attrs = scsi_sdev_attrs, - .bin_attrs = scsi_sdev_bin_attrs, + .bin_attrs_new = scsi_sdev_bin_attrs, .is_visible = scsi_sdev_attr_is_visible, .is_bin_visible = scsi_sdev_bin_attr_is_visible, }; From patchwork Mon Dec 16 11:29:09 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: 13909587 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 AFE08204C15; Mon, 16 Dec 2024 11:29:19 +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=1734348561; cv=none; b=mslTR6oRSvbhsOuqwCx3Xm99xXAY7FLY0XLpROuIPSfRy3knchxfVCONj5uyWWO0cZKALy90uNm2zx0MFGZv8yXg4oJUQgSVrGQ+Rnp1WkmGlW6x5z3bgatiWrDgf+pbSTHwODdouMiiYi+KcPYlD/anokFjTwTfNB69VozTh6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348561; c=relaxed/simple; bh=oitZ6tqthOyv84s9N34Rb9nzMVcAd+9eCJs7DMuMPZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sj0J8+/dj6QKxzkE2B5AW+Z621o+MHNE7CBD8NDUp8FF/Xh9TIMyToind1NissIjiWINAlfaVECIwnn0ogfMY3yzROmV6dskv/LsxeF64LR5uunZOtu0AOwgM5i+cdNjQpmLFDhdeydVb+0+tGv2E9zfTnElDEoWm8j5E8/x2j0= 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=Q1eyXdHb; 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="Q1eyXdHb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348552; bh=oitZ6tqthOyv84s9N34Rb9nzMVcAd+9eCJs7DMuMPZg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Q1eyXdHbyag9KhzRNNgo9E8H9QL8KBm0VJ3bBuTYmu/Q8ID2LdEs7F82M+oAGmL0f hFS3ewEZkIiO22+WG30C4OWIEuIknRZphCNvM1N8nsB04lCaZxqliKvhBLxrIsnnGK yEdF8dh4FKu2rUj1XByTCI+l4AHJ0pzX80nSFnSk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:09 +0100 Subject: [PATCH 02/11] scsi: 3w-sas: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-2-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2354; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=oitZ6tqthOyv84s9N34Rb9nzMVcAd+9eCJs7DMuMPZg=; b=sacDHXbh5wtVuj4CIy4c8lPoMwYfRqbvW7o53sDn3Rl8gYBj1PngcDtMJ7orcye3Msm+5Yd3Y i5icvP0is0qAVyMZ0QA3a+yvatFzrL5ioZHW6iyicE3OkmniylWhmUR 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/scsi/3w-sas.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c index caa6713a62a44a72c7cfa5128c01fe54788cf708..6b2b02f89490aeb0494f3b586c9df995ec05a158 100644 --- a/drivers/scsi/3w-sas.c +++ b/drivers/scsi/3w-sas.c @@ -96,7 +96,7 @@ static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_res /* This function returns AENs through sysfs */ static ssize_t twl_sysfs_aen_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *outbuf, loff_t offset, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); @@ -116,18 +116,18 @@ static ssize_t twl_sysfs_aen_read(struct file *filp, struct kobject *kobj, } /* End twl_sysfs_aen_read() */ /* aen_read sysfs attribute initializer */ -static struct bin_attribute twl_sysfs_aen_read_attr = { +static const struct bin_attribute twl_sysfs_aen_read_attr = { .attr = { .name = "3ware_aen_read", .mode = S_IRUSR, }, .size = 0, - .read = twl_sysfs_aen_read + .read_new = twl_sysfs_aen_read }; /* This function returns driver compatibility info through sysfs */ static ssize_t twl_sysfs_compat_info(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *outbuf, loff_t offset, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); @@ -147,13 +147,13 @@ static ssize_t twl_sysfs_compat_info(struct file *filp, struct kobject *kobj, } /* End twl_sysfs_compat_info() */ /* compat_info sysfs attribute initializer */ -static struct bin_attribute twl_sysfs_compat_info_attr = { +static const struct bin_attribute twl_sysfs_compat_info_attr = { .attr = { .name = "3ware_compat_info", .mode = S_IRUSR, }, .size = 0, - .read = twl_sysfs_compat_info + .read_new = twl_sysfs_compat_info }; /* Show some statistics about the card */ From patchwork Mon Dec 16 11:29:10 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: 13909586 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 949D4203D79; Mon, 16 Dec 2024 11:29:15 +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=1734348559; cv=none; b=EuhQW2Z2S3Mz91scKRnvKjifpDIW3z8z4Zf0/GUgxuTPY6NG6mJqu4kHDK9uj4Z8TDIgcJAc6+043YYlnSGxHYFf/YTTm+5ekebDNM3Qw2Ts4aSq25Wbln0aUj1NP6sDIpGMDmK3b2y9JIoDsK8pRakCzskm+f8a7BMxhffA5Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348559; c=relaxed/simple; bh=UxSxwL/qK4i4u8NjbrtHnSuDQ3zqF0XhxRjgbnp1ehs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pqLIxYVKiWKjDf/bCBwCagCAndhQvj9OC/RnUa68AEfD9O+V3SGcickQ1HU3PvBX5NmSInZuyqkweKUl/1tpEaJOIf7EQGJrT3mtcyPAplTyNawqRvKqb0FacDKpr7GIJSNPxOkgm36BEP9rP2BTK5lI9m7hGocSRntqd2lTb/c= 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=FQQrBHSu; 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="FQQrBHSu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348552; bh=UxSxwL/qK4i4u8NjbrtHnSuDQ3zqF0XhxRjgbnp1ehs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FQQrBHSuc72gKSix1QVSuur4IgSvsKGMsC93Gbmx0fPteAd57elXpFWksPYL3Wuul CtzDCAFfce5XoAN+wFusEAxuZ++WObbQDSu3h+vAgjVa2dsRO2udFjZNmvFleRSHic xlszaq5LqCMZmwjIwwXu0S/L1pscFPyLclE8Fkcw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:10 +0100 Subject: [PATCH 03/11] scsi: arcmsr: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-3-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2527; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=UxSxwL/qK4i4u8NjbrtHnSuDQ3zqF0XhxRjgbnp1ehs=; b=vcyhEJcSeUIpb/s74+rAXfMuCTEu+PgS5tfd520cNRubmtpMJ+lqdXmNUTpuW64jf2eM5p4hu EXGDhImAe/bCfxvGEXm5GK3GNZZPH02XxoEI1YUiBIbmgO1caKNY1v5 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/scsi/arcmsr/arcmsr_attr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c index baeb5e79569026f1af6612705689219bb4a7052f..8e3d4799ce93c35b0befe8744fd20aa3fe467ad3 100644 --- a/drivers/scsi/arcmsr/arcmsr_attr.c +++ b/drivers/scsi/arcmsr/arcmsr_attr.c @@ -60,7 +60,7 @@ static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin, + const struct bin_attribute *bin, char *buf, loff_t off, size_t count) { @@ -107,7 +107,7 @@ static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp, static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin, + const struct bin_attribute *bin, char *buf, loff_t off, size_t count) { @@ -155,7 +155,7 @@ static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp, static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin, + const struct bin_attribute *bin, char *buf, loff_t off, size_t count) { @@ -194,7 +194,7 @@ static const struct bin_attribute arcmsr_sysfs_message_read_attr = { .mode = S_IRUSR , }, .size = ARCMSR_API_DATA_BUFLEN, - .read = arcmsr_sysfs_iop_message_read, + .read_new = arcmsr_sysfs_iop_message_read, }; static const struct bin_attribute arcmsr_sysfs_message_write_attr = { @@ -203,7 +203,7 @@ static const struct bin_attribute arcmsr_sysfs_message_write_attr = { .mode = S_IWUSR, }, .size = ARCMSR_API_DATA_BUFLEN, - .write = arcmsr_sysfs_iop_message_write, + .write_new = arcmsr_sysfs_iop_message_write, }; static const struct bin_attribute arcmsr_sysfs_message_clear_attr = { @@ -212,7 +212,7 @@ static const struct bin_attribute arcmsr_sysfs_message_clear_attr = { .mode = S_IWUSR, }, .size = 1, - .write = arcmsr_sysfs_iop_message_clear, + .write_new = arcmsr_sysfs_iop_message_clear, }; int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb) From patchwork Mon Dec 16 11:29:11 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: 13909583 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 2DD1E4C7C; Mon, 16 Dec 2024 11:29:14 +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=1734348558; cv=none; b=BXrk6iODnZYc6ulWxvMeZ7tw27ooJumoXJ7nXESs5UJvroWO17hS3nRbeuMoNulEfLgCzshe49ex/CvJJK68go3/jobW+aE5b2+Q7LCGsn8rKAkK88j+Rk/QnvhxYAKmmUuDfXC4hiHPKz2IuynqVf/30XXApXgfzKzWdhhaLVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348558; c=relaxed/simple; bh=TjVja/zk+UJSLd4Q97XnJXAzbXafaV96VJJ2y2xcgm4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ilZL0IrMyIU1yJ0bUUz7cjDTa000/Ekru/hZV8yaBK2N+YXIscmX/CspApyYOS/GIYZaqIhuIgzMrVWUw2bngGD/CzWWvnaAR48KF3Q8rPigM1OYLEXaZ4FkQ4VbtMCXnMKjO0Slt0QbzXSkU+mpKSxBi7OjlGn3QVXwjFP9qy0= 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=smBWsnEG; 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="smBWsnEG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348552; bh=TjVja/zk+UJSLd4Q97XnJXAzbXafaV96VJJ2y2xcgm4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=smBWsnEGDX0bZ10U/9wLxtIv2PGJ5U4XBMe94YkqdZF6ukWU83aG4wJzucfAP2k8P YBRJMCxE9jiZ/Rrj9akKDg1C4jyus9A4sJaJL8S8em1xWjoKlmkWTA+NOeQ4fli+s+ NzNipJv6XG8USBabiBG904lzidmMQVDwCXIO2c/c= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:11 +0100 Subject: [PATCH 04/11] scsi: esas2r: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-4-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=6468; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=TjVja/zk+UJSLd4Q97XnJXAzbXafaV96VJJ2y2xcgm4=; b=cHpzmCZLeQqd1OQ9m+VjdHMlnbORVFZql4Wpf6q2sfJdTUE0nTJzea+z2TUT+o90QQnQ3pVcM 1Qkron+E+zwDaDCjDL5AgAFL69ATj+ts8h3Zvs/T8Ma3pN/j1evnvnD 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/scsi/esas2r/esas2r.h | 12 ++++++------ drivers/scsi/esas2r/esas2r_main.c | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h index 1e2d7c63a8e36a22bed3b365cd2e6eb81a3a4a1d..c48275d53aef3d45c0b8a1c38f5a21020ab33102 100644 --- a/drivers/scsi/esas2r/esas2r.h +++ b/drivers/scsi/esas2r/esas2r.h @@ -1411,11 +1411,11 @@ static inline void esas2r_comp_list_drain(struct esas2r_adapter *a, } /* sysfs handlers */ -extern struct bin_attribute bin_attr_fw; -extern struct bin_attribute bin_attr_fs; -extern struct bin_attribute bin_attr_vda; -extern struct bin_attribute bin_attr_hw; -extern struct bin_attribute bin_attr_live_nvram; -extern struct bin_attribute bin_attr_default_nvram; +extern const struct bin_attribute bin_attr_fw; +extern const struct bin_attribute bin_attr_fs; +extern const struct bin_attribute bin_attr_vda; +extern const struct bin_attribute bin_attr_hw; +extern const struct bin_attribute bin_attr_live_nvram; +extern const struct bin_attribute bin_attr_default_nvram; #endif /* ESAS2R_H */ diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c index f700a16cd88534c1edc9fb0ed8ed8b8d1db4fe51..44871746944ad0c0f30f28975ed40e0fde4e8d03 100644 --- a/drivers/scsi/esas2r/esas2r_main.c +++ b/drivers/scsi/esas2r/esas2r_main.c @@ -66,7 +66,7 @@ static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj) } static ssize_t read_fw(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -75,7 +75,7 @@ static ssize_t read_fw(struct file *file, struct kobject *kobj, } static ssize_t write_fw(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -84,7 +84,7 @@ static ssize_t write_fw(struct file *file, struct kobject *kobj, } static ssize_t read_fs(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -93,7 +93,7 @@ static ssize_t read_fs(struct file *file, struct kobject *kobj, } static ssize_t write_fs(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -109,7 +109,7 @@ static ssize_t write_fs(struct file *file, struct kobject *kobj, } static ssize_t read_vda(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -118,7 +118,7 @@ static ssize_t read_vda(struct file *file, struct kobject *kobj, } static ssize_t write_vda(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -127,7 +127,7 @@ static ssize_t write_vda(struct file *file, struct kobject *kobj, } static ssize_t read_live_nvram(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -138,7 +138,7 @@ static ssize_t read_live_nvram(struct file *file, struct kobject *kobj, } static ssize_t write_live_nvram(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -158,7 +158,7 @@ static ssize_t write_live_nvram(struct file *file, struct kobject *kobj, } static ssize_t read_default_nvram(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -169,7 +169,7 @@ static ssize_t read_default_nvram(struct file *file, struct kobject *kobj, } static ssize_t read_hw(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -187,7 +187,7 @@ static ssize_t read_hw(struct file *file, struct kobject *kobj, } static ssize_t write_hw(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj); @@ -211,12 +211,12 @@ static ssize_t write_hw(struct file *file, struct kobject *kobj, } #define ESAS2R_RW_BIN_ATTR(_name) \ - struct bin_attribute bin_attr_ ## _name = { \ + const struct bin_attribute bin_attr_ ## _name = { \ .attr = \ { .name = __stringify(_name), .mode = S_IRUSR | S_IWUSR }, \ .size = 0, \ - .read = read_ ## _name, \ - .write = write_ ## _name } + .read_new = read_ ## _name, \ + .write_new = write_ ## _name } ESAS2R_RW_BIN_ATTR(fw); ESAS2R_RW_BIN_ATTR(fs); @@ -224,10 +224,10 @@ ESAS2R_RW_BIN_ATTR(vda); ESAS2R_RW_BIN_ATTR(hw); ESAS2R_RW_BIN_ATTR(live_nvram); -struct bin_attribute bin_attr_default_nvram = { +const struct bin_attribute bin_attr_default_nvram = { .attr = { .name = "default_nvram", .mode = S_IRUGO }, .size = 0, - .read = read_default_nvram, + .read_new = read_default_nvram, .write = NULL }; From patchwork Mon Dec 16 11:29:12 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: 13909592 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 5D974204F7A; Mon, 16 Dec 2024 11:29:20 +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=1734348562; cv=none; b=YneuaUmuA5ahxfFVTvN0r5nd7Z1DyYGIi/toXueL+vadicQLgw5LNdqdF+c7CiuhUHt2rYgOVhIVdlxw4lXJ0yp3FRwxp2xLNj7mLTzd7n99t3ngfSIS1/h9LW5dMfZ7R9shCUgxzldOySTRpqG6XVOqAGYf7B7HFQA/tQmJQig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348562; c=relaxed/simple; bh=qDXql5e0dlsoUkgnrUATod+FIdN2oCDJzygWUo2bAxI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uhw48A+cVdogrpE+1yrw55WJn0Bi/fNb0h6dgMFgDEeKVAPNAHHg3Zvwyny8L24wWX5lgqAw5ESZrYUTf2ELmHZgtBhST8t4PQLwd2JoNq67SIx2lrWsTly8EH3l9uBtOmyRwJs16C3t6dQzQo6Z6PovxpyfK54IwOA5UF8G5C8= 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=dZKEYZOu; 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="dZKEYZOu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348552; bh=qDXql5e0dlsoUkgnrUATod+FIdN2oCDJzygWUo2bAxI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dZKEYZOuYIHlGMQvecOcn2uix+tggU/FkxIxa3rtLJR1ytNHcWcz1br92ylyAydSN AaGg4z+b62l/Jnx9a7qEvnDagQ+5qgY9qf6W8AsuUNgYyCRQkCdx06aCL3kp1iUP93 j6hK6BCVF2OpA96b4jyQJflQWD6xbwe6Il2RcEQk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:12 +0100 Subject: [PATCH 05/11] scsi: ibmvfc: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-5-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=1371; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=qDXql5e0dlsoUkgnrUATod+FIdN2oCDJzygWUo2bAxI=; b=dDgz9Ydf6v4c6BI1Dnxg8otiPshJZaMRuHcfAE+qvBaHTOKVPItUmjE76IBIT2jLd/2Q0crxB eOz7VAZ6/uECvTk+TKC/HJAY59i1sBjxrZyaCFMfdE1+rcuzjW44oZJ 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/scsi/ibmvscsi/ibmvfc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c index e66c3ef74267a5527b21e6e1d13efb91425b158e..dc8401587bb529860d261ac83b924fceac8335d9 100644 --- a/drivers/scsi/ibmvscsi/ibmvfc.c +++ b/drivers/scsi/ibmvscsi/ibmvfc.c @@ -3639,7 +3639,7 @@ static DEVICE_ATTR(nr_scsi_channels, S_IRUGO | S_IWUSR, * number of bytes printed to buffer **/ static ssize_t ibmvfc_read_trace(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -3662,13 +3662,13 @@ static ssize_t ibmvfc_read_trace(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute ibmvfc_trace_attr = { +static const struct bin_attribute ibmvfc_trace_attr = { .attr = { .name = "trace", .mode = S_IRUGO, }, .size = 0, - .read = ibmvfc_read_trace, + .read_new = ibmvfc_read_trace, }; #endif From patchwork Mon Dec 16 11:29:13 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: 13909584 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 1BEEC2040BC; Mon, 16 Dec 2024 11:29:15 +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=1734348558; cv=none; b=oPalmBz5liwS3oIMJy2gaHK3NXhHKBRZ+eII6D6bXyQjCve1NHHQtItysKV39aZB2z3gAWIsjDSh1yxIkg4LVKU441/AjJex6XlSR/vzRVSQAwI4rEyFsVRr+9Q6mA/O0kM/muyhRzBjBW7qfcdHfQHS7aW+9H/OytEgPd0yfac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348558; c=relaxed/simple; bh=W+0Z4QVsEE43bUpRexFCykIgMN9iO9eLgbxKoLARbqk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hxSJhoY8Sx1wIWkE8s0ek+Q/OPe2uDbytmbYXECNZL3NoywdHMHs9nplLCFWsR0eopobDcI5dk3XC0i57P6TlixcMUJ4NHwedGzwUkGRFrbW9s7OHHWa8Sj1g7DiKnkXzdj0EbUqYLvzHSpb4kGYxz15pR06JCGBwVKKWRjRc10= 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=ix4b7inj; 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="ix4b7inj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=W+0Z4QVsEE43bUpRexFCykIgMN9iO9eLgbxKoLARbqk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ix4b7injg+/iY+ZOZh+5gU5wmZFvPs6gnTB9UQENKl3DystMTzeSMrmyVUfkqAqg/ gZ69Cq9X70sGKHjvMImWM+Nj/LUWX2W19kcSZedUxWupGBepLGik2YAcO8dx7QU+ly zQ8gb3MLOWd5WoYQf1/B4gj94nY1po/wDLkcIqpk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:13 +0100 Subject: [PATCH 06/11] scsi: lpfc: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-6-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2659; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=W+0Z4QVsEE43bUpRexFCykIgMN9iO9eLgbxKoLARbqk=; b=PvxT0Qpnkj49P3LHfPfXUCSjZE54BDHEBEjiOzke6/a3CdIzFNkyHoShGplVXsJePuSfUff3F dfoi0gw/LXlDRb6N4AsoA6trIQtSEUSLVm2LIqvPkYloF319CSfV2Bf 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/scsi/lpfc/lpfc_attr.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c index 39b504164ecc187d8b0798c95c9fa3f6bc9780e3..0d0213bba35da8e10be8b874763dd5f01d6ff586 100644 --- a/drivers/scsi/lpfc/lpfc_attr.c +++ b/drivers/scsi/lpfc/lpfc_attr.c @@ -6185,7 +6185,7 @@ const struct attribute_group *lpfc_vport_groups[] = { **/ static ssize_t sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { size_t buf_off; @@ -6244,7 +6244,7 @@ sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, **/ static ssize_t sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { size_t buf_off; @@ -6280,14 +6280,14 @@ sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_ctlreg_attr = { +static const struct bin_attribute sysfs_ctlreg_attr = { .attr = { .name = "ctlreg", .mode = S_IRUSR | S_IWUSR, }, .size = 256, - .read = sysfs_ctlreg_read, - .write = sysfs_ctlreg_write, + .read_new = sysfs_ctlreg_read, + .write_new = sysfs_ctlreg_write, }; /** @@ -6308,7 +6308,7 @@ static struct bin_attribute sysfs_ctlreg_attr = { **/ static ssize_t sysfs_mbox_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { return -EPERM; @@ -6332,20 +6332,20 @@ sysfs_mbox_write(struct file *filp, struct kobject *kobj, **/ static ssize_t sysfs_mbox_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { return -EPERM; } -static struct bin_attribute sysfs_mbox_attr = { +static const struct bin_attribute sysfs_mbox_attr = { .attr = { .name = "mbox", .mode = S_IRUSR | S_IWUSR, }, .size = MAILBOX_SYSFS_MAX, - .read = sysfs_mbox_read, - .write = sysfs_mbox_write, + .read_new = sysfs_mbox_read, + .write_new = sysfs_mbox_write, }; /** From patchwork Mon Dec 16 11:29:14 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: 13909585 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 77068204563; Mon, 16 Dec 2024 11:29:16 +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=1734348558; cv=none; b=aY/FQct6UISWz5Y9qSetNVAqGxjXKRi6+YO4p2KSm5OyI6Vo9W8FjGFDXPnNTajeq4iW+3C6hE5tUNZ8i+D+hQ4STGSvgAuxyIduOB0Nxm8DGeeDjpLMmYty1i3vRcPRgwBGq+D+4q0FetvcPYf5d37IgyeddJz5SJ6+q/84w1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348558; c=relaxed/simple; bh=J7r5Ti/saHXCrjrJTNrPH1+HHellTzKNGzEhEZF4B/8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HLxWvQ2E9E6P1bBF8GTfqc/KGQefBSgkLQ1DrCHEWnGMBXwRVR4C6EfS/GJlLC8xBw6S02YRyul3j0NvwIPTM2MyGUvCKVRq5yEGIiKUHGbYSlsTQKrv7ch5bn6PiZh64uRiw7ZNDFmnfZ+gg3mzrKhnrJcYG2S3mtXWiwwbPE0= 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=ezXrjNfZ; 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="ezXrjNfZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=J7r5Ti/saHXCrjrJTNrPH1+HHellTzKNGzEhEZF4B/8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ezXrjNfZeyrhOmlE3jk3YbSVQVNKRizh3lAJnus8DGuzlcE6RzSC9JrFiNokNSuSP wIBV4gL6Q45L788RVY2O7GqGFjFTWkITpIaVHI+0VmeSW7l5YPySAMxz2NJu2I7V4L p6DY+Vi09CFaP0/3fFBrYHt+c3R4Ts/EgUT22Lls= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:14 +0100 Subject: [PATCH 07/11] scsi: ipr: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-7-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=3842; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=J7r5Ti/saHXCrjrJTNrPH1+HHellTzKNGzEhEZF4B/8=; b=ikn/d3a4NvnzIoHDX3GVT/kqTj/u6jpmFIMnON6Q5cPNcZXzDO6bWCS+3GkoABkAbnZG8P+BJ LPuxqooaZ6uAHRElQg2VVKnnE/PybWFkgTefSC+utZqJHkMb2J4lr7F 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/scsi/ipr.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index 31cf2d31cceba090859c15f72f85fe7ca1698a55..db19888c5351a27d7560192339d2b9b533101e58 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -3366,7 +3366,7 @@ static void ipr_worker_thread(struct work_struct *work) * number of bytes printed to buffer **/ static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -3383,13 +3383,13 @@ static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj, return ret; } -static struct bin_attribute ipr_trace_attr = { +static const struct bin_attribute ipr_trace_attr = { .attr = { .name = "trace", .mode = S_IRUGO, }, .size = 0, - .read = ipr_read_trace, + .read_new = ipr_read_trace, }; #endif @@ -4087,7 +4087,7 @@ static struct device_attribute ipr_ioa_fw_type_attr = { }; static ssize_t ipr_read_async_err_log(struct file *filep, 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 *cdev = kobj_to_dev(kobj); @@ -4111,7 +4111,7 @@ static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj, } static ssize_t ipr_next_async_err_log(struct file *filep, 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 *cdev = kobj_to_dev(kobj); @@ -4134,14 +4134,14 @@ static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj, return count; } -static struct bin_attribute ipr_ioa_async_err_log = { +static const struct bin_attribute ipr_ioa_async_err_log = { .attr = { .name = "async_err_log", .mode = S_IRUGO | S_IWUSR, }, .size = 0, - .read = ipr_read_async_err_log, - .write = ipr_next_async_err_log + .read_new = ipr_read_async_err_log, + .write_new = ipr_next_async_err_log }; static struct attribute *ipr_ioa_attrs[] = { @@ -4172,7 +4172,7 @@ ATTRIBUTE_GROUPS(ipr_ioa); * number of bytes printed to buffer **/ static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *cdev = kobj_to_dev(kobj); @@ -4361,7 +4361,7 @@ static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) * number of bytes printed to buffer **/ static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *cdev = kobj_to_dev(kobj); @@ -4385,14 +4385,14 @@ static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute ipr_dump_attr = { +static const struct bin_attribute ipr_dump_attr = { .attr = { .name = "dump", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = ipr_read_dump, - .write = ipr_write_dump + .read_new = ipr_read_dump, + .write_new = ipr_write_dump }; #else static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; }; From patchwork Mon Dec 16 11:29:15 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: 13909590 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 590C3204F76; Mon, 16 Dec 2024 11:29:20 +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=1734348562; cv=none; b=u2+ZLrRvUqNSSx/4ru/UjDDkM5K2xPExKb5Fa+a1YJk8aBIpazrRam+r0p6DxoxrOZmQPJIhepLjULOx7HJqkd9iL/v79CbUFJuNn4sOIWP/X9+E3MLmXoJa4R61GGuxPWC2dJ85OuKOfx5J6vK0lGEUJ4YgovOcbeZ1KQQeAz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348562; c=relaxed/simple; bh=/47zmPkyqW64N/sWNZItQvBd6ybLPkBtNbUpLnt2Msc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T+HNRwPHCIQoWgjX4lIcBUNLUOPqMDKXldyDBo6MEe6TXYgG5MzX+rp4ezY1V2DMknyh4TOS2fHy0NHLTqeizy4/y9wQHnpEC5MQiO6AYvXagLTmvjc2nf5PyJ9dnOulKYb+aGCEi9DoKUUBTcJCQetja6Sg/O8c9nCEkThdzQM= 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=RMkcaJQt; 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="RMkcaJQt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=/47zmPkyqW64N/sWNZItQvBd6ybLPkBtNbUpLnt2Msc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RMkcaJQt8UBr77DelZNaePGGudtkBLDC/fceGR/DYNrQruoPmfGp4X4Ih/idasJ6J LiP0ReqpGtsDJ4ilq11ZC+OV9Cbpz725LuWbb6g46Hx+hov/ipO+zMCZVcF09Ux8PE lJ5Ghu3SIfOUoQJLq2aoT99RDZ4Fio79eyMt9grk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:15 +0100 Subject: [PATCH 08/11] scsi: qedf: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-8-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2312; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=/47zmPkyqW64N/sWNZItQvBd6ybLPkBtNbUpLnt2Msc=; b=yoemaf355a7pBtjrYmusgAHSgDSHBiZ/xpsxVOY2bN+lr7orgVWt0/padwJDXbBQS6h6g2A/v ZfCk5GBEeFnA/CuO6ERllqvp4wf56ggfq0HQFvV9/Vx9XlOgwrjVYfl 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/scsi/qedf/qedf_attr.c | 10 +++++----- drivers/scsi/qedf/qedf_dbg.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/qedf/qedf_attr.c b/drivers/scsi/qedf/qedf_attr.c index 8d8c760eee435ad9018e64440837211109725ff6..769da92ee20d0fac71525a8265cb6332146585ec 100644 --- a/drivers/scsi/qedf/qedf_attr.c +++ b/drivers/scsi/qedf/qedf_attr.c @@ -104,7 +104,7 @@ void qedf_capture_grc_dump(struct qedf_ctx *qedf) static ssize_t qedf_sysfs_read_grcdump(struct file *filep, struct kobject *kobj, - struct bin_attribute *ba, char *buf, loff_t off, + const struct bin_attribute *ba, char *buf, loff_t off, size_t count) { ssize_t ret = 0; @@ -124,7 +124,7 @@ qedf_sysfs_read_grcdump(struct file *filep, struct kobject *kobj, static ssize_t qedf_sysfs_write_grcdump(struct file *filep, struct kobject *kobj, - struct bin_attribute *ba, char *buf, loff_t off, + const struct bin_attribute *ba, char *buf, loff_t off, size_t count) { struct fc_lport *lport = NULL; @@ -160,14 +160,14 @@ qedf_sysfs_write_grcdump(struct file *filep, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_grcdump_attr = { +static const struct bin_attribute sysfs_grcdump_attr = { .attr = { .name = "grcdump", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = qedf_sysfs_read_grcdump, - .write = qedf_sysfs_write_grcdump, + .read_new = qedf_sysfs_read_grcdump, + .write_new = qedf_sysfs_write_grcdump, }; static struct sysfs_bin_attrs bin_file_entries[] = { diff --git a/drivers/scsi/qedf/qedf_dbg.h b/drivers/scsi/qedf/qedf_dbg.h index 5ec2b817c694a9846c337c88f6e9b59382dbaa1b..eeb6c841dacb1e68890420db2e5349e9ce60bc20 100644 --- a/drivers/scsi/qedf/qedf_dbg.h +++ b/drivers/scsi/qedf/qedf_dbg.h @@ -100,7 +100,7 @@ struct Scsi_Host; struct sysfs_bin_attrs { char *name; - struct bin_attribute *attr; + const struct bin_attribute *attr; }; extern int qedf_alloc_grc_dump_buf(uint8_t **buf, uint32_t len); From patchwork Mon Dec 16 11:29:16 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: 13909593 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 387C3204F66; Mon, 16 Dec 2024 11:29:20 +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=1734348563; cv=none; b=bl/ZhhCtHxNuJnnHh8AVHD/a5feAFd96dCs2nzhRWQRRM/G37uMS84CshuIwGXP9cm7MIshIt0c/qmKvbVcSXnTdvWhMv9nrVc/1ODVTglAcZOmB4qZ9zMmSRMwwYB6/SsOgDaRoFFxnoouiNgSu190ceM0PtA08Hwbh+IC8EP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348563; c=relaxed/simple; bh=0zAR1Zgw045+wqZMsF16+d7FFPr4+tRVMSP1LbUeDkQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RicB43d3X3lAizq50wf9aaUop7EVb/8Lve9ByuEHSYR95in7epa4FkdiF8pQ4u53K2MIFM0XcXTgTTVQiQ64AhinlA7HzqewxQyIxtEGRr6LS3Dliwqo3yNi83N5AfWl9f6gcU7I9L+ItnW9sw7PDPR5YPsuiyUnB4EpxljtDy4= 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=IfQGNQzq; 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="IfQGNQzq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=0zAR1Zgw045+wqZMsF16+d7FFPr4+tRVMSP1LbUeDkQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IfQGNQzq3sv2I6lR7Bm4wIXf4JexmJ6Orz/ItN7wWI5NG1ehxVi8OJiDmBs3XloXw SpKa9d0FdcuKXuLbHQ0vgALExfPumXMeWpgHDlTMkDWRfAvHcYQabjxC0qb4cyffv7 Tz2Rcr8yjxSC1drhVomftVoQCIvwhT/jsZ2yCP28= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:16 +0100 Subject: [PATCH 09/11] scsi: qedi: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-9-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=802; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=0zAR1Zgw045+wqZMsF16+d7FFPr4+tRVMSP1LbUeDkQ=; b=1W6RZ9BA9Dsc+CBzANf4Tht8N5AIdCyB6NGgVKB+IsTA27eXPneFAttchQy0ojXOOZQZt6vds A+mCsUddQeNDsjzwyDljmAV7qogymPgp/ZcoHbiY7G+vm89CQ7DGCvg 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/scsi/qedi/qedi_dbg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/qedi/qedi_dbg.h b/drivers/scsi/qedi/qedi_dbg.h index fdda12ef13b0fd1f69103a28b8a9e8641281e151..5a1ec45421834bfed5f7d7b87391ae8cc4905c6e 100644 --- a/drivers/scsi/qedi/qedi_dbg.h +++ b/drivers/scsi/qedi/qedi_dbg.h @@ -91,7 +91,7 @@ struct Scsi_Host; struct sysfs_bin_attrs { char *name; - struct bin_attribute *attr; + const struct bin_attribute *attr; }; int qedi_create_sysfs_attr(struct Scsi_Host *shost, From patchwork Mon Dec 16 11:29:17 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: 13909591 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 5BDE7204F78; Mon, 16 Dec 2024 11:29:20 +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=1734348562; cv=none; b=r6iJd/SrF5a/wbzLoN9/BU0lKnl7d38n7zsQUWUn9PtftHnXIx9sfoYipQw7NNEYxIUlYlEYWnJaDyJ76D0q1HRj6wfL6LA8bzNCoElZyJ99gyGzr5tfRFsxJsnlLZGTdjv3D1S7vYfA5xgI3wSsfkk+pHjlLnsB3uOaJn+bE2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348562; c=relaxed/simple; bh=TnuBvtbm/eKcN8yGKFA+/hPyKlT4aEyQjANk9DeyXiI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DH0P6sECcGk/JHNob3ETnw3UFNRh09I0CVlDcwBKQIYnjjylSuw9WPcP/j6oWW1XyZSJ8pZ+C/exDJk3+1qQHOs613O7Qt4ex1ZyGW8gr4L0cfRnJAA2qrmbsTgxWt18oybhwrIQ80QH70Gpv9jWwJW/IcOHICyEL6npwlsRHgw= 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=A1FxjZYR; 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="A1FxjZYR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=TnuBvtbm/eKcN8yGKFA+/hPyKlT4aEyQjANk9DeyXiI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A1FxjZYRPPJQX0xbzKEXvO1Q9aAIWd0ldmiTpipg/B45okU5dWp/imiObvOguW73E 7QCyrC4X6ldX7RnzZxlphHwAJAd9i5FiTbQCkzIQLz/fg3n6BljzV47kOSkuVmSji+ 8I85ovRjBYMgJPYP5Hh+kkF5H2aLupGkGSvqBHpE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:17 +0100 Subject: [PATCH 10/11] scsi: qla2xxx: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-10-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=9804; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=TnuBvtbm/eKcN8yGKFA+/hPyKlT4aEyQjANk9DeyXiI=; b=hMP1olY6EzhDv4p3LOXBwNL02D9JjGyYAaTYTMdtgmGsKSZbwRDLoJlLp8E+KZMqxkaOwp8pV sFlVux4YBYGClYqis4bxn540b7WW9JUJueJYIG3tACx4vyI0MUTLc4u 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/scsi/qla2xxx/qla_attr.c | 80 ++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c index e6ece30c43486ce8f268e369f317e850994ed008..dcb0c2af1fa7cf9b63a5613c01b792143142a412 100644 --- a/drivers/scsi/qla2xxx/qla_attr.c +++ b/drivers/scsi/qla2xxx/qla_attr.c @@ -17,7 +17,7 @@ static int qla24xx_vport_disable(struct fc_vport *, bool); static ssize_t qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -58,7 +58,7 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj, static ssize_t qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -168,19 +168,19 @@ qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_fw_dump_attr = { +static const struct bin_attribute sysfs_fw_dump_attr = { .attr = { .name = "fw_dump", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = qla2x00_sysfs_read_fw_dump, - .write = qla2x00_sysfs_write_fw_dump, + .read_new = qla2x00_sysfs_read_fw_dump, + .write_new = qla2x00_sysfs_write_fw_dump, }; static ssize_t qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -220,7 +220,7 @@ qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj, static ssize_t qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -282,19 +282,19 @@ qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_nvram_attr = { +static const struct bin_attribute sysfs_nvram_attr = { .attr = { .name = "nvram", .mode = S_IRUSR | S_IWUSR, }, .size = 512, - .read = qla2x00_sysfs_read_nvram, - .write = qla2x00_sysfs_write_nvram, + .read_new = qla2x00_sysfs_read_nvram, + .write_new = qla2x00_sysfs_write_nvram, }; static ssize_t qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -318,7 +318,7 @@ qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj, static ssize_t qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -344,19 +344,19 @@ qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_optrom_attr = { +static const struct bin_attribute sysfs_optrom_attr = { .attr = { .name = "optrom", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = qla2x00_sysfs_read_optrom, - .write = qla2x00_sysfs_write_optrom, + .read_new = qla2x00_sysfs_read_optrom, + .write_new = qla2x00_sysfs_write_optrom, }; static ssize_t qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -529,18 +529,18 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj, return rval; } -static struct bin_attribute sysfs_optrom_ctl_attr = { +static const struct bin_attribute sysfs_optrom_ctl_attr = { .attr = { .name = "optrom_ctl", .mode = S_IWUSR, }, .size = 0, - .write = qla2x00_sysfs_write_optrom_ctl, + .write_new = qla2x00_sysfs_write_optrom_ctl, }; static ssize_t qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -587,7 +587,7 @@ qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj, static ssize_t qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -642,19 +642,19 @@ qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_vpd_attr = { +static const struct bin_attribute sysfs_vpd_attr = { .attr = { .name = "vpd", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = qla2x00_sysfs_read_vpd, - .write = qla2x00_sysfs_write_vpd, + .read_new = qla2x00_sysfs_read_vpd, + .write_new = qla2x00_sysfs_write_vpd, }; static ssize_t qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -679,18 +679,18 @@ qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_sfp_attr = { +static const struct bin_attribute sysfs_sfp_attr = { .attr = { .name = "sfp", .mode = S_IRUSR | S_IWUSR, }, .size = SFP_DEV_SIZE, - .read = qla2x00_sysfs_read_sfp, + .read_new = qla2x00_sysfs_read_sfp, }; static ssize_t qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -823,19 +823,19 @@ qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_reset_attr = { +static const struct bin_attribute sysfs_reset_attr = { .attr = { .name = "reset", .mode = S_IWUSR, }, .size = 0, - .write = qla2x00_sysfs_write_reset, + .write_new = qla2x00_sysfs_write_reset, }; static ssize_t qla2x00_issue_logo(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) + const struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, struct device, kobj))); @@ -866,18 +866,18 @@ qla2x00_issue_logo(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_issue_logo_attr = { +static const struct bin_attribute sysfs_issue_logo_attr = { .attr = { .name = "issue_logo", .mode = S_IWUSR, }, .size = 0, - .write = qla2x00_issue_logo, + .write_new = qla2x00_issue_logo, }; static ssize_t qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -929,18 +929,18 @@ qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_xgmac_stats_attr = { +static const struct bin_attribute sysfs_xgmac_stats_attr = { .attr = { .name = "xgmac_stats", .mode = S_IRUSR, }, .size = 0, - .read = qla2x00_sysfs_read_xgmac_stats, + .read_new = qla2x00_sysfs_read_xgmac_stats, }; static ssize_t qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj, @@ -987,18 +987,18 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_dcbx_tlv_attr = { +static const struct bin_attribute sysfs_dcbx_tlv_attr = { .attr = { .name = "dcbx_tlv", .mode = S_IRUSR, }, .size = 0, - .read = qla2x00_sysfs_read_dcbx_tlv, + .read_new = qla2x00_sysfs_read_dcbx_tlv, }; static struct sysfs_entry { char *name; - struct bin_attribute *attr; + const struct bin_attribute *attr; int type; } bin_file_entries[] = { { "fw_dump", &sysfs_fw_dump_attr, }, From patchwork Mon Dec 16 11:29:18 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: 13909589 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 38745204F65; Mon, 16 Dec 2024 11:29:20 +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=1734348561; cv=none; b=NG9wTukMZIdSV1gLMfP4HSBgvyerXANGgSgnhhQHx9s7wrErTZzKkw0qX8xFoEHkIqO1aNZHJDDxzbfVwxawUMaN2+iyyO2dSbmtKyX/79bvRRLeWK1pKWAKjBq/ax3Cz1FJJgWiNWSuV6t1cSCfGa68HusGA2moiXl/qC8OmYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734348561; c=relaxed/simple; bh=3uZW7n2Dks+H/Doo9q/ymOJETj3rjFvKcshiuUcefLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xclmz0hhedQj0TSPRXvHSIWJWXGYMmw5UUmjuriEFeNv3BuUGeA4CwD0OrCw6AKsES4uLS0kMrnJVqHgNHz2ZtQ22akGD3Cwkv894XBrUD5P9scZoUoISWOP0ANzU94f9WrvjjvOz2R/LoHO9db6wDF5QWH20aB6/+f5ggcGpY8= 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=JZnvdDvI; 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="JZnvdDvI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734348553; bh=3uZW7n2Dks+H/Doo9q/ymOJETj3rjFvKcshiuUcefLM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JZnvdDvIVLp1ZOxxcHNlXN8wdnL+pIUmr0q7kiYSIb59hF+wPedan38OdkIU3mFxI GCnSq0idhsTC5EYfkYXdnHztJe4bXI9oXfLHux5+MNwo1WYKNujzy1r+0jT6DM7Gyp VQzSYcM/qQ/Z4JjpIikvUVUs9SejC6uHDS2gdaF0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 12:29:18 +0100 Subject: [PATCH 11/11] scsi: qla4xxx: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241216-sysfs-const-bin_attr-scsi-v1-11-f0a5e54b3437@weissschuh.net> References: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net> To: "James E.J. Bottomley" , "Martin K. Petersen" , Adam Radford , Bradley Grove , Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , James Smart , Dick Kennedy , Brian King , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734348551; l=2063; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=3uZW7n2Dks+H/Doo9q/ymOJETj3rjFvKcshiuUcefLM=; b=FudiGZdk+7eiqucd0Mb3IdXBG2lRQt7iNuv+QY5rtiehQ0sCbeMq8dx/vlYt5/Q9/IIhVyJBr R65fOzklM+wC2PS3I1zQMq5XL6HeZTFUPE1v5sntq59RyzxSNb7mE4t 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/scsi/qla4xxx/ql4_attr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_attr.c b/drivers/scsi/qla4xxx/ql4_attr.c index abfa6ef604800aefef3dbc757d656b7dc20ede8c..e3f85d6ea0db25d5674ca69475af31a4267e2fdb 100644 --- a/drivers/scsi/qla4xxx/ql4_attr.c +++ b/drivers/scsi/qla4xxx/ql4_attr.c @@ -10,7 +10,7 @@ static ssize_t qla4_8xxx_sysfs_read_fw_dump(struct file *filep, struct kobject *kobj, - struct bin_attribute *ba, char *buf, loff_t off, + const struct bin_attribute *ba, char *buf, loff_t off, size_t count) { struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, @@ -28,7 +28,7 @@ qla4_8xxx_sysfs_read_fw_dump(struct file *filep, struct kobject *kobj, static ssize_t qla4_8xxx_sysfs_write_fw_dump(struct file *filep, struct kobject *kobj, - struct bin_attribute *ba, char *buf, loff_t off, + const struct bin_attribute *ba, char *buf, loff_t off, size_t count) { struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, @@ -104,19 +104,19 @@ qla4_8xxx_sysfs_write_fw_dump(struct file *filep, struct kobject *kobj, return count; } -static struct bin_attribute sysfs_fw_dump_attr = { +static const struct bin_attribute sysfs_fw_dump_attr = { .attr = { .name = "fw_dump", .mode = S_IRUSR | S_IWUSR, }, .size = 0, - .read = qla4_8xxx_sysfs_read_fw_dump, - .write = qla4_8xxx_sysfs_write_fw_dump, + .read_new = qla4_8xxx_sysfs_read_fw_dump, + .write_new = qla4_8xxx_sysfs_write_fw_dump, }; static struct sysfs_entry { char *name; - struct bin_attribute *attr; + const struct bin_attribute *attr; } bin_file_entries[] = { { "fw_dump", &sysfs_fw_dump_attr }, { NULL },