From nobody Mon Feb 9 03:59:01 2026 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 03DD51885AD for ; Mon, 16 Dec 2024 04:07:48 +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=1734322072; cv=none; b=CdjmEnDwlIcOJq7QFItSeJLrv+Dm3JpYTLYyifwF7iV/G65Z0c4EHeAp6vxSl5NiM9ctJ7GbOwR96PIZ3W06IshusQaDox/uLVKMgh8AkIisjfj37WPLTSnb/BFlUdP0/h+Cd7VgJXxm54JLRiPdJDKIMgo7zqdtBTTaefSBfIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734322072; c=relaxed/simple; bh=Jn8gj5ETLfAmg0J0FzeVMFzW8y4Al5TBi0L76/poVeY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZQfOnA+du3/zt67+4Q64hiz9tm1j0kJixv8EF5jE0jJkb2UCbUWFS5G1TEiaArZMSW3KX9avIZkrB7cc6Ks/k9+ZAn5gw95iAbB6KK+DEPxucNRRoETJwg9xykNIXOw/234u2N7I7mgP5TmRkUe0zCRsWwmXvt+ie/0M/EI6MxQ= 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=rKNRcGOq; 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="rKNRcGOq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734322066; bh=Jn8gj5ETLfAmg0J0FzeVMFzW8y4Al5TBi0L76/poVeY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rKNRcGOqDyGxIYNM6sGZypbYnUnRhbQsV3FSVJNv/Lud70FZlizhYzCTa0WaOykWm eHv6szvSHrftwF35djHryS1bvs5YDc3G4wVzKvPXqabtkn6xYcKvAmEbee245Zn8g6 d+/J1OBw4dROLzbQidPJzXElYXPymhqLhHaUrFfU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 05:07:43 +0100 Subject: [PATCH 1/5] powerpc/secvar: Mark __init functions as such 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: <20241216-sysfs-const-bin_attr-powerpc-v1-1-bbed8906f476@weissschuh.net> References: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan 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=1734322065; l=1924; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Jn8gj5ETLfAmg0J0FzeVMFzW8y4Al5TBi0L76/poVeY=; b=o5LTMX942/pTgvjJuj+3fewCjW41uN7ZEzdZrygLYHNpJhNVyIR79PTD79v0ctAOfgC45j8mU 1vBsP3mrbdUBir6cn6QYNshbLXlDwNTuDsJ0EiLiAweMAdo1SY4aZEb X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The setup functions are only called during the init phase of the kernel. They can be discarded and their memory reused after that. Signed-off-by: Thomas Wei=C3=9Fschuh --- arch/powerpc/kernel/secvar-sysfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secva= r-sysfs.c index fbeb1cbac01b2c575cb7a71b16d214f2f822c489..b7536fbe8c4f43fa0f523c64685= 167b8b9dfd5ee 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -130,7 +130,7 @@ static const struct kobj_type secvar_ktype =3D { .default_groups =3D secvar_attr_groups, }; =20 -static int update_kobj_size(void) +static __init int update_kobj_size(void) { =20 u64 varsize; @@ -145,7 +145,7 @@ static int update_kobj_size(void) return 0; } =20 -static int secvar_sysfs_config(struct kobject *kobj) +static __init int secvar_sysfs_config(struct kobject *kobj) { struct attribute_group config_group =3D { .name =3D "config", @@ -158,7 +158,7 @@ static int secvar_sysfs_config(struct kobject *kobj) return 0; } =20 -static int add_var(const char *name) +static __init int add_var(const char *name) { struct kobject *kobj; int rc; @@ -181,7 +181,7 @@ static int add_var(const char *name) return 0; } =20 -static int secvar_sysfs_load(void) +static __init int secvar_sysfs_load(void) { u64 namesize =3D 0; char *name; @@ -209,7 +209,7 @@ static int secvar_sysfs_load(void) return rc; } =20 -static int secvar_sysfs_load_static(void) +static __init int secvar_sysfs_load_static(void) { const char * const *name_ptr =3D secvar_ops->var_names; int rc; @@ -224,7 +224,7 @@ static int secvar_sysfs_load_static(void) return 0; } =20 -static int secvar_sysfs_init(void) +static __init int secvar_sysfs_init(void) { u64 max_size; int rc; --=20 2.47.1 From nobody Mon Feb 9 03:59:01 2026 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 2AEBA199240 for ; Mon, 16 Dec 2024 04:07:48 +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=1734322074; cv=none; b=j1Cu1vZ5FiPBRDhvpc1ak5DDb/quzkrfzKeHfLuDurzY78XahlsEeq9OJM40nkUcIove+URlPC2aN79sLQ+gRko5q6NVXeHxyNo6yrgUEUEujix61k1LAduIubGAFq8vsjDY/tnVFG2TZtkVxk1WO+Utu81YeQkgOBDogLQVWNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734322074; c=relaxed/simple; bh=UwFlrZoaphbEMf2Wi/FBevBRcRQkiVMw7c3eq5eTCfk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VPD/SEA+za+m+Eg7dYcETf9ZzpKyPXufxSGfg5YPn0/HHpIBMwC8bo0Ap+pT0g+BYJOs90iF1uXGppKt8Lm9eLXz8st290YxnddlJDgVg/30+CycvM2gsH9CQKlJOSFWC/q7mGKtr42Ml9vRJ7+asypiriiGVwEpDiF0LcYCQYs= 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=lW+vXty2; 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="lW+vXty2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734322065; bh=UwFlrZoaphbEMf2Wi/FBevBRcRQkiVMw7c3eq5eTCfk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lW+vXty2mFB0zNdICvad95Ludo+LgrtTfz8STKo9jEiOQ82+B/j8YTemdDpeqKlu2 mlSFWQsiVDxdFOe+/cKTkPOZONRC7CgsMd9Jut75CpAGSlTMtNqJ25Uy+C7W5x1aSR kUmqo1bl72QuGhEw0GYvmCYxgvfWRuciuR1MtZOw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 05:07:44 +0100 Subject: [PATCH 2/5] powerpc/secvar: 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: <20241216-sysfs-const-bin_attr-powerpc-v1-2-bbed8906f476@weissschuh.net> References: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan 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=1734322065; l=2183; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=UwFlrZoaphbEMf2Wi/FBevBRcRQkiVMw7c3eq5eTCfk=; b=CyAuDv4h7ejzrTBndYz5Dci7CbE7wh32OdcwjNOfWT70ARoUjG9JXQCms//SEBUcPGOHeEDGU K+EZ0j7voEtCRKMaq8Rw+vFcxnzP5U9SW2/4qkjKKfRCIZM5Lx+9CSX 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 --- arch/powerpc/kernel/secvar-sysfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secva= r-sysfs.c index b7536fbe8c4f43fa0f523c64685167b8b9dfd5ee..afb690a172b4e281830d0dd1878= 5f70e0a967d13 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -52,7 +52,7 @@ static ssize_t size_show(struct kobject *kobj, struct kob= j_attribute *attr, } =20 static ssize_t data_read(struct file *filep, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { char *data; @@ -85,7 +85,7 @@ static ssize_t data_read(struct file *filep, struct kobje= ct *kobj, } =20 static ssize_t update_write(struct file *filep, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { int rc; @@ -104,11 +104,11 @@ static struct kobj_attribute format_attr =3D __ATTR_R= O(format); =20 static struct kobj_attribute size_attr =3D __ATTR_RO(size); =20 -static struct bin_attribute data_attr =3D __BIN_ATTR_RO(data, 0); +static struct bin_attribute data_attr __ro_after_init =3D __BIN_ATTR_RO(da= ta, 0); =20 -static struct bin_attribute update_attr =3D __BIN_ATTR_WO(update, 0); +static struct bin_attribute update_attr __ro_after_init =3D __BIN_ATTR_WO(= update, 0); =20 -static struct bin_attribute *secvar_bin_attrs[] =3D { +static const struct bin_attribute *const secvar_bin_attrs[] =3D { &data_attr, &update_attr, NULL, @@ -121,7 +121,7 @@ static struct attribute *secvar_attrs[] =3D { =20 static const struct attribute_group secvar_attr_group =3D { .attrs =3D secvar_attrs, - .bin_attrs =3D secvar_bin_attrs, + .bin_attrs_new =3D secvar_bin_attrs, }; __ATTRIBUTE_GROUPS(secvar_attr); =20 --=20 2.47.1 From nobody Mon Feb 9 03:59:01 2026 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 05449191F8F for ; Mon, 16 Dec 2024 04:07:48 +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=1734322071; cv=none; b=ndZtfVwmxdf4yqXpsu4TQQDvY3ObrMjrg1r+dLR+k0dtln3dhG9mSoKnRr2Ch/NapvyWviB2LO1R3I6hk+QOA8bOD0xmhwPk8gX5uhpTaverrHyqyIsd+srdsUi9bIPwXMrtzv7EOISRt67xC0IvF74TQo5oxgRppaI2MoxMhto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734322071; c=relaxed/simple; bh=lpG1ThR/8HH372NAoQFJS0Y3lxzTHbVf7kKGZfLomkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CN209aJz5y0uht1b85TO5RVJZd8j88Q61vnSsASwcEvxhzXdHtH5v/q4vmjKqZNz1A2d2WL8bh4Dd7heerHtd+J5GtaWz0jrtH1IGWx2S15IK02k4vmxKfNooKwY/9Aze8cHTQNFh5Ilz2NF64FcrDdt7P4ifknqSUyrSwEDG/A= 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=gGd9+H1A; 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="gGd9+H1A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734322066; bh=lpG1ThR/8HH372NAoQFJS0Y3lxzTHbVf7kKGZfLomkc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gGd9+H1ADEHjqWuudOxcGRWSv2b2PyMpyuCg6o0S2WV84iWtSMSm2qvDLMOKolW2s Q/IdNHRLHFasCV5+TH9zJ0w92nniDVTmM7DSprZY+5DHHkBolzN4cl7nfbpwnhmzKP KfwSBonKXmHfb+mJUa7E/j/aKDoXJDzZ4CSw75z4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 05:07:45 +0100 Subject: [PATCH 3/5] powerpc/powernv/ultravisor: 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: <20241216-sysfs-const-bin_attr-powerpc-v1-3-bbed8906f476@weissschuh.net> References: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan 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=1734322065; l=1354; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=lpG1ThR/8HH372NAoQFJS0Y3lxzTHbVf7kKGZfLomkc=; b=FR6JUSEBPQc3U3GGSnGW9IVHs/F4mGUD0E0I92qZILVDo9mi57GtkSXWbOOTSE0CLhtga7jBb uj4m3AdQMHfA7/3Q+odV/9RDms/AMYC661n9V0oi8z9qQYG0IepYkRi 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 --- arch/powerpc/platforms/powernv/ultravisor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/powernv/ultravisor.c b/arch/powerpc/pla= tforms/powernv/ultravisor.c index 67c8c4b2d8b17c3662507121e97f48587d3ef82b..157d9a8134e445ed22be8ae58ff= 9181b45ac7ff0 100644 --- a/arch/powerpc/platforms/powernv/ultravisor.c +++ b/arch/powerpc/platforms/powernv/ultravisor.c @@ -32,15 +32,15 @@ int __init early_init_dt_scan_ultravisor(unsigned long = node, const char *uname, static struct memcons *uv_memcons; =20 static ssize_t uv_msglog_read(struct file *file, struct kobject *kobj, - struct bin_attribute *bin_attr, char *to, + const struct bin_attribute *bin_attr, char *to, loff_t pos, size_t count) { return memcons_copy(uv_memcons, to, pos, count); } =20 -static struct bin_attribute uv_msglog_attr =3D { +static struct bin_attribute uv_msglog_attr __ro_after_init =3D { .attr =3D {.name =3D "msglog", .mode =3D 0400}, - .read =3D uv_msglog_read + .read_new =3D uv_msglog_read }; =20 static int __init uv_init(void) --=20 2.47.1 From nobody Mon Feb 9 03:59:01 2026 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 B2BA22E401 for ; Mon, 16 Dec 2024 04:07:48 +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=1734322072; cv=none; b=Zg3uf7oDzqfX0u1qjr2at00cn7srCjJtYWXOUG/bhOS+biY/c/HV4DQ9QP1f9q2h9bqlRmQd6P2t4t4nh7aaCkiDoExm6wSsJSiRRdFfoyomt0DmmWbWFnVm8A/BwEcz8tmsAWzLPdbQw3278qL5D94TcW3OzAV7Yq3DEmZ8Jbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734322072; c=relaxed/simple; bh=xVlfF3vwhCOzCWvL8Ii8hOh/IkFAQglYuNvWAMyTYs8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q7dDrEIdE/RfurTMh7sE0oS93PkM3iNATlIxeoRnw40J1G+WegEwjWogCFkn4V3YfLiFS4JYVXht3LTIb3cOB/94igcO8U6d1xfDD3NpuzaT1x7b9/kgPNd4IGjsvSXOiXQwh/UYAZa9rO+Yb/dWDqJ/z/lsG3g7fI6hgQkANuE= 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=lVyEtQL9; 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="lVyEtQL9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734322066; bh=xVlfF3vwhCOzCWvL8Ii8hOh/IkFAQglYuNvWAMyTYs8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lVyEtQL94BGDrg733MzGrad3i6Ww9VapAuG8dBIxraCIbivycNs0p2YIoGAdSquk1 eWXKJhSyNFvnB4wDmdQW/IJkWkWTmRSNYMLX5ZdjH4qdQD7bdQEwRWa5W7aoxnfuPS QOR1l8oJM0tgfbDdh9yg7WpMaSg6V/ADiAO26qFA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 05:07:46 +0100 Subject: [PATCH 4/5] powerpc/powernv/opal: 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: <20241216-sysfs-const-bin_attr-powerpc-v1-4-bbed8906f476@weissschuh.net> References: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan 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=1734322065; l=6045; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=xVlfF3vwhCOzCWvL8Ii8hOh/IkFAQglYuNvWAMyTYs8=; b=v+ZhvbX5ifsO6BpGDVoed2HvRqEPe6UBGxRFwd+zOtrS9MgvHfZXvenQJPZAuot4SPRQeyWC3 hj3BdHTiZipCkeeYL/LkPyyHk8KBrNUvIW3/IWMZTVIubSF5Xlwrzio 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 --- arch/powerpc/platforms/powernv/opal-core.c | 10 +++++----- arch/powerpc/platforms/powernv/opal-dump.c | 4 ++-- arch/powerpc/platforms/powernv/opal-elog.c | 4 ++-- arch/powerpc/platforms/powernv/opal-flash.c | 4 ++-- arch/powerpc/platforms/powernv/opal-msglog.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal-core.c b/arch/powerpc/plat= forms/powernv/opal-core.c index c9a9b759cc928b931a0ac18f7ed7469a6ecd52b5..d95a5f67211b73724d61a040433= 6a32116872527 100644 --- a/arch/powerpc/platforms/powernv/opal-core.c +++ b/arch/powerpc/platforms/powernv/opal-core.c @@ -159,7 +159,7 @@ static Elf64_Word *__init auxv_to_elf64_notes(Elf64_Wor= d *buf, * Returns number of bytes read on success, -errno on failure. */ static ssize_t read_opalcore(struct file *file, struct kobject *kobj, - struct bin_attribute *bin_attr, char *to, + const struct bin_attribute *bin_attr, char *to, loff_t pos, size_t count) { struct opalcore *m; @@ -206,9 +206,9 @@ static ssize_t read_opalcore(struct file *file, struct = kobject *kobj, return (tpos - pos); } =20 -static struct bin_attribute opal_core_attr =3D { +static struct bin_attribute opal_core_attr __ro_after_init =3D { .attr =3D {.name =3D "core", .mode =3D 0400}, - .read =3D read_opalcore + .read_new =3D read_opalcore }; =20 /* @@ -599,7 +599,7 @@ static struct attribute *mpipl_attr[] =3D { NULL, }; =20 -static struct bin_attribute *mpipl_bin_attr[] =3D { +static const struct bin_attribute *const mpipl_bin_attr[] =3D { &opal_core_attr, NULL, =20 @@ -607,7 +607,7 @@ static struct bin_attribute *mpipl_bin_attr[] =3D { =20 static const struct attribute_group mpipl_group =3D { .attrs =3D mpipl_attr, - .bin_attrs =3D mpipl_bin_attr, + .bin_attrs_new =3D mpipl_bin_attr, }; =20 static int __init opalcore_init(void) diff --git a/arch/powerpc/platforms/powernv/opal-dump.c b/arch/powerpc/plat= forms/powernv/opal-dump.c index 608e4b68c5ea9d1610e2270b1ba08ed12b69860e..27e25693cf3990e4f53687d3835= 5c4f4c0a7d8c5 100644 --- a/arch/powerpc/platforms/powernv/opal-dump.c +++ b/arch/powerpc/platforms/powernv/opal-dump.c @@ -286,7 +286,7 @@ static int64_t dump_read_data(struct dump_obj *dump) } =20 static ssize_t dump_attr_read(struct file *filep, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { ssize_t rc; @@ -342,7 +342,7 @@ static void create_dump_obj(uint32_t id, size_t size, u= int32_t type) dump->dump_attr.attr.name =3D "dump"; dump->dump_attr.attr.mode =3D 0400; dump->dump_attr.size =3D size; - dump->dump_attr.read =3D dump_attr_read; + dump->dump_attr.read_new =3D dump_attr_read; =20 dump->id =3D id; dump->size =3D size; diff --git a/arch/powerpc/platforms/powernv/opal-elog.c b/arch/powerpc/plat= forms/powernv/opal-elog.c index 5db1e733143bfa8c7cb4bda1ab604e825b3f176f..de33f354e9fdd1440f39407aecf= 1e7085e9b52df 100644 --- a/arch/powerpc/platforms/powernv/opal-elog.c +++ b/arch/powerpc/platforms/powernv/opal-elog.c @@ -156,7 +156,7 @@ static const struct kobj_type elog_ktype =3D { #define OPAL_MAX_ERRLOG_SIZE 16384 =20 static ssize_t raw_attr_read(struct file *filep, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { int opal_rc; @@ -203,7 +203,7 @@ static void create_elog_obj(uint64_t id, size_t size, u= int64_t type) elog->raw_attr.attr.name =3D "raw"; elog->raw_attr.attr.mode =3D 0400; elog->raw_attr.size =3D size; - elog->raw_attr.read =3D raw_attr_read; + elog->raw_attr.read_new =3D raw_attr_read; =20 elog->id =3D id; elog->size =3D size; diff --git a/arch/powerpc/platforms/powernv/opal-flash.c b/arch/powerpc/pla= tforms/powernv/opal-flash.c index d5ea04e8e4c526b99ca8f1ab613266b385362d82..fd8c8621e97340cdf5570d72ce8= 2f86516cb2786 100644 --- a/arch/powerpc/platforms/powernv/opal-flash.c +++ b/arch/powerpc/platforms/powernv/opal-flash.c @@ -432,7 +432,7 @@ static int alloc_image_buf(char *buffer, size_t count) * and pre-allocate required memory. */ static ssize_t image_data_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buffer, loff_t pos, size_t count) { int rc; @@ -493,7 +493,7 @@ static ssize_t image_data_write(struct file *filp, stru= ct kobject *kobj, static const struct bin_attribute image_data_attr =3D { .attr =3D {.name =3D "image", .mode =3D 0200}, .size =3D MAX_IMAGE_SIZE, /* Limit image size */ - .write =3D image_data_write, + .write_new =3D image_data_write, }; =20 static struct kobj_attribute validate_attribute =3D diff --git a/arch/powerpc/platforms/powernv/opal-msglog.c b/arch/powerpc/pl= atforms/powernv/opal-msglog.c index 22d6efe17b0d01223d1c216a9fb21203a350bddf..f1988d0ab45ce49f09f47c9e885= 9cc5dfcee3a6d 100644 --- a/arch/powerpc/platforms/powernv/opal-msglog.c +++ b/arch/powerpc/platforms/powernv/opal-msglog.c @@ -94,15 +94,15 @@ ssize_t opal_msglog_copy(char *to, loff_t pos, size_t c= ount) } =20 static ssize_t opal_msglog_read(struct file *file, struct kobject *kobj, - struct bin_attribute *bin_attr, char *to, + const struct bin_attribute *bin_attr, char *to, loff_t pos, size_t count) { return opal_msglog_copy(to, pos, count); } =20 -static struct bin_attribute opal_msglog_attr =3D { +static struct bin_attribute opal_msglog_attr __ro_after_init =3D { .attr =3D {.name =3D "msglog", .mode =3D 0400}, - .read =3D opal_msglog_read + .read_new =3D opal_msglog_read }; =20 struct memcons *__init memcons_init(struct device_node *node, const char *= mc_prop_name) --=20 2.47.1 From nobody Mon Feb 9 03:59:01 2026 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 5313B1BE23F for ; Mon, 16 Dec 2024 04:07:53 +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=1734322075; cv=none; b=bmSR1TA4bgX1OtSVPgI33Ru+fk2JiVaZRjq84/j24mc7fOuty4JzDrB04EH12P2BpCytUlEj336x7CvbER0+QA4ONfnxGpzGMcpYU71nZ6XR/pO7nyZ2AqHeaur7SxRTsGH8wp7M5OeghqYCo3Yo1VJCWOzLqNW+osyirlh0h1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734322075; c=relaxed/simple; bh=kSKaIzakyLMOLTGavl1YigRi/jhUzDBr+KHmuegXLT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Obd+6fB3LN9E4N3dHlUKNddpHGMPtkenb/2RqIv174X6IHJf2CWhCxDSBkA8VkUBOk0ZwYnN6n9XkJe4PZLkaJQGWWn1coNAAi+lWn+qApxhHu7bEgwqv45HB6NELuuafQe8pxCT0yZlhPTq7D8Ic2YAJGjOSmdEFC5WcMPHdgw= 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=BadyMFb6; 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="BadyMFb6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734322066; bh=kSKaIzakyLMOLTGavl1YigRi/jhUzDBr+KHmuegXLT0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BadyMFb61RzPUtsPOslUvj2r9ugXcqC+cwewH7uzQHDSTD4ypCnzfheaLXoLct+XU 3a37PgP5LYlGYqX1Mw+ZU52qb2ow3Z1aB47tmlmDcplSGHIhppUK6lM7W+HMdWKMuW dDOYQrmdm5wKKVXVoAMjb6BSRgZNFMbPVAvKlgT4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 05:07:47 +0100 Subject: [PATCH 5/5] powerpc/perf/hv-24x7: 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: <20241216-sysfs-const-bin_attr-powerpc-v1-5-bbed8906f476@weissschuh.net> References: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> In-Reply-To: <20241216-sysfs-const-bin_attr-powerpc-v1-0-bbed8906f476@weissschuh.net> To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan 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=1734322065; l=1832; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=kSKaIzakyLMOLTGavl1YigRi/jhUzDBr+KHmuegXLT0=; b=nxzBc5603KmXdcAfj1ul0CWTZ3mnR0agqe30xCjxbiQhQeU50/tSIF00ai6WtgSME2KlEmf4V y4S8KHR5rTBDpW291Kll/z1PKPHWSHp+5aDhibQSkoSY20ZK4n2g9ox 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 --- arch/powerpc/perf/hv-24x7.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c index d400fa391c2765cf201ee4dc754007e655cc74ca..b0768f3d289300826dcd454a8e3= 97a943572fd45 100644 --- a/arch/powerpc/perf/hv-24x7.c +++ b/arch/powerpc/perf/hv-24x7.c @@ -998,7 +998,7 @@ static int create_events_from_catalog(struct attribute = ***events_, } =20 static ssize_t catalog_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t offset, size_t count) { long hret; @@ -1108,14 +1108,14 @@ PAGE_0_ATTR(catalog_version, "%lld\n", (unsigned long long)be64_to_cpu(page_0->version)); PAGE_0_ATTR(catalog_len, "%lld\n", (unsigned long long)be32_to_cpu(page_0->length) * 4096); -static BIN_ATTR_RO(catalog, 0/* real length varies */); +static const BIN_ATTR_RO(catalog, 0/* real length varies */); static DEVICE_ATTR_RO(domains); static DEVICE_ATTR_RO(sockets); static DEVICE_ATTR_RO(chipspersocket); static DEVICE_ATTR_RO(coresperchip); static DEVICE_ATTR_RO(cpumask); =20 -static struct bin_attribute *if_bin_attrs[] =3D { +static const struct bin_attribute *const if_bin_attrs[] =3D { &bin_attr_catalog, NULL, }; @@ -1141,7 +1141,7 @@ static struct attribute *if_attrs[] =3D { =20 static const struct attribute_group if_group =3D { .name =3D "interface", - .bin_attrs =3D if_bin_attrs, + .bin_attrs_new =3D if_bin_attrs, .attrs =3D if_attrs, }; =20 --=20 2.47.1