]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
firmware_loader: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 22 Dec 2024 20:20:50 +0000 (21:20 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jan 2025 09:15:11 +0000 (10:15 +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>
Reviewed-by: Russ Weight <russ.weight@linux.dev>
Link: https://lore.kernel.org/r/20241222-sysfs-const-bin_attr-firmware-v1-1-c35e56bfb4eb@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/firmware_loader/sysfs.c

index c9c93b47d9a519aa2e32e368e4b930dd05d16f0c..d254ceb56d8434e80085dcb4fdef2752582cdab8 100644 (file)
@@ -259,7 +259,7 @@ static void firmware_rw(struct fw_priv *fw_priv, char *buffer,
 }
 
 static ssize_t firmware_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);
@@ -316,7 +316,7 @@ static int fw_realloc_pages(struct fw_sysfs *fw_sysfs, int min_size)
  *     the driver as a firmware image.
  **/
 static ssize_t firmware_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);
@@ -356,11 +356,11 @@ out:
        return retval;
 }
 
-static struct bin_attribute firmware_attr_data = {
+static const struct bin_attribute firmware_attr_data = {
        .attr = { .name = "data", .mode = 0644 },
        .size = 0,
-       .read = firmware_data_read,
-       .write = firmware_data_write,
+       .read_new = firmware_data_read,
+       .write_new = firmware_data_write,
 };
 
 static struct attribute *fw_dev_attrs[] = {
@@ -374,14 +374,14 @@ static struct attribute *fw_dev_attrs[] = {
        NULL
 };
 
-static struct bin_attribute *fw_dev_bin_attrs[] = {
+static const struct bin_attribute *const fw_dev_bin_attrs[] = {
        &firmware_attr_data,
        NULL
 };
 
 static const struct attribute_group fw_dev_attr_group = {
        .attrs = fw_dev_attrs,
-       .bin_attrs = fw_dev_bin_attrs,
+       .bin_attrs_new = fw_dev_bin_attrs,
 #ifdef CONFIG_FW_UPLOAD
        .is_visible = fw_upload_is_visible,
 #endif