Skip to contentSkip to conversation

ACPI: NFIT: limit string attribute write

PATCH Superseded Ben Dooks 2 participants 3 messages Jul 11, 2023 – Jul 12, 2023

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 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..d7e9d9cd16d2 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 snprintf(buf, PAGE_SIZE, "%s\n", nfit_mem->id);
 }
 static DEVICE_ATTR_RO(id);
 
Signature · 1 line
2.40.1
maintainer
#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..d7e9d9cd16d2 100644

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

Quoted 5 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 snprintf(buf, PAGE_SIZE, "%s\n", nfit_mem->id);

Doesn't look like you updated your patch with your new changes....

Quoted 3 lines
drivers/acpi/nfit/core.c +0 -0
  }
  static DEVICE_ATTR_RO(id);
 
author
#2 lore raw
Quoted 16 lines · Dave Jiang
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 11 lines

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

Quoted 9 lines
drivers/acpi/nfit/core.c +1 -1
index 9213b426b125..d7e9d9cd16d2 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 snprintf(buf, PAGE_SIZE, "%s\n", nfit_mem->id);

Doesn't look like you updated your patch with your new changes....

Ooops, sorry about that. Will sort that for v2++

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

https://www.codethink.co.uk/privacy.html