Skip to contentSkip to conversation

scsi: Correct sysfs attributes access rights

PATCH Applied Damien Le Moal 4 participants 7 messages Jul 28, 2025 – Aug 6, 2025 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: Correct sysfs attributes access rights

The scsi sysfs attributes "supported_mode" and "active_mode" do not define a store method and thus cannot be modified. Correct the DEVICE_ATTR() call for these two attributes to not include S_IWUSR to allow write access as they are read-only.

---
 drivers/scsi/scsi_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +2 -2
index d772258e29ad..e6464b998960 100644
@@ -265,7 +265,7 @@ show_shost_supported_mode(struct device *dev, struct device_attribute *attr,
 	return show_shost_mode(supported_mode, buf);
 }
 
-static DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
+static DEVICE_ATTR(supported_mode, S_IRUGO, show_shost_supported_mode, NULL);
 
 static ssize_t
 show_shost_active_mode(struct device *dev,
@@ -279,7 +279,7 @@ show_shost_active_mode(struct device *dev,
 		return show_shost_mode(shost->active_mode, buf);
 }
 
-static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
+static DEVICE_ATTR(active_mode, S_IRUGO, show_shost_active_mode, NULL);
 
 static int check_reset_type(const char *str)
 {
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Damien Le Moal

The scsi sysfs attributes "supported_mode" and "active_mode" do not define a store method and thus cannot be modified. Correct the DEVICE_ATTR() call for these two attributes to not include S_IWUSR to allow write access as they are read-only.

Note that class_attr_store() returns -EIO for no store method. Does the same happen after this change?

Quoted 26 lines
---
  drivers/scsi/scsi_sysfs.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +2 -2
index d772258e29ad..e6464b998960 100644
@@ -265,7 +265,7 @@ show_shost_supported_mode(struct device *dev, struct device_attribute *attr,
  	return show_shost_mode(supported_mode, buf);
  }
 
-static DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
+static DEVICE_ATTR(supported_mode, S_IRUGO, show_shost_supported_mode, NULL);
 
  static ssize_t
  show_shost_active_mode(struct device *dev,
@@ -279,7 +279,7 @@ show_shost_active_mode(struct device *dev,
  		return show_shost_mode(shost->active_mode, buf);
  }
 
-static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
+static DEVICE_ATTR(active_mode, S_IRUGO, show_shost_active_mode, NULL);
 
  static int check_reset_type(const char *str)
  {
#2 lore raw
Quoted 6 lines · John Garry
Quoted 5 lines · Damien Le Moal

The scsi sysfs attributes "supported_mode" and "active_mode" do not define a store method and thus cannot be modified. Correct the DEVICE_ATTR() call for these two attributes to not include S_IWUSR to allow write access as they are read-only.

Quoted 6 lines
Quoted 1 line

Note that class_attr_store() returns -EIO for no store method. Does the same happen after this change?

The regular Permission Denied (-EPERM) is returned. Do you think that is a problem ?

Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw
Quoted 4 lines · Damien Le Moal
Quoted 2 lines

Note that class_attr_store() returns -EIO for no store method. Does the same happen after this change?

The regular Permission Denied (-EPERM) is returned. Do you think that is a problem ?

Probably not. I can't imagine that any sane application would rely on that behavior (of returning -EIO).

#5 lore raw
In reply to Damien Le Moal

Damien,

Quoted 4 lines

The scsi sysfs attributes "supported_mode" and "active_mode" do not define a store method and thus cannot be modified. Correct the DEVICE_ATTR() call for these two attributes to not include S_IWUSR to allow write access as they are read-only.

Applied to 6.17/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen
#6 lore raw
In reply to Damien Le Moal
Quoted 6 lines · Damien Le Moal

The scsi sysfs attributes "supported_mode" and "active_mode" do not define a store method and thus cannot be modified. Correct the DEVICE_ATTR() call for these two attributes to not include S_IWUSR to allow write access as they are read-only.

Applied to 6.17/scsi-queue, thanks!

[1/1] scsi: Correct sysfs attributes access rights

      https://git.kernel.org/mkp/scsi/c/a2f54ff15c3b
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering