devcoredump: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 14 Jan 2025 21:44:59 +0000 (22:44 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Jan 2025 17:30:58 +0000 (18:30 +0100)
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@weissschuh.net>
Link: https://lore.kernel.org/r/20250114-sysfs-const-bin_attr-devcoredump-v1-2-fa93be30efae@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/devcoredump.c

index 4b1f7a6cee52769028c7ee9503dbf0428f521c35..64840e5d5fcc91c5d72e552c41afa8fcb8b0c943 100644 (file)
@@ -106,7 +106,7 @@ static void devcd_del(struct work_struct *wk)
 }
 
 static ssize_t devcd_data_read(struct file *filp, struct kobject *kobj,
-                              struct bin_attribute *bin_attr,
+                              const struct bin_attribute *bin_attr,
                               char *buffer, loff_t offset, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -116,7 +116,7 @@ static ssize_t devcd_data_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buffer, loff_t offset, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -132,15 +132,15 @@ static ssize_t devcd_data_write(struct file *filp, struct kobject *kobj,
        return count;
 }
 
-static struct bin_attribute devcd_attr_data =
+static const struct bin_attribute devcd_attr_data =
        __BIN_ATTR(data, 0600, devcd_data_read, devcd_data_write, 0);
 
-static struct bin_attribute *devcd_dev_bin_attrs[] = {
+static const struct bin_attribute *const devcd_dev_bin_attrs[] = {
        &devcd_attr_data, NULL,
 };
 
 static const struct attribute_group devcd_dev_group = {
-       .bin_attrs = devcd_dev_bin_attrs,
+       .bin_attrs_new = devcd_dev_bin_attrs,
 };
 
 static const struct attribute_group *devcd_dev_groups[] = {