From nobody Wed Dec 17 21:41:10 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