Skip to contentSkip to conversation

ACPI: NFIT: limit string attribute write

PATCH RESEND In review Ben Dooks 3 participants 5 messages Jul 12, 2023 – Jul 13, 2023

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH RESEND v2 1/1 ACPI: NFIT: limit string attribute write

If we're writing what could be an arbitrary sized string into an attribute we should probably use sysfs_emit() just to be safe. Most of the other attriubtes are some sort of integer so unlikely to be an issue so not altered at this time.

---
v2:
- use sysfs_emit() instead of snprintf.

---
 drivers/acpi/nfit/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/nfit/core.c +1 -1
index 9213b426b125..59c354137627 100644
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
 {
 	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
-	return sprintf(buf, "%s\n", nfit_mem->id);
+	return sysfs_emit(buf, "%s\n", nfit_mem->id);
 }
 static DEVICE_ATTR_RO(id);
 
Signature · 1 line
2.40.1
author
#1 lore raw
Quoted 18 lines · Ben Dooks

If we're writing what could be an arbitrary sized string into an attribute we should probably use sysfs_emit() just to be safe. Most of the other attriubtes are some sort of integer so unlikely to be an issue so not altered at this time.

---
v2:
- use sysfs_emit() instead of snprintf.

---
  drivers/acpi/nfit/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/nfit/core.c +0 -0
index 9213b426b125..59c354137627 100644

drivers/acpi/nfit/core.c static ssize_t id_show(struct device *dev, · line 1584

Quoted 7 lines
drivers/acpi/nfit/core.c +1 -1
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
  {
  	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
-	return sprintf(buf, "%s\n", nfit_mem->id);
+	return sysfs_emit(buf, "%s\n", nfit_mem->id);
  }
  static DEVICE_ATTR_RO(id);

Should we go through and change all the attribute code to use sysfs_emit() ?

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
maintainer
#2 lore raw
Quoted 14 lines · Ben Dooks
Quoted 13 lines · Ben Dooks

If we're writing what could be an arbitrary sized string into an attribute we should probably use sysfs_emit() just to be safe. Most of the other attriubtes are some sort of integer so unlikely to be an issue so not altered at this time.

---
v2:
   - use sysfs_emit() instead of snprintf.
---
  drivers/acpi/nfit/core.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/acpi/nfit/core.c static ssize_t id_show(struct device *dev, · line 1583

Quoted 11 lines
drivers/acpi/nfit/core.c +1 -1
index 9213b426b125..59c354137627 100644
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
   {
       struct nfit_mem *nfit_mem = to_nfit_mem(dev);
-    return sprintf(buf, "%s\n", nfit_mem->id);
+    return sysfs_emit(buf, "%s\n", nfit_mem->id);
   }
   static DEVICE_ATTR_RO(id);

Should we go through and change all the attribute code to use sysfs_emit() ?

Probably not a bad idea given they all have the same issue.

Quoted 1 line
maintainer Reviewed-by on v2 1/1
#3 lore raw
In reply to Ben Dooks
Quoted 6 lines · Ben Dooks

If we're writing what could be an arbitrary sized string into an attribute we should probably use sysfs_emit() just to be safe. Most of the other attriubtes are some sort of integer so unlikely to be an issue so not altered at this time.

Quoted 20 lines

---
v2:
- use sysfs_emit() instead of snprintf.

---
  drivers/acpi/nfit/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/nfit/core.c +1 -1
index 9213b426b125..59c354137627 100644
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
  {
  	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
-	return sprintf(buf, "%s\n", nfit_mem->id);
+	return sysfs_emit(buf, "%s\n", nfit_mem->id);
  }
  static DEVICE_ATTR_RO(id);
 
maintainer
#4 lore raw
In reply to Ben Dooks
Quoted 4 lines · Ben Dooks

If we're writing what could be an arbitrary sized string into an attribute we should probably use sysfs_emit() just to be safe. Most of the other attriubtes are some sort of integer so unlikely to be an issue so not altered at this time.

Hi Ben,

Documentation/process/submitting-patches.rst says:
"Don't add "RESEND" when you are submitting a modified version of your patch or patch series - "RESEND" only applies to resubmission of a patch or patch series which have not been modified in any way from the previous submission."

I see maybe you are going to go back and use sysfs_emit in all the _show functions. I'd suggest either justify it as either a) or b), Both are more explicit than 'just to be safe'

a) following the recommendations of Documentation/filesystems/sysfs.rst which says to only use sysfs_emit in show() functions.

b) explain that you are doing it because sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content requests and it's possible to overrun the buffer length.

I vote for doing 'em all!

Alison

Quoted 26 lines

---
v2:
- use sysfs_emit() instead of snprintf.

---
 drivers/acpi/nfit/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/nfit/core.c +1 -1
index 9213b426b125..59c354137627 100644
@@ -1579,7 +1579,7 @@ static ssize_t id_show(struct device *dev,
 {
 	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
-	return sprintf(buf, "%s\n", nfit_mem->id);
+	return sysfs_emit(buf, "%s\n", nfit_mem->id);
 }
 static DEVICE_ATTR_RO(id);
 
Signature · 1 line
2.40.1