[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241202-sysfs-const-bin_attr-hid-v1-2-16369423a48a@weissschuh.net>
Date: Mon, 02 Dec 2024 20:01:33 +0100
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Jiri Kosina <jikos@...nel.org>, Benjamin Tissoires <bentiss@...nel.org>,
Stefan Achatz <erazor_de@...rs.sourceforge.net>
Cc: linux-input@...r.kernel.org, linux-kernel@...r.kernel.org,
Thomas Weißschuh <linux@...ssschuh.net>
Subject: [PATCH 02/10] HID: core: constify 'struct bin_attribute'
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 <linux@...ssschuh.net>
---
drivers/hid/hid-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index c7a8066061f621e80ec37f303d8a310d126569b4..10a71d6bd672566a43b2cde294ab42e35df367b6 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2175,7 +2175,7 @@ static bool hid_hiddev(struct hid_device *hdev)
static ssize_t
report_descriptor_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
+ const struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
@@ -2201,7 +2201,7 @@ country_show(struct device *dev, struct device_attribute *attr,
return sprintf(buf, "%02x\n", hdev->country & 0xff);
}
-static BIN_ATTR_RO(report_descriptor, HID_MAX_DESCRIPTOR_SIZE);
+static const BIN_ATTR_RO(report_descriptor, HID_MAX_DESCRIPTOR_SIZE);
static const DEVICE_ATTR_RO(country);
@@ -2793,13 +2793,13 @@ static struct attribute *hid_dev_attrs[] = {
&dev_attr_modalias.attr,
NULL,
};
-static struct bin_attribute *hid_dev_bin_attrs[] = {
+static const struct bin_attribute *hid_dev_bin_attrs[] = {
&bin_attr_report_descriptor,
NULL
};
static const struct attribute_group hid_dev_group = {
.attrs = hid_dev_attrs,
- .bin_attrs = hid_dev_bin_attrs,
+ .bin_attrs_new = hid_dev_bin_attrs,
};
__ATTRIBUTE_GROUPS(hid_dev);
--
2.47.1
Powered by blists - more mailing lists