From nobody Wed May 14 03:22:36 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=weissschuh.net ARC-Seal: i=1; a=rsa-sha256; t=1736891502; cv=none; d=zohomail.com; s=zohoarc; b=VtRTAaJ/nxQ1NexYL0uqG9DL36BskOIHeeHzJagqVewSFFLlAmi9+BWmQ0EFI6jz2kmQH9rZ5SnCE7UE6rhNKdUNZx002LU4orQzHCkc9+qoghukHDVcklgm5DUpXnaIIZ6MKwyisK2LJgq/uzWjxSx/jnDeNwYquVOEnoKg7BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736891502; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LFrenJqXSsAubWRwB5HsAuWscxji5S6+dGWIG2fFyUo=; b=OFmTNtfYGVFUFE4Gdg+Hd/SMKOOPpKzkAIIjVpDNI73bVSbQVQiD+qN/lTHvfJuzxtG6HcN60o6RjHyasDlWCrx9waHLD+2IwZh4LMGO8y0Dmtbc4Es+KpeuiBX0Ur76ADINW3Rui935OclvCShqbxFSY5ZrdWgwLJ7YwbFUwZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from=<linux@weissschuh.net> (p=quarantine dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736891502916663.0613222888002; Tue, 14 Jan 2025 13:51:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1tXooD-0000rv-Ft; Tue, 14 Jan 2025 16:50:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <linux@weissschuh.net>) id 1tXooB-0000rT-F6 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 16:50:47 -0500 Received: from todd.t-8ch.de ([2a01:4f8:c010:41de::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <linux@weissschuh.net>) id 1tXoo8-0003fx-6I for qemu-devel@nongnu.org; Tue, 14 Jan 2025 16:50:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1736891435; bh=uRwcJb3TjICUyPhUz/VimhDyFmB/p85NF8kCEbSI6rU=; h=From:Date:Subject:To:Cc:From; b=an8fopgQswiF/V2vvDZ1FiwbUwKXGQM27ZNAOzPSnKSKA55W3uWa1zfB7ePccxYuM JQzRrC7Z4SUkPaRVyWbjhytKLNfUbx7v8WdAZqpnbxhSQOrtPLTtTyubWD1AVsefcm HGs0ARVySZvBqf/gZlR89Vv7lzHTdJVslkBC10Ps= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Date: Tue, 14 Jan 2025 22:50:20 +0100 Subject: [PATCH] firmware: qemu_fw_cfg: constify 'struct bin_attribute' MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250114-sysfs-const-bin_attr-qemu_fw_cfg-v1-1-76f525a3ee72@weissschuh.net> X-B4-Tracking: v=1; b=H4sIABvchmcC/x3NPQ7DIAxA4atEnmsJUjLQq1QVotROPIQkmP4py t2LOn7LezsoFSGFS7dDoZeoLLnBnjpIU8wjoTyaoTf9YKx1qF9lxbRkrXiXHGKtBTean4HfIfG IHF30gz87bxy0zFqI5fNfXG/H8QMxw/qBcgAAAA== X-Change-ID: 20250114-sysfs-const-bin_attr-qemu_fw_cfg-fa4a95934904 To: Gabriel Somlo <somlo@cmu.edu>, "Michael S. Tsirkin" <mst@redhat.com> Cc: qemu-devel@nongnu.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736891434; l=1599; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=uRwcJb3TjICUyPhUz/VimhDyFmB/p85NF8kCEbSI6rU=; b=V9U8C+VpPf8QiCxoM33e4TVTUFnByc39D1XF6YXt5z3hK4HZlNwyy/pmUlQFi4gXxOpgsOWbv 4u8avJbXg2EBaUus0gzBwtySCHum5JEP4KdqTN2puzdjjO3uIIXT34m X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a01:4f8:c010:41de::1; envelope-from=linux@weissschuh.net; helo=todd.t-8ch.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @weissschuh.net) X-ZM-MESSAGEID: 1736891505590019000 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 <linux@weissschuh.net> Acked-by: Gabriel Somlo <somlo@cmu.edu> Acked-by: Michael S. Tsirkin <mst@redhat.com> --- drivers/firmware/qemu_fw_cfg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index d58da3e4500a5e230b7da9a75e4d70df7c38c542..2615fb780e3c4500db36d474688= 0455f05479f1f 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -460,7 +460,7 @@ static const struct kobj_type fw_cfg_sysfs_entry_ktype = =3D { =20 /* raw-read method and attribute */ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp, struct kobject *ko= bj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct fw_cfg_sysfs_entry *entry =3D to_entry(kobj); @@ -474,9 +474,9 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp,= struct kobject *kobj, return fw_cfg_read_blob(entry->select, buf, pos, count); } =20 -static struct bin_attribute fw_cfg_sysfs_attr_raw =3D { +static const struct bin_attribute fw_cfg_sysfs_attr_raw =3D { .attr =3D { .name =3D "raw", .mode =3D S_IRUSR }, - .read =3D fw_cfg_sysfs_read_raw, + .read_new =3D fw_cfg_sysfs_read_raw, }; =20 /* --- base-commit: 7f5b6a8ec18e3add4c74682f60b90c31bdf849f2 change-id: 20250114-sysfs-const-bin_attr-qemu_fw_cfg-fa4a95934904 Best regards, --=20 Thomas Wei=C3=9Fschuh <linux@weissschuh.net>