Skip to content

Commit

Permalink
Merge patch series "scsi: Constify 'struct bin_attribute'"
Browse files Browse the repository at this point in the history
Thomas Weißschuh <linux@weissschuh.net> says:

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.

Link: https://lore.kernel.org/r/20241216-sysfs-const-bin_attr-scsi-v1-0-f0a5e54b3437@weissschuh.net
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
martinkpetersen committed Jan 2, 2025
2 parents 1edc2a6 + ea4f221 commit ebbf01f
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 121 deletions.
12 changes: 6 additions & 6 deletions drivers/scsi/3w-sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int twl_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_res

/* This function returns AENs through sysfs */
static ssize_t twl_sysfs_aen_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *outbuf, loff_t offset, size_t count)
{
struct device *dev = container_of(kobj, struct device, kobj);
Expand All @@ -116,18 +116,18 @@ static ssize_t twl_sysfs_aen_read(struct file *filp, struct kobject *kobj,
} /* End twl_sysfs_aen_read() */

/* aen_read sysfs attribute initializer */
static struct bin_attribute twl_sysfs_aen_read_attr = {
static const struct bin_attribute twl_sysfs_aen_read_attr = {
.attr = {
.name = "3ware_aen_read",
.mode = S_IRUSR,
},
.size = 0,
.read = twl_sysfs_aen_read
.read_new = twl_sysfs_aen_read
};

/* This function returns driver compatibility info through sysfs */
static ssize_t twl_sysfs_compat_info(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *outbuf, loff_t offset, size_t count)
{
struct device *dev = container_of(kobj, struct device, kobj);
Expand All @@ -147,13 +147,13 @@ static ssize_t twl_sysfs_compat_info(struct file *filp, struct kobject *kobj,
} /* End twl_sysfs_compat_info() */

/* compat_info sysfs attribute initializer */
static struct bin_attribute twl_sysfs_compat_info_attr = {
static const struct bin_attribute twl_sysfs_compat_info_attr = {
.attr = {
.name = "3ware_compat_info",
.mode = S_IRUSR,
},
.size = 0,
.read = twl_sysfs_compat_info
.read_new = twl_sysfs_compat_info
};

/* Show some statistics about the card */
Expand Down
12 changes: 6 additions & 6 deletions drivers/scsi/arcmsr/arcmsr_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin,
const struct bin_attribute *bin,
char *buf, loff_t off,
size_t count)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,

static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin,
const struct bin_attribute *bin,
char *buf, loff_t off,
size_t count)
{
Expand Down Expand Up @@ -155,7 +155,7 @@ static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,

static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin,
const struct bin_attribute *bin,
char *buf, loff_t off,
size_t count)
{
Expand Down Expand Up @@ -194,7 +194,7 @@ static const struct bin_attribute arcmsr_sysfs_message_read_attr = {
.mode = S_IRUSR ,
},
.size = ARCMSR_API_DATA_BUFLEN,
.read = arcmsr_sysfs_iop_message_read,
.read_new = arcmsr_sysfs_iop_message_read,
};

static const struct bin_attribute arcmsr_sysfs_message_write_attr = {
Expand All @@ -203,7 +203,7 @@ static const struct bin_attribute arcmsr_sysfs_message_write_attr = {
.mode = S_IWUSR,
},
.size = ARCMSR_API_DATA_BUFLEN,
.write = arcmsr_sysfs_iop_message_write,
.write_new = arcmsr_sysfs_iop_message_write,
};

static const struct bin_attribute arcmsr_sysfs_message_clear_attr = {
Expand All @@ -212,7 +212,7 @@ static const struct bin_attribute arcmsr_sysfs_message_clear_attr = {
.mode = S_IWUSR,
},
.size = 1,
.write = arcmsr_sysfs_iop_message_clear,
.write_new = arcmsr_sysfs_iop_message_clear,
};

int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb)
Expand Down
12 changes: 6 additions & 6 deletions drivers/scsi/esas2r/esas2r.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
32 changes: 16 additions & 16 deletions drivers/scsi/esas2r/esas2r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -211,23 +211,23 @@ 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);
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
};

Expand Down
6 changes: 3 additions & 3 deletions drivers/scsi/ibmvscsi/ibmvfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3641,7 +3641,7 @@ static DEVICE_ATTR(nr_scsi_channels, S_IRUGO | S_IWUSR,
* number of bytes printed to buffer
**/
static ssize_t ibmvfc_read_trace(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
Expand All @@ -3664,13 +3664,13 @@ static ssize_t ibmvfc_read_trace(struct file *filp, struct kobject *kobj,
return count;
}

static struct bin_attribute ibmvfc_trace_attr = {
static const struct bin_attribute ibmvfc_trace_attr = {
.attr = {
.name = "trace",
.mode = S_IRUGO,
},
.size = 0,
.read = ibmvfc_read_trace,
.read_new = ibmvfc_read_trace,
};
#endif

Expand Down
26 changes: 13 additions & 13 deletions drivers/scsi/ipr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3366,7 +3366,7 @@ static void ipr_worker_thread(struct work_struct *work)
* number of bytes printed to buffer
**/
static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *dev = kobj_to_dev(kobj);
Expand All @@ -3383,13 +3383,13 @@ static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
return ret;
}

static struct bin_attribute ipr_trace_attr = {
static const struct bin_attribute ipr_trace_attr = {
.attr = {
.name = "trace",
.mode = S_IRUGO,
},
.size = 0,
.read = ipr_read_trace,
.read_new = ipr_read_trace,
};
#endif

Expand Down Expand Up @@ -4087,7 +4087,7 @@ static struct device_attribute ipr_ioa_fw_type_attr = {
};

static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct device *cdev = kobj_to_dev(kobj);
Expand All @@ -4111,7 +4111,7 @@ static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj,
}

static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
const struct bin_attribute *bin_attr, char *buf,
loff_t off, size_t count)
{
struct device *cdev = kobj_to_dev(kobj);
Expand All @@ -4134,14 +4134,14 @@ static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj,
return count;
}

static struct bin_attribute ipr_ioa_async_err_log = {
static const struct bin_attribute ipr_ioa_async_err_log = {
.attr = {
.name = "async_err_log",
.mode = S_IRUGO | S_IWUSR,
},
.size = 0,
.read = ipr_read_async_err_log,
.write = ipr_next_async_err_log
.read_new = ipr_read_async_err_log,
.write_new = ipr_next_async_err_log
};

static struct attribute *ipr_ioa_attrs[] = {
Expand Down Expand Up @@ -4172,7 +4172,7 @@ ATTRIBUTE_GROUPS(ipr_ioa);
* number of bytes printed to buffer
**/
static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *cdev = kobj_to_dev(kobj);
Expand Down Expand Up @@ -4361,7 +4361,7 @@ static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
* number of bytes printed to buffer
**/
static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
const struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *cdev = kobj_to_dev(kobj);
Expand All @@ -4385,14 +4385,14 @@ static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
return count;
}

static struct bin_attribute ipr_dump_attr = {
static const struct bin_attribute ipr_dump_attr = {
.attr = {
.name = "dump",
.mode = S_IRUSR | S_IWUSR,
},
.size = 0,
.read = ipr_read_dump,
.write = ipr_write_dump
.read_new = ipr_read_dump,
.write_new = ipr_write_dump
};
#else
static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
Expand Down
Loading

0 comments on commit ebbf01f

Please sign in to comment.