]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: esas2r: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 16 Dec 2024 11:29:11 +0000 (12:29 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 2 Jan 2025 20:07:45 +0000 (15:07 -0500)
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/20241216-sysfs-const-bin_attr-scsi-v1-4-f0a5e54b3437@weissschuh.net
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/esas2r/esas2r.h
drivers/scsi/esas2r/esas2r_main.c

index 1e2d7c63a8e36a22bed3b365cd2e6eb81a3a4a1d..c48275d53aef3d45c0b8a1c38f5a21020ab33102 100644 (file)
@@ -1411,11 +1411,11 @@ static inline void esas2r_comp_list_drain(struct esas2r_adapter *a,
 }
 
 /* sysfs handlers */
-extern struct bin_attribute bin_attr_fw;
-extern struct bin_attribute bin_attr_fs;
-extern struct bin_attribute bin_attr_vda;
-extern struct bin_attribute bin_attr_hw;
-extern struct bin_attribute bin_attr_live_nvram;
-extern struct bin_attribute bin_attr_default_nvram;
+extern const struct bin_attribute bin_attr_fw;
+extern const struct bin_attribute bin_attr_fs;
+extern const struct bin_attribute bin_attr_vda;
+extern const struct bin_attribute bin_attr_hw;
+extern const struct bin_attribute bin_attr_live_nvram;
+extern const struct bin_attribute bin_attr_default_nvram;
 
 #endif /* ESAS2R_H */
index f700a16cd88534c1edc9fb0ed8ed8b8d1db4fe51..44871746944ad0c0f30f28975ed40e0fde4e8d03 100644 (file)
@@ -66,7 +66,7 @@ static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
 }
 
 static ssize_t read_fw(struct file *file, struct kobject *kobj,
-                      struct bin_attribute *attr,
+                      const struct bin_attribute *attr,
                       char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -75,7 +75,7 @@ static ssize_t read_fw(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t write_fw(struct file *file, struct kobject *kobj,
-                       struct bin_attribute *attr,
+                       const struct bin_attribute *attr,
                        char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -84,7 +84,7 @@ static ssize_t write_fw(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t read_fs(struct file *file, struct kobject *kobj,
-                      struct bin_attribute *attr,
+                      const struct bin_attribute *attr,
                       char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -93,7 +93,7 @@ static ssize_t read_fs(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t write_fs(struct file *file, struct kobject *kobj,
-                       struct bin_attribute *attr,
+                       const struct bin_attribute *attr,
                        char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -109,7 +109,7 @@ static ssize_t write_fs(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t read_vda(struct file *file, struct kobject *kobj,
-                       struct bin_attribute *attr,
+                       const struct bin_attribute *attr,
                        char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -118,7 +118,7 @@ static ssize_t read_vda(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t write_vda(struct file *file, struct kobject *kobj,
-                        struct bin_attribute *attr,
+                        const struct bin_attribute *attr,
                         char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -127,7 +127,7 @@ static ssize_t write_vda(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
-                              struct bin_attribute *attr,
+                              const struct bin_attribute *attr,
                               char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -138,7 +138,7 @@ static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t write_live_nvram(struct file *file, struct kobject *kobj,
-                               struct bin_attribute *attr,
+                               const struct bin_attribute *attr,
                                char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -158,7 +158,7 @@ static ssize_t write_live_nvram(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
-                                 struct bin_attribute *attr,
+                                 const struct bin_attribute *attr,
                                  char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -169,7 +169,7 @@ static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t read_hw(struct file *file, struct kobject *kobj,
-                      struct bin_attribute *attr,
+                      const struct bin_attribute *attr,
                       char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -187,7 +187,7 @@ static ssize_t read_hw(struct file *file, struct kobject *kobj,
 }
 
 static ssize_t write_hw(struct file *file, struct kobject *kobj,
-                       struct bin_attribute *attr,
+                       const struct bin_attribute *attr,
                        char *buf, loff_t off, size_t count)
 {
        struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -211,12 +211,12 @@ static ssize_t write_hw(struct file *file, struct kobject *kobj,
 }
 
 #define ESAS2R_RW_BIN_ATTR(_name) \
-       struct bin_attribute bin_attr_ ## _name = { \
+       const struct bin_attribute bin_attr_ ## _name = { \
                .attr   = \
                { .name = __stringify(_name), .mode  = S_IRUSR | S_IWUSR }, \
                .size   = 0, \
-               .read   = read_ ## _name, \
-               .write  = write_ ## _name }
+               .read_new       = read_ ## _name, \
+               .write_new      = write_ ## _name }
 
 ESAS2R_RW_BIN_ATTR(fw);
 ESAS2R_RW_BIN_ATTR(fs);
@@ -224,10 +224,10 @@ ESAS2R_RW_BIN_ATTR(vda);
 ESAS2R_RW_BIN_ATTR(hw);
 ESAS2R_RW_BIN_ATTR(live_nvram);
 
-struct bin_attribute bin_attr_default_nvram = {
+const struct bin_attribute bin_attr_default_nvram = {
        .attr   = { .name = "default_nvram", .mode = S_IRUGO },
        .size   = 0,
-       .read   = read_default_nvram,
+       .read_new       = read_default_nvram,
        .write  = NULL
 };