From nobody Wed Dec 4 19:20:32 2024 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 11C3E1DE4FC for ; Mon, 2 Dec 2024 19:43:28 +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=1733168610; cv=none; b=VOjjKrUf6UwA/TIgy5AwwPx1iy7N/8xR0x3T49tMKhI8gFdXsQRp1XKyKU/B3q29o0CELE38KGld7Bwlm+ioz9vPTS60GJhOgJaBafo7dsq8h1QWUU7zP1MOSaNq9HP6GA0k/VXnocz8abaNNcByZFJsZvOIYEcdviIe4VOwkIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733168610; c=relaxed/simple; bh=n1+D0i8OXR5P0ydgsCj6+rtw09x6rt1HAh8gDChLLsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=H2JdN52ZskLZDwsHrMhU3V4dqjiutJsaCcHp1Ss+tNSk6uNN8It7GvSiqKCCkWQ7d2GuG7nGON8zrUkPLsYfFfyQEalN9HmK5sSbWNym8iMjyWYcJIF62a6AkHO6kJg9IJtEYazsyfDmRY8K9EhFNDb34tJEHUxKB0vkrgn1U80= 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=OPYr2Vd9; 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="OPYr2Vd9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733168607; bh=n1+D0i8OXR5P0ydgsCj6+rtw09x6rt1HAh8gDChLLsU=; h=From:Date:Subject:To:Cc:From; b=OPYr2Vd9yjk1lS7rif5qQ+wqUHvlzWYZodHeE5abVLYY6W9BZxYShZE6yONeKH4tl JZdSAQG0ITrmyggAIElzHT+OlMoxdepfmwM4XbBvk7yLOFZ6FkMGEkJ/+kU+f/romH qaQcdQzD16dcMRrpc8XK2wozM9+qHfKIk5d9N0gg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:43:24 +0100 Subject: [PATCH] x86/sysfs: 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: <20241202-sysfs-const-bin_attr-x86-v1-1-b767d5f0ac5c@weissschuh.net> X-B4-Tracking: v=1; b=H4sIANsNTmcC/x2MQQqAIBAAvxJ7biGtJPpKRJSttRcLV8KI/p50G ZjDzANCgUmgLx4IdLHw4bOosgC7z34j5DU76Eo3KgPlFidoDy8RF/bTHGPA1BlsVaeaWjtrjIO cn4Ecp389jO/7Ad8nmEdqAAAA X-Change-ID: 20241202-sysfs-const-bin_attr-x86-5181432fc66f To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: 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=1733168606; l=3110; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=n1+D0i8OXR5P0ydgsCj6+rtw09x6rt1HAh8gDChLLsU=; b=lVyHsqTz0gZAHaPIJmbBZkmCnDqrN2VKi8cJIoDwx04pUrp+d/mlHI8bezXtSozynZ0eZASxn bjU4jd6w9nDDArKwqRh+WAfBfS/1SWDmg0sRcEBDG+Xx7s5ROKgdFXr 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/x86/kernel/ksysfs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c index 257892fcefa794803d8eaf2d3d1810ebb278957b..b68d4be9464efab13b808fd6909= 2003a89b5612b 100644 --- a/arch/x86/kernel/ksysfs.c +++ b/arch/x86/kernel/ksysfs.c @@ -28,19 +28,19 @@ static ssize_t version_show(struct kobject *kobj, static struct kobj_attribute boot_params_version_attr =3D __ATTR_RO(versio= n); =20 static ssize_t boot_params_data_read(struct file *fp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { memcpy(buf, (void *)&boot_params + off, count); return count; } =20 -static struct bin_attribute boot_params_data_attr =3D { +static const struct bin_attribute boot_params_data_attr =3D { .attr =3D { .name =3D "data", .mode =3D S_IRUGO, }, - .read =3D boot_params_data_read, + .read_new =3D boot_params_data_read, .size =3D sizeof(boot_params), }; =20 @@ -49,14 +49,14 @@ static struct attribute *boot_params_version_attrs[] = =3D { NULL, }; =20 -static struct bin_attribute *boot_params_data_attrs[] =3D { +static const struct bin_attribute *const boot_params_data_attrs[] =3D { &boot_params_data_attr, NULL, }; =20 static const struct attribute_group boot_params_attr_group =3D { .attrs =3D boot_params_version_attrs, - .bin_attrs =3D boot_params_data_attrs, + .bin_attrs_new =3D boot_params_data_attrs, }; =20 static int kobj_to_setup_data_nr(struct kobject *kobj, int *nr) @@ -172,7 +172,7 @@ static ssize_t type_show(struct kobject *kobj, =20 static ssize_t setup_data_data_read(struct file *fp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { @@ -250,7 +250,7 @@ static struct bin_attribute data_attr __ro_after_init = =3D { .name =3D "data", .mode =3D S_IRUGO, }, - .read =3D setup_data_data_read, + .read_new =3D setup_data_data_read, }; =20 static struct attribute *setup_data_type_attrs[] =3D { @@ -258,14 +258,14 @@ static struct attribute *setup_data_type_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *setup_data_data_attrs[] =3D { +static const struct bin_attribute *const setup_data_data_attrs[] =3D { &data_attr, NULL, }; =20 static const struct attribute_group setup_data_attr_group =3D { .attrs =3D setup_data_type_attrs, - .bin_attrs =3D setup_data_data_attrs, + .bin_attrs_new =3D setup_data_data_attrs, }; =20 static int __init create_setup_data_node(struct kobject *parent, --- base-commit: e70140ba0d2b1a30467d4af6bcfe761327b9ec95 change-id: 20241202-sysfs-const-bin_attr-x86-5181432fc66f Best regards, --=20 Thomas Wei=C3=9Fschuh