From nobody Wed Dec 17 19:54:45 2025 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 F2C2F33FE for ; Sat, 21 Dec 2024 14:48:12 +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=1734792494; cv=none; b=LWZ8blvo3yWSI6U7gWC/TgPPsRGlfKY4qp+BNQlVsP/JNSX0iugdwohV8WutwBW/uIFMIPCyFnKxFC73OQhjqS13ASaFriaA5G2fveoDqmKAFdluTO5AZOPplgCuN4RETfnEDwx7FTSiNnkXyhdkO6zCLS9LeH1mxQVf/y/WIs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792494; c=relaxed/simple; bh=HdhEo0+3qt1XAEQ2OvK1EVfCCKLrCDFgHBMKfkRiFtc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ugZo6dvt3u4uBMTOrB3JRqnNw3Vh4zzw0jgdX3oDc68jy0xC3RJ+7vURg9aLGrnoJpY38Nn259cnaNVGJINtkFkjwG+u3OxEBXQl8T4mmF9DymJOESbN/25lStVOWfoP2zAxN6TzzEfsweLj/3/O/veti9XyueG1crKDfuvN56w= 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=LNg9OD6K; 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="LNg9OD6K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=HdhEo0+3qt1XAEQ2OvK1EVfCCKLrCDFgHBMKfkRiFtc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LNg9OD6Kr8itKOZKhpX6flzRmPnildZpCIg/HAjDHrQx9R4odaRnx6dZcGuhsjVAZ oUSmhmnDx3juaBAT34M/+2MyIVEEWVl6yD6kV5boUS0Tr9JbKK+zV/XdOPy508v/gi IVjtwSLoppZPloW1TgYIP/2OsUb0MI7NdRFcfp4w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:07 +0100 Subject: [PATCH v2 1/9] ocxl: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-1-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1457; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=HdhEo0+3qt1XAEQ2OvK1EVfCCKLrCDFgHBMKfkRiFtc=; b=FdmsEIMeigKQSa0j6GAYjlnflM/7EQ6hcX2TirjlZzlbp4oPUluc4uCjBR/gbYPZjqTrAc+N0 msW6nBb7a31A5r2IQxSAS4yORFYgZgxxkDBLJ2zAXEopFKpLUgc16/r 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=C3=9Fschuh Acked-by: Andrew Donnellan --- drivers/misc/ocxl/sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ocxl/sysfs.c b/drivers/misc/ocxl/sysfs.c index 07520d6e6dc55702696b8656440914c379e6e27a..e849641687a005fec5eb7a6b2e9= 6bc0e9d04dc05 100644 --- a/drivers/misc/ocxl/sysfs.c +++ b/drivers/misc/ocxl/sysfs.c @@ -94,7 +94,7 @@ static struct device_attribute afu_attrs[] =3D { }; =20 static ssize_t global_mmio_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 ocxl_afu *afu =3D to_afu(kobj_to_dev(kobj)); @@ -155,7 +155,7 @@ int ocxl_sysfs_register_afu(struct ocxl_file_info *info) info->attr_global_mmio.attr.name =3D "global_mmio_area"; info->attr_global_mmio.attr.mode =3D 0600; info->attr_global_mmio.size =3D info->afu->config.global_mmio_size; - info->attr_global_mmio.read =3D global_mmio_read; + info->attr_global_mmio.read_new =3D global_mmio_read; info->attr_global_mmio.mmap =3D global_mmio_mmap; rc =3D device_create_bin_file(&info->dev, &info->attr_global_mmio); if (rc) { --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 45DC144C76 for ; Sat, 21 Dec 2024 14:48:13 +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=1734792495; cv=none; b=roeEJs1kzK4ILpD6G8htms5t/+c5tYwy9CZ0l5IlTR1s2ElvtVK6Z4+PS+HJLctySHn+gTxFtu5ifbRNDGzg4bk6f2wZvUWLt5qEKYIjV1YuySKUnmeLKqIzBgC349v729ROH2Rd6tJKuZ+7WE67PGoJ79s1UTlG+Cs5hZEHWLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792495; c=relaxed/simple; bh=RwAfPP9M2GhUNJqftttiOezg9EgAoMngS2VyEVuwqHs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i5ut2AHQdwT+GmDrSWTI9td19P09PVOOz/rQERmhhdoZ5Gy8AsMAvePftWgFS98tz4ocd5wEwtedCFJrWyqOMkJbXLChdE0e0cV9/Zp6YSBGs55yGLXa6i4iGX1G38pkO9e4r1M2P/IJywagKo8BlrVS2GhB18XWGTTwNG9cjJ4= 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=qVGDyzQZ; 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="qVGDyzQZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=RwAfPP9M2GhUNJqftttiOezg9EgAoMngS2VyEVuwqHs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qVGDyzQZaxTjxePLqqeh0PYSAauLlAcjAXx21OS2ucpxW4E03kDA0WdkQRdWNsl88 udXSOBR16ID1YWkjIr0AufMMs2Ku8WzR7bavJB4l2dPQziEFpN0UheYAdatzE1Abs1 DoY+M4cTZCmt2CpaPca47FvKgg0vWYMc+hoP3Lmo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:08 +0100 Subject: [PATCH v2 2/9] cxl: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-2-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=2119; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=RwAfPP9M2GhUNJqftttiOezg9EgAoMngS2VyEVuwqHs=; b=OkQn3R2RgNSCuhxmhVduMnO3k9hbmoJYC3K9thYJkN5ETqHzqu+V+OfVYJG0JVRpk5GW8TBt2 ziTNFgrLzVwAyY+jJVAUWvFmpvzYInLJxoUxqpIXqGJBrcxDdtFMLEh 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=C3=9Fschuh Acked-by: Andrew Donnellan --- drivers/misc/cxl/sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c index 409bd1c39663159a0d11c3ccba2aa5a8451baa34..b1fc6446bd4b7caa2f5c6e23e0a= ba5934caffd46 100644 --- a/drivers/misc/cxl/sysfs.c +++ b/drivers/misc/cxl/sysfs.c @@ -444,7 +444,7 @@ static ssize_t api_version_compatible_show(struct devic= e *device, } =20 static ssize_t afu_eb_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 cxl_afu *afu =3D to_cxl_afu(kobj_to_dev(kobj)); @@ -538,7 +538,7 @@ static ssize_t class_show(struct kobject *kobj, } =20 static ssize_t afu_read_config(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 afu_config_record *cr =3D to_cr(kobj); @@ -620,7 +620,7 @@ static struct afu_config_record *cxl_sysfs_afu_new_cr(s= truct cxl_afu *afu, int c cr->config_attr.attr.name =3D "config"; cr->config_attr.attr.mode =3D S_IRUSR; cr->config_attr.size =3D afu->crs_len; - cr->config_attr.read =3D afu_read_config; + cr->config_attr.read_new =3D afu_read_config; =20 rc =3D kobject_init_and_add(&cr->kobj, &afu_config_record_type, &afu->dev.kobj, "cr%i", cr->cr); @@ -693,7 +693,7 @@ int cxl_sysfs_afu_add(struct cxl_afu *afu) afu->attr_eb.attr.name =3D "afu_err_buff"; afu->attr_eb.attr.mode =3D S_IRUGO; afu->attr_eb.size =3D afu->eb_len; - afu->attr_eb.read =3D afu_eb_read; + afu->attr_eb.read_new =3D afu_eb_read; =20 rc =3D device_create_bin_file(&afu->dev, &afu->attr_eb); if (rc) { --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 95F511F37C0 for ; Sat, 21 Dec 2024 14:48:13 +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=1734792495; cv=none; b=BBL3eXGxQRk1wDaKZfHW2xtXZJkDVpNHd6XJyJFPee1zHmFePIldg/C1qi1Zu7BZjps/ye26bYn6MmzKA00lH8VR4LSb8jsyFfbrrYQ482Q/KBQp5+iZb9sL7lj9W9bx842F0oxtnecUBkoBYXcD/v0Rxo6kZCrmYJmx2I7f/Wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792495; c=relaxed/simple; bh=lrmkPttDURFKu0OlFekPYzaHej1ygcR7qwdieg64a/U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L5JDWna4oX92cU8UwHMAS46eoDbT3uRxlkCWfzXHyurztHV5d48mJDEUNBXtS5c7HbIJ33FTF+9HbttcD8iLQfXrLi/GL1kgEEFhoriKyA6PnO2q9CHa3ZFitrr/qKFM9e3K6tzvlYbPCnWwlsbdhnFWzmOMoKEdIgDofMyQe8c= 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=EWtNXKai; 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="EWtNXKai" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=lrmkPttDURFKu0OlFekPYzaHej1ygcR7qwdieg64a/U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EWtNXKaiesE5iymgb6Nx8YvZuEAPf9vYASG1fjoU46cjYroVYOuoHCLLUTYybsOc1 BsxvOei373DqCAw8R3zXSBeo8XXGoBK5r8n71NytzfbrmYZGnr6WMsBFDiSFveF4vi pNuYVuSoHtfZNDOl2WWMu+9tql0AsAEtAXsaUvmk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:09 +0100 Subject: [PATCH v2 3/9] misc: sram: constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-3-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1550; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=lrmkPttDURFKu0OlFekPYzaHej1ygcR7qwdieg64a/U=; b=bdSQV5Q6IhmFAaIFeRAfk/SbSV3IqpAh93NP3WZkXM1uYH6quaPwdVCV+1MdEt9keWOo8kNPu o5bEK7MDyKoAEUDUsmbDpHz8ivH+xXGdj40OWuHG0gpN5H4u8iIc2LA 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=C3=9Fschuh --- drivers/misc/sram.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index e40b027a88e25209933a20dc9dbd7db29cb81ba5..e5069882457ef6ba5dc084d0299= 4034dc39d24c6 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -23,7 +23,7 @@ #define SRAM_GRANULARITY 32 =20 static ssize_t sram_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t pos, size_t count) { struct sram_partition *part; @@ -38,7 +38,7 @@ static ssize_t sram_read(struct file *filp, struct kobjec= t *kobj, } =20 static ssize_t sram_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t pos, size_t count) { struct sram_partition *part; @@ -83,8 +83,8 @@ static int sram_add_export(struct sram_dev *sram, struct = sram_reserve *block, return -ENOMEM; =20 part->battr.attr.mode =3D S_IRUSR | S_IWUSR; - part->battr.read =3D sram_read; - part->battr.write =3D sram_write; + part->battr.read_new =3D sram_read; + part->battr.write_new =3D sram_write; part->battr.size =3D block->size; =20 return device_create_bin_file(sram->dev, &part->battr); --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 88BD857CB6 for ; Sat, 21 Dec 2024 14:48:13 +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=1734792495; cv=none; b=YOVOEmYocdS0/FJi19jYtLLlf3dZhH/rbEJQu/xx3l9M9PFKv/OsETDTCG8OpkVaUqBHO3lGFibYF+zbmTabi8Yu1GpxvETdLgDS2wBolzWl20JR+wyFTi8uZEAN0Lb7o6Zb+cYqaArLKDlpJVEepTnJ70vUt0/LStk3ek9Rebc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792495; c=relaxed/simple; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W4LPIhb5Joq26gjTCWbz34wcC67tPOq0r08ONYrMo8WaVdpjsDp/corPEpEqMVsEa/jcXyY8GCsl6t8Yvd1Alh/el/N9I+DNcoIXX9G6zL2UAJgkzzEapxA4kDVFGEqwVcNhfbQ4MM844Btchb4fNNlt7JNW8SFX8CIInNLT/mM= 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=enMld3zO; 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="enMld3zO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=enMld3zO6o9mSKLhYxKXQHG2Bbc+Rs+lByn+GiB88gzFWqhFsDLgpQ/CPRdpDkwKD RisG0Szjk9NMl3jV0HnhYxnY9RxEJQKbGKoKRg0Mm7dRmt8lVOdE/wwuwtbJH0YmkP Oe9bBtsCvEJPdBMgOEsOrZlpE0RK7Zxs2XA8QGsU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:10 +0100 Subject: [PATCH v2 4/9] misc: c2port: Calculate bin_attribute size through group callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-4-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1911; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=H724roLIaoPip44zZqVVk4vtvisEZYzLS47/VZWgyws=; b=zsZ1GLJgkyJDB4FWW1KUeoShxFYHVmehKqs0aufi24x33PwPG/GMeCoROYkLYuZad1oVFmeqt CLu8iRDVOUhBfq6slRcQdzva8KpYTs09xWkYf0/7+lSRZ7Ffzo2Um7O X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Modifying the size of the global bin_attribute instance can be racy. Instead use the new .bin_size callback to do so safely. For this to work move the initialization of c2dev->ops before the call to device_create() as the size callback will need access to it. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/misc/c2port/core.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index 2bb1dd2511f9dd178b8c06baa460bb609f7f8fd7..f455d702b9cd4999648a57985e3= 05aac5301403f 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -874,9 +874,22 @@ static struct bin_attribute *c2port_bin_attrs[] =3D { NULL, }; =20 +static size_t c2port_bin_attr_size(struct kobject *kobj, + const struct bin_attribute *attr, + int i) +{ + struct c2port_device *c2dev =3D dev_get_drvdata(kobj_to_dev(kobj)); + + if (attr =3D=3D &bin_attr_flash_data) + return c2dev->ops->blocks_num * c2dev->ops->block_size; + + return attr->size; +} + static const struct attribute_group c2port_group =3D { .attrs =3D c2port_attrs, .bin_attrs =3D c2port_bin_attrs, + .bin_size =3D c2port_bin_attr_size, }; =20 static const struct attribute_group *c2port_groups[] =3D { @@ -912,8 +925,7 @@ struct c2port_device *c2port_device_register(char *name, if (ret < 0) goto error_idr_alloc; c2dev->id =3D ret; - - bin_attr_flash_data.size =3D ops->blocks_num * ops->block_size; + c2dev->ops =3D ops; =20 c2dev->dev =3D device_create(c2port_class, NULL, 0, c2dev, "c2port%d", c2dev->id); @@ -924,7 +936,6 @@ struct c2port_device *c2port_device_register(char *name, dev_set_drvdata(c2dev->dev, c2dev); =20 strscpy(c2dev->name, name, sizeof(c2dev->name)); - c2dev->ops =3D ops; mutex_init(&c2dev->mutex); =20 /* By default C2 port access is off */ --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 32C041FCCFA for ; Sat, 21 Dec 2024 14:48: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=1734792497; cv=none; b=lzYSb7d8ih3nr9PcFbO4hKmVhDfxrvUAWTvh7nPCD1RXgLJkGqyBV3LsV7wYiGDP6M2B8o3ecMfebr5PnFYCmQirNEHYPFec98d32Y1tR+/coMyf6npQUda/h4zFK2tZmnMtiAxGFkXry3piWCHbmNLg4PjAPkz/TWTZ2BK+A3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792497; c=relaxed/simple; bh=CW1VrAsVcIFzeSQ+LRElzz/v/465hJ7K48yutpNKaDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cx4yA/6/tFvQ8onO+5bE+qZ0phik0s1kn1+0F35lsr893y34HtmK3+FVTMklvhxYUHk20S/EKC8X4gWkmgSA16WA7vUfFUBmZ6zvF9MZNXMzICJJM0h3FUJgTGjSIzKuxoH6kyKfqiretaZn0qLYUPUkikCUUzw8HpoLX3w6dRE= 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=QbvJmsg+; 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="QbvJmsg+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=CW1VrAsVcIFzeSQ+LRElzz/v/465hJ7K48yutpNKaDw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QbvJmsg+CNQBRggf76QWd9xXxskBhyJUd/KIIa+CoheJZlSWikhp3QXu9kXtAHmpy cVN5NUblycFJRWx4OJHNUtZVrzfPNGhobeBRxKK27ghb9r94ssbEcQd5JeXwEyfxU7 hZdNIM0FDT2rTXPxLiVW6RmAG4cqEXfoW5/wnBP0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:11 +0100 Subject: [PATCH v2 5/9] misc: c2port: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-5-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=2244; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=CW1VrAsVcIFzeSQ+LRElzz/v/465hJ7K48yutpNKaDw=; b=HmftUGO/Q1gjc1W9SM0u88Rx7nEVoZHpGYfZvAoUDF+I4EtC4sXEYCXkrNtxqBs9a5jkryhl8 EWg9WKupm5uCiRgGg8WJ3jywOnRpnj5vRnBHvEJBy+8ljU2G4rfL+Pp 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=C3=9Fschuh --- drivers/misc/c2port/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index f455d702b9cd4999648a57985e305aac5301403f..fc64474b8241b73df4937bd4bac= 5593fbb96016c 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -714,7 +714,7 @@ static ssize_t __c2port_read_flash_data(struct c2port_d= evice *dev, } =20 static ssize_t c2port_read_flash_data(struct file *filp, struct kobject *k= obj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buffer, loff_t offset, size_t count) { struct c2port_device *c2dev =3D dev_get_drvdata(kobj_to_dev(kobj)); @@ -829,7 +829,7 @@ static ssize_t __c2port_write_flash_data(struct c2port_= device *dev, } =20 static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *= kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buffer, loff_t offset, size_t count) { struct c2port_device *c2dev =3D dev_get_drvdata(kobj_to_dev(kobj)); @@ -849,8 +849,8 @@ static ssize_t c2port_write_flash_data(struct file *fil= p, struct kobject *kobj, return ret; } /* size is computed at run-time */ -static BIN_ATTR(flash_data, 0644, c2port_read_flash_data, - c2port_write_flash_data, 0); +static const BIN_ATTR(flash_data, 0644, c2port_read_flash_data, + c2port_write_flash_data, 0); =20 /* * Class attributes @@ -869,7 +869,7 @@ static struct attribute *c2port_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *c2port_bin_attrs[] =3D { +static const struct bin_attribute *const c2port_bin_attrs[] =3D { &bin_attr_flash_data, NULL, }; @@ -888,7 +888,7 @@ static size_t c2port_bin_attr_size(struct kobject *kobj, =20 static const struct attribute_group c2port_group =3D { .attrs =3D c2port_attrs, - .bin_attrs =3D c2port_bin_attrs, + .bin_attrs_new =3D c2port_bin_attrs, .bin_size =3D c2port_bin_attr_size, }; =20 --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 58EFF1FCD0D for ; Sat, 21 Dec 2024 14:48: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=1734792497; cv=none; b=BuYtsgdnczcEvAK3nmygpMj1UMsY0HVz/M3DyRoPExgFvRJCP5LqL0HJo16m1w/LKX18jyzver/c5QaXj5ZBs1yllZ1Frp7NdIayXI34Ypa+bBkwTskBKsJcA/Wex9fYB2WL+D851pHgXgyiOyOcE5KIB6ZYSKVhaUHfUYkFQvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792497; c=relaxed/simple; bh=N27SW5V9S6zkyqz00AIvVG+5Rix9h0ENrJDmGyAeG8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tkIH8t7A768cjCXa2OzxtrEzk3pGbhflDH5en6/vH5YGpGnE/HB3o6YrC9Fu/gkhnN+6TLL1/r5oNsZyNU9NFBn3+Pfwccx29mJUkvSPQxfGB/hVjdX0TnJBvRnYTJB6BTSWagCTvt1v+yIDmkCS9DqfsoAW8Z+jKqPWg6u8E3Y= 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=Pdf7WZd/; 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="Pdf7WZd/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=N27SW5V9S6zkyqz00AIvVG+5Rix9h0ENrJDmGyAeG8A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Pdf7WZd/KEqFjEvas4FwWWeir8E5g7EOhTvWrqB6Nt5Gu7CTdpjO9Ura+5T4IfMLt 79ciGz484dD4DeYNJ7/Mm8SbIl7tGg92pmaX+PeYdxB7Fr3aUVuKpGIDsRIsijgPjq /Gk+HfDic2O9cqtQdvtU9/SBeSVcmxWo9/OKN7Gs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:12 +0100 Subject: [PATCH v2 6/9] misc: pch_phub: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-6-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1571; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=N27SW5V9S6zkyqz00AIvVG+5Rix9h0ENrJDmGyAeG8A=; b=IXDM8dc7lVmDMCAr1wkZkdrRiZs8RT6lHIXepnbM8+omOaL1e1ocmfOreTcpfRPzfdnG4Wi1F Hu13Q87/KUkDiZYTf0ZJ3fg47IwdGmBMfJ0MrsUFJjIn6nchblbQVy6 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=C3=9Fschuh --- drivers/misc/pch_phub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c index 8d2b7135738ed5543138f2249d2379a10113b410..6121c0940cd148d48b8d574065c= 50703b6a301d7 100644 --- a/drivers/misc/pch_phub.c +++ b/drivers/misc/pch_phub.c @@ -483,7 +483,7 @@ static int pch_phub_write_gbe_mac_addr(struct pch_phub_= reg *chip, u8 *data) } =20 static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { unsigned int rom_signature; @@ -553,7 +553,7 @@ static ssize_t pch_phub_bin_read(struct file *filp, str= uct kobject *kobj, } =20 static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { int err; @@ -655,8 +655,8 @@ static const struct bin_attribute pch_bin_attr =3D { .mode =3D S_IRUGO | S_IWUSR, }, .size =3D PCH_PHUB_OROM_SIZE + 1, - .read =3D pch_phub_bin_read, - .write =3D pch_phub_bin_write, + .read_new =3D pch_phub_bin_read, + .write_new =3D pch_phub_bin_write, }; =20 static int pch_phub_probe(struct pci_dev *pdev, --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 3CB1A1FCCFD for ; Sat, 21 Dec 2024 14:48: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=1734792497; cv=none; b=gQM5D7FXOrmtRJxGe9OdmcfNO2m9oaJnndbPXAuVInHcz2geLxyK6Uivhddr8tjTBSPNtLubeaqUDaUAygh3y3KcbyCHuLG7k+AzZWGcduFSLYTqvEWGfZSAZ+RpI/3gVlVBpfefG2I/PjU3bMCKwyUYVjGbkkdnMlaPxPeoQ5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792497; c=relaxed/simple; bh=SGNU5IH45oWd8l2/U8DWBMgp52g/CAQH5eqzkYxnU98=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rgnsdCB2hlHRBueZKKAD0eTzPeCHcA1MnN1//mvXSI98fYDmJOfLy6QOc3YqoDBlNZ5sduZ2Vd5VRTteI/pQd3b/EBWii0MShWlR0mLLKYVSNPOZSiiEXU5nI/Rwld/x3CHKM9OOGruW43/JMFjYQNX0JHvomd4E3e76NkuHFzw= 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=BYWrCwnE; 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="BYWrCwnE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=SGNU5IH45oWd8l2/U8DWBMgp52g/CAQH5eqzkYxnU98=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BYWrCwnEkn0QHxatyy8rZTjh4Iq0endZnyBkLvR4dJY+RPmT+pSThMIA1VQGAenM/ 7CS3e3STgGwan9cQT9P4oaqoN2vSXl/xZ3ik5i3X5oMIyRpT1wcgJxYgEEwoU/KAqY Ct0A+8BrBH8ROREFUysqC6o9TIh24e2OaWWF9tdU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:13 +0100 Subject: [PATCH v2 7/9] misc: eeprom/idt_89hpesx: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-7-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1790; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=SGNU5IH45oWd8l2/U8DWBMgp52g/CAQH5eqzkYxnU98=; b=QNNWabCGxYdXGIaopmxDFnMFSHHSbTjQvdcOUBaTQYvRsIoPHmXFwwCwl2o+0S2E1qKiWVKVD B9JJWLcfMQICjSaIrvp4H0cDOrl3beHSgRgZ1W6PewNC25s/IpIV8dt 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=C3=9Fschuh --- drivers/misc/eeprom/idt_89hpesx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89= hpesx.c index 43421fe37d338874ff1c2949497c64ebf0143106..1fc632ebf22f560088084519e5a= d8e8b37958368 100644 --- a/drivers/misc/eeprom/idt_89hpesx.c +++ b/drivers/misc/eeprom/idt_89hpesx.c @@ -847,7 +847,7 @@ static int idt_csr_read(struct idt_89hpesx_dev *pdev, u= 16 csraddr, u32 *data) * @count: Number of bytes to write */ static ssize_t eeprom_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct idt_89hpesx_dev *pdev; @@ -871,7 +871,7 @@ static ssize_t eeprom_write(struct file *filp, struct k= object *kobj, * @count: Number of bytes to write */ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct idt_89hpesx_dev *pdev; @@ -1017,7 +1017,7 @@ static ssize_t idt_dbgfs_csr_read(struct file *filep,= char __user *ubuf, * NOTE Size will be changed in compliance with OF node. EEPROM attribute = will * be read-only as well if the corresponding flag is specified in OF node. */ -static BIN_ATTR_RW(eeprom, EEPROM_DEF_SIZE); +static const BIN_ATTR_RW(eeprom, EEPROM_DEF_SIZE); =20 /* * csr_dbgfs_ops - CSR debugfs-node read/write operations --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 5922D1FCD0F for ; Sat, 21 Dec 2024 14:48: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=1734792498; cv=none; b=JQU4n4VnOUyLX2HoT6gWjOP7UuohUc8So8GBXrk9XGeqfEy9enyUuvA7DyVhhi2W97DLH3yH4pOkaABCHE0JWXdvCVpp6yhNbaaj3XY5YYFEBKrXVqxiof0T5YR9N9Ai8S39qoB/Ui+UJa4j0iVWSfSDibFW8uX5FHru0WizPTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792498; c=relaxed/simple; bh=P5yp8xYY8rjGfFuGyyUiA1DeB8eRe4QDxQgMbEH9sX4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bfa6vFiPjrTr84Dm+U/x1LRPLTia9RL0mwhQKr3ERVjodIpHGV+1ZHujgh1NNojA3quPsUbMy7oF7EUytALQy2AjudNhXmj9gRX0bBrPkSp7nNaGrszfCGnLcTV/OhK3OMBXi6VO4gjnqkzgC2/ie5a+lNAu8yGOZAx8KMg7g6w= 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=JNVcWW2g; 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="JNVcWW2g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=P5yp8xYY8rjGfFuGyyUiA1DeB8eRe4QDxQgMbEH9sX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JNVcWW2gFSmvicQCnJGojFONnzhcFAsQGpIKt6ReRKCCf+YKAnUgrh7vjeRAisGUm v30iei+YcDn+MZfccO4rxmoS++hnGiFThuz/x2TRXE7UHzOduKb7TdVX9PkfQS3vso lTMgneXPAepSWSzaIiCNTSuFL23RzMF9ctzWzffA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:14 +0100 Subject: [PATCH v2 8/9] misc: eeprom/max6875: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-8-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1212; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=P5yp8xYY8rjGfFuGyyUiA1DeB8eRe4QDxQgMbEH9sX4=; b=RXc6sdUDetNj/ZNOQ7p5ylGNWpmccRq2GRI6mGXONV+ZAdL005yVc1OM1q/GydoVP+FgaFH1y bll9rm0OAfvDlwN6xXOLVsWLG0SZrIssLygrIHOyS6BFhM5dXEfMukl 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=C3=9Fschuh --- drivers/misc/eeprom/max6875.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c index 6fab2ffa736b741593931c413f230d7c43b5b8dd..1c36ad153e783ead6ba2481c648= 38390f0bb05f4 100644 --- a/drivers/misc/eeprom/max6875.c +++ b/drivers/misc/eeprom/max6875.c @@ -104,7 +104,7 @@ static void max6875_update_slice(struct i2c_client *cli= ent, int slice) } =20 static ssize_t max6875_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) { struct i2c_client *client =3D kobj_to_i2c_client(kobj); @@ -127,7 +127,7 @@ static const struct bin_attribute user_eeprom_attr =3D { .mode =3D S_IRUGO, }, .size =3D USER_EEPROM_SIZE, - .read =3D max6875_read, + .read_new =3D max6875_read, }; =20 static int max6875_probe(struct i2c_client *client) --=20 2.47.1 From nobody Wed Dec 17 19:54:45 2025 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 B65FA1FCF7C for ; Sat, 21 Dec 2024 14:48: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=1734792498; cv=none; b=UnXIxKxZRsqiBRsHiECWXT1PvRYUyQL5/HVPR0kXnFeCgOpKcEdCWl3CuHqyuXD2/nyPTQ/zw9qww2Xy73ZutpuDxj7CMPToLR3sN5Ct3QGiq+bpFi2nrl+opxsDRwy8TwUrOLLPsjopiK0u1DZYOHJrWcaS1VOOKK/0A/bsXoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734792498; c=relaxed/simple; bh=K4ArLdURdX68J2n0OD7NKA61+TDFNtIXruvjgSApS6k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d9dghQ2DE4IoIUCIWA0EB/HuRchpfHnwdN+Xkzsz1zQT2Ju9BdRUpNRpSpqOPgiTDNiZtjyEVcpALUOhMqixol3Ii2JerdMRQLTOvDLGlk/W9153Pmb3AxkxjoTc/vvZPo/kTb5f7himsxNxwJjb45g/5xQx520+EZLvusttFzc= 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=FHyHaGrB; 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="FHyHaGrB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734792491; bh=K4ArLdURdX68J2n0OD7NKA61+TDFNtIXruvjgSApS6k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FHyHaGrBeFnd6dXa1UhJKEN/Vj2M8u9k7KuCJeQBZ+TI0lgE+nsDb3YJJRQcRhln+ l6L7ImQUPv6oLtF9lGu0hab4fAk8lNt24Wank24BA7AIZuOZnjq20PP2zvp7LgZRr+ wk7d629uOMIHeU3wI3GWCxe3u9J23I95fIreojVo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 21 Dec 2024 15:48:15 +0100 Subject: [PATCH v2 9/9] misc: ds1682: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241221-sysfs-const-bin_attr-misc-drivers-v2-9-ba5e79fe8771@weissschuh.net> References: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> In-Reply-To: <20241221-sysfs-const-bin_attr-misc-drivers-v2-0-ba5e79fe8771@weissschuh.net> To: Frederic Barrat , Andrew Donnellan , Arnd Bergmann , Greg Kroah-Hartman Cc: linuxppc-dev@lists.ozlabs.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=1734792490; l=1662; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=K4ArLdURdX68J2n0OD7NKA61+TDFNtIXruvjgSApS6k=; b=foEod6mMQTcekZkVuJkj3bgmnzgSH+ihxv0TERCRycmamIXRwEQekQx7aQLC9tnLABorA1EFH PCmFdNEgnGBArnWNitpNlMuNBREu/XWm0QXLKvsE2KCJdI/rKNR/fHA 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=C3=9Fschuh --- drivers/misc/ds1682.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c index 4175df7ef0111f69ed8d4229b7ab50a3c3d7ad12..5d5a70a62e98b6691aac1c0f914= 2d39555ba4f8c 100644 --- a/drivers/misc/ds1682.c +++ b/drivers/misc/ds1682.c @@ -154,7 +154,7 @@ static const struct attribute_group ds1682_group =3D { * User data attribute */ static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct i2c_client *client =3D kobj_to_i2c_client(kobj); @@ -172,7 +172,7 @@ static ssize_t ds1682_eeprom_read(struct file *filp, st= ruct kobject *kobj, } =20 static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct i2c_client *client =3D kobj_to_i2c_client(kobj); @@ -194,8 +194,8 @@ static const struct bin_attribute ds1682_eeprom_attr = =3D { .mode =3D S_IRUGO | S_IWUSR, }, .size =3D DS1682_EEPROM_SIZE, - .read =3D ds1682_eeprom_read, - .write =3D ds1682_eeprom_write, + .read_new =3D ds1682_eeprom_read, + .write_new =3D ds1682_eeprom_write, }; =20 static int ds1682_nvmem_read(void *priv, unsigned int offset, void *val, --=20 2.47.1