Skip to contentSkip to conversation

driver core: fix driver_set_override() issue with empty strings

PATCH In review Greg Kroah-Hartman 3 participants 3 messages Sep 1, 2022 – Sep 5, 2022 Driver core

lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 driver core: fix driver_set_override() issue with empty strings

Python likes to send an empty string for some sysfs files, including the driver_override field. When commit 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") moved the PCI core to use the driver core function instead of hand-rolling their own handler, this showed up as a regression from some userspace tools, like DPDK.

Fix this up by actually looking at the length of the string first instead of trusting that userspace got it correct.

Fixes 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding")
Cc Krzysztof Kozlowski <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc stable <[email protected]>
---
 drivers/base/driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/driver.c +6 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override,
 	if (len >= (PAGE_SIZE - 1))
 		return -EINVAL;
 
+	/*
+	 * Compute the real length of the string in case userspace sends us a
+	 * bunch of \0 characters like python likes to do.
+	 */
+	len = strlen(s);
+
 	if (!len) {
 		/* Empty string passed - clear override */
 		device_lock(dev);
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · On Thu, 1 Sep 2022 18:37:34 +0200 Greg Kroah-Hartman…

Python likes to send an empty string for some sysfs files, including the driver_override field. When commit 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") moved the PCI core to use the driver core function instead of hand-rolling their own handler, this showed up as a regression from some userspace tools, like DPDK.

Fix this up by actually looking at the length of the string first instead of trusting that userspace got it correct.

Fixes 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding")
Cc Krzysztof Kozlowski <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc stable <[email protected]>
---
 drivers/base/driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/driver.c +0 -0
index 15a75afe6b84..676b6275d5b5 100644
@@ -63,6 +63,12 @@ int driver_set_override(struct device *dev, const char **override,
 	if (len >= (PAGE_SIZE - 1))
 		return -EINVAL;

drivers/base/driver.c int driver_set_override(struct device *dev, const char **override, · line 74

Quoted 10 lines
drivers/base/driver.c +6 -0
 
+	/*
+	 * Compute the real length of the string in case userspace sends us a
+	 * bunch of \0 characters like python likes to do.
+	 */
+	len = strlen(s);
+
 	if (!len) {
 		/* Empty string passed - clear override */
 		device_lock(dev);

Thanks for addressing this.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 9 lines · Greg Kroah-Hartman

Python likes to send an empty string for some sysfs files, including the driver_override field. When commit 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding") moved the PCI core to use the driver core function instead of hand-rolling their own handler, this showed up as a regression from some userspace tools, like DPDK.

Fix this up by actually looking at the length of the string first instead of trusting that userspace got it correct.

Quoted 8 lines
Fixes 23d99baf9d72 ("PCI: Use driver_set_override() instead of open-coding")
Cc Krzysztof Kozlowski <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc stable <[email protected]>

Best regards,
Krzysztof