Skip to contentSkip to conversation

base: memory: fix soft/hard_offline_page permissions

PATCH In review Felipe Balbi 2 participants 7 messages Feb 18, 2013 – Feb 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 base: memory: fix soft/hard_offline_page permissions

those two sysfs files don't have a 'show' method, so they shouldn't have a read permission. Thanks to Greg Kroah-Hartman for actually looking into the source code and figuring out we had a real bug with these two files.

---
 drivers/base/memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/memory.c +2 -2
index 987604d..83d0b17 100644
@@ -494,8 +494,8 @@ store_hard_offline_page(struct device *dev,
 	return ret ? ret : count;
 }
 
-static DEVICE_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
-static DEVICE_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
+static DEVICE_ATTR(soft_offline_page, S_IWUSR, NULL, store_soft_offline_page);
+static DEVICE_ATTR(hard_offline_page, S_IWUSR, NULL, store_hard_offline_page);
 
 static __init int memory_fail_init(void)
 {
Signature · 1 line
1.8.1.rc1.5.g7e0651a
#1 lore raw

PATCH 2/2 base: core: WARN() about bogus permissions on device attributes

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

---

This is completely untested. I have only compile tested to make sure I'm not breaking anything.

Greg, do you think this would be nice to have ? I could fire up kvm tomorrow and run on a few of my OMAP-based boards to make sure it works as expected.

 drivers/base/core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/base/core.c +8 -1
index a235085..14e6a92 100644
@@ -563,8 +563,15 @@ int device_create_file(struct device *dev,
 		       const struct device_attribute *attr)
 {
 	int error = 0;
-	if (dev)
+
+	if (dev) {
+		WARN(((attr->attr.mode & S_IWUGO) && !attr->store),
+				"Write permission without 'store'\n");
+		WARN(((attr->attr.mode & S_IRUGO) && !attr->show),
+				"Read permission without 'show'\n");
 		error = sysfs_create_file(&dev->kobj, &attr->attr);
+	}
+
 	return error;
 }
 
Signature · 1 line
1.8.1.rc1.5.g7e0651a
maintainer
#2 lore raw

Re: [BONUS PATCH 2/2] base: core: WARN() about bogus permissions on device attributes

Quoted 7 lines · Felipe Balbi

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

Quoted 8 lines

---

This is completely untested. I have only compile tested to make sure I'm not breaking anything.

Greg, do you think this would be nice to have ? I could fire up kvm tomorrow and run on a few of my OMAP-based boards to make sure it works as expected.

Looks good, but you better fix up all of the big offenders that this points out, before I apply it, otherwise we will get a ton of bug reports :)

thanks,

greg k-h

#3 lore raw

Re: [BONUS PATCH 2/2] base: core: WARN() about bogus permissions on device attributes

Quoted 13 lines · Greg KH
Quoted 12 lines · Felipe Balbi

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

---

This is completely untested. I have only compile tested to make sure I'm not breaking anything.

Quoted 7 lines
Quoted 3 lines

Greg, do you think this would be nice to have ? I could fire up kvm tomorrow and run on a few of my OMAP-based boards to make sure it works as expected.

Looks good, but you better fix up all of the big offenders that this points out, before I apply it, otherwise we will get a ton of bug reports :)

sure, will do that tomorrow though ;-)

Signature · 1 line
balbi
#4 lore raw

Re: [BONUS PATCH 2/2] base: core: WARN() about bogus permissions on device attributes

Hi,

Quoted 18 lines · Felipe Balbi
Quoted 17 lines · Greg KH
Quoted 15 lines · Felipe Balbi

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

---

This is completely untested. I have only compile tested to make sure I'm not breaking anything.

Greg, do you think this would be nice to have ? I could fire up kvm tomorrow and run on a few of my OMAP-based boards to make sure it works as expected.

Quoted 5 lines
Quoted 3 lines

Looks good, but you better fix up all of the big offenders that this points out, before I apply it, otherwise we will get a ton of bug reports :)

sure, will do that tomorrow though ;-)

Just tested $SUBJECT and it didn't trigger any extra warnings. Only the one whose fix you already applied (I reverted it to make sure $SUBJECT was working as expected).

Signature · 1 line
balbi
maintainer
#5 lore raw

Re: [BONUS PATCH 2/2] base: core: WARN() about bogus permissions on device attributes

Quoted 25 lines · Felipe Balbi

Hi,

Quoted 22 lines · Felipe Balbi
Quoted 20 lines · Greg KH
Quoted 7 lines · Felipe Balbi

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

Quoted 8 lines

---

This is completely untested. I have only compile tested to make sure I'm not breaking anything.

Greg, do you think this would be nice to have ? I could fire up kvm tomorrow and run on a few of my OMAP-based boards to make sure it works as expected.

Looks good, but you better fix up all of the big offenders that this points out, before I apply it, otherwise we will get a ton of bug reports :)

Quoted 5 lines
Quoted 1 line

sure, will do that tomorrow though ;-)

Just tested $SUBJECT and it didn't trigger any extra warnings. Only the one whose fix you already applied (I reverted it to make sure $SUBJECT was working as expected).

Ok, care to resend so that I can queue it up after 3.9-rc1 is out, for inclusion in 3.10, and we can have lots of time to see what falls out?

thanks,

greg k-h

#6 lore raw

PATCH 1/1 base: core: WARN() about bogus permissions on device attributes

Whenever a struct device_attribute is registered with mismatched permissions - read permission without a show routine or write permission without store routine - we will issue a big warning so we catch those early enough.

---
 drivers/base/core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/base/core.c +8 -1
index a235085..14e6a92 100644
@@ -563,8 +563,15 @@ int device_create_file(struct device *dev,
 		       const struct device_attribute *attr)
 {
 	int error = 0;
-	if (dev)
+
+	if (dev) {
+		WARN(((attr->attr.mode & S_IWUGO) && !attr->store),
+				"Write permission without 'store'\n");
+		WARN(((attr->attr.mode & S_IRUGO) && !attr->show),
+				"Read permission without 'show'\n");
 		error = sysfs_create_file(&dev->kobj, &attr->attr);
+	}
+
 	return error;
 }
 
Signature · 1 line
1.8.1.rc1.5.g7e0651a