From patchwork Mon Dec 2 19:04:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 846993 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 05FB11D958E; Mon, 2 Dec 2024 19:04:11 +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=1733166253; cv=none; b=kBI7Vk2D+TBDivsTfczw/BpYb++W96tRUaNcPbDPFDrnm+UUoyLTAgcvj+cx23oLMfNf2HHmCy3W4eymqCnF5BQnqsAlaNTIOvi2pjYDUvLklsQc4ptxcm6ak5xl3yDKxoKX2pf1XImWXUHSFTuAOBjmm+RHaXSq01tClpw9z0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166253; c=relaxed/simple; bh=s/bcJ0LBtQNLQMlmnLBuTDfzYiYUoVgtb9Rx7FMamO4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OC9a/EqhOx7/1XMOdisQ0qisvmv5UPBeGXl/djpb7hMb6U2oiCsdMx240hYphDl9PQJYyfiiM8VPMFsstjp1LAVQ6GzvxEn4xb8VNtzKuxT8lNHg2Cy2L8+Biy4om7KUD2pc7OaTQUpQdtUKEYniU7Y7gRMyXlOpvessPdFYKAw= 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=p5ZdpFJd; 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="p5ZdpFJd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166250; bh=s/bcJ0LBtQNLQMlmnLBuTDfzYiYUoVgtb9Rx7FMamO4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=p5ZdpFJdICUgCyVgmKl+X6L/gPNoWiIXmQwZaFL+00pHwGvBXfmvQL652ic3dehBi O9MJ1jxDI4k8uP1wEmO3m7Ap1XDQbEjKEBhKY5lMGOtMdIX0pQAt/JuEUxlTGcTqfR GdAutSxhP//Z8VUFIJuoqsR7gk6JGJ/7k3Jbr0ak= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:04:09 +0100 Subject: [PATCH 1/3] ACPI: BGRT: Mark bin_attribute as __ro_after_init Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-acpi-v1-1-78f3b38d350d@weissschuh.net> References: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166249; l=785; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=s/bcJ0LBtQNLQMlmnLBuTDfzYiYUoVgtb9Rx7FMamO4=; b=z4KHS12m9aEwQCmu78SR62Wvv+3TxbEzyQ5lbDOsS/X6FE+tn8y/Dc3wMvahxUTjF18EHmQAj klaI/d4DPSrCr4ZcDBMWM7RbhtHnFTifppDMdG9FUytVs4Xc1M7Wxbo X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The attribute is only modified during __init phase. Protect it against accidental or intentional modifications afterwards. Signed-off-by: Thomas Weißschuh --- drivers/acpi/bgrt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c index d1d9c9289087a1ca6b36e8497cb104bad3282737..88837c291a7630416f0ae3854d6d1a733a590961 100644 --- a/drivers/acpi/bgrt.c +++ b/drivers/acpi/bgrt.c @@ -29,7 +29,7 @@ BGRT_SHOW(type, image_type); BGRT_SHOW(xoffset, image_offset_x); BGRT_SHOW(yoffset, image_offset_y); -static BIN_ATTR_SIMPLE_RO(image); +static __ro_after_init BIN_ATTR_SIMPLE_RO(image); static struct attribute *bgrt_attributes[] = { &bgrt_attr_version.attr, From patchwork Mon Dec 2 19:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 846660 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 0604A1DED54; Mon, 2 Dec 2024 19:04:11 +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=1733166253; cv=none; b=g6Su/JO2WYZi1BVDLZ55WisD7hw8SgERnDpsSomlBmTRj8gtJDqy2IYn+zcGjxRNiKzczIAEsT3gjaK682c98CQt5PA+vE22VVrASewuFeAJnpwHSrNY6OVNTmIoXoeNZhhlmAh2IxztRIMLWNToLD4AJh80olfFSSZxdSV6VuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166253; c=relaxed/simple; bh=idHnkK7FE+k9jSjzZJTwT9vCEnNXD5HcnIgvlgtivw0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a2OBk9UvmPHqi1mmj1+I5z46pcZ+DEsCVK6lcDmQYkhRmaUl/kTwJwrJz/KT20yKMzVF/OGq1zJovDr1ge+XED76lU3NuwlbURps2bf/UlwW2M1R9yhV/s+0MhNHBUTinFch6UVj6FTASOXlHPCy94W3Fh5qSnbdfMEqGqp3YCY= 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=tjMwBUH3; 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="tjMwBUH3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166250; bh=idHnkK7FE+k9jSjzZJTwT9vCEnNXD5HcnIgvlgtivw0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tjMwBUH3vsaq40LH5EutpiDvDOJzXADuw0V4FvP8bnl9gY/wCKHr1x934oN+sbS1y lP3+DzkBRZZJXLWKRAAljtbFfqAvmHH/1AZM19n0SjPM1P8oA6dMsmqDVkkDiKHpPi mnR85mUcMJ1GWnL0kHtwkdW8P9BFVEXTdfP9QpPs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:04:10 +0100 Subject: [PATCH 2/3] ACPI: BGRT: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-acpi-v1-2-78f3b38d350d@weissschuh.net> References: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166249; l=1037; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=idHnkK7FE+k9jSjzZJTwT9vCEnNXD5HcnIgvlgtivw0=; b=9PbT6StwmGEjLZCXb7lS1nBuP/j1AjHMbaEmPq5Ompous68ttVqUEcSqih4kTrMQRrd5+SOgK dfSAgJfwvucCSsxLRFZOQDv3LNbivjanG2tz41NcYzR+bEglQ6qiiPQ 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ßschuh --- drivers/acpi/bgrt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c index 88837c291a7630416f0ae3854d6d1a733a590961..35ece8e9f15d1d15c224fb6879d48730898fa3df 100644 --- a/drivers/acpi/bgrt.c +++ b/drivers/acpi/bgrt.c @@ -40,14 +40,14 @@ static struct attribute *bgrt_attributes[] = { NULL, }; -static struct bin_attribute *bgrt_bin_attributes[] = { +static const struct bin_attribute *const bgrt_bin_attributes[] = { &bin_attr_image, NULL, }; static const struct attribute_group bgrt_attribute_group = { .attrs = bgrt_attributes, - .bin_attrs = bgrt_bin_attributes, + .bin_attrs_new = bgrt_bin_attributes, }; int __init acpi_parse_bgrt(struct acpi_table_header *table) From patchwork Mon Dec 2 19:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 846992 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 A502E1DED4E; Mon, 2 Dec 2024 19:04:11 +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=1733166253; cv=none; b=vCuFxHO42jaQ+IgfdqJRRoQB+Np5Q+KvU0vRmfYqu1/+31Zp/3YPEkFJvWKMEIUFhlLLxjqCfv+6J2ZeGZub3XPJZ3lLjDhKH6dNPwjczfvkHAc/Fq/zvh6qJ7erSzpyFXEIWbgagfzIjadc9DgYj8HGOP9mIHvtapFQ0LKvCow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166253; c=relaxed/simple; bh=gJ1ibdZq5DLD6ML91YfAivFjEZvpbtq1ja6dZ3n4Wf8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R0XIxHCHBVVvwEEXQI9Sdo1c+xuEVEUx4QVrUy6bdgl+FIxtnKVRxMWgqYLwjozdnKzp5yp6+SRG8+nK47a7H7KIMRHrrLAxMEhTI5sXZyudJ0LydPB8vPQxbnA6JyTO8PLaRtURTRb38VUSmYDNYx2NAbSoJmz9ZiFwRjStqxo= 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=SL9NqyaD; 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="SL9NqyaD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166250; bh=gJ1ibdZq5DLD6ML91YfAivFjEZvpbtq1ja6dZ3n4Wf8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SL9NqyaDt3u38FIX6iK+hmjPn/aA3LS3sfoEua5p+BMLYZtRlkSFmXm4RNDAt0xXJ zmps5aLd3AH2O0QENgh74CKVVV0ZHKe6JxnySj13lOtfVVjRv1W+8f9WVN0UCRjm/p Gn3Ay32JSn0DRgTLn63j+aCmR1q+O9akz+QX9cPA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:04:11 +0100 Subject: [PATCH 3/3] ACPI: sysfs: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-acpi-v1-3-78f3b38d350d@weissschuh.net> References: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-acpi-v1-0-78f3b38d350d@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166249; l=1940; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=gJ1ibdZq5DLD6ML91YfAivFjEZvpbtq1ja6dZ3n4Wf8=; b=Wx1C36bm9gP6DQ0RuCsGUwhtDnmDmTnluUEd43JfMdC3WB9zO5zBu/zJ/qmu/0n5jl55NTbYZ a59gQA39p/YAgCoEBUPL7OqNLB8iEFxkqb6+0W4iKamA+zFmsvNYmjB 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ßschuh --- drivers/acpi/sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index 687524b5008592c58c021f9c7981b76eaa58038f..a48ebbf768f91ab354cd276f1b4dda2c063ef9b5 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -319,7 +319,7 @@ struct acpi_data_attr { }; static ssize_t acpi_table_show(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) { struct acpi_table_attr *table_attr = @@ -372,7 +372,7 @@ static int acpi_table_attr_init(struct kobject *tables_obj, } table_attr->attr.size = table_header->length; - table_attr->attr.read = acpi_table_show; + table_attr->attr.read_new = acpi_table_show; table_attr->attr.attr.name = table_attr->filename; table_attr->attr.attr.mode = 0400; @@ -412,7 +412,7 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context) } static ssize_t acpi_data_show(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) { struct acpi_data_attr *data_attr; @@ -495,7 +495,7 @@ static int acpi_table_data_init(struct acpi_table_header *th) if (!data_attr) return -ENOMEM; sysfs_attr_init(&data_attr->attr.attr); - data_attr->attr.read = acpi_data_show; + data_attr->attr.read_new = acpi_data_show; data_attr->attr.attr.mode = 0400; return acpi_data_objs[i].fn(th, data_attr); }