Skip to contentSkip to conversation

gpiolib: avoid format string weakness in workqueue interface

PATCH Applied Arnd Bergmann 2 participants 2 messages Oct 28, 2024 – Oct 31, 2024

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

PATCH 1/1 gpiolib: avoid format string weakness in workqueue interface

From: Arnd Bergmann <[email protected]>

Using a string literal as a format string is a possible bug when the string contains '%' characters:

drivers/gpio/gpiolib-cdev.c:2813:48: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
2813 | gdev->line_state_wq = alloc_ordered_workqueue(dev_name(&gdev->dev),

      |                                                       ^~~~~~~~~~~~~~~~~~~~
drivers/gpio/gpiolib-cdev.c:2813:48: note: treat the string as an argument to avoid this
 2813 |         gdev->line_state_wq = alloc_ordered_workqueue(dev_name(&gdev->dev),
      |                                                       ^
      |                                                       "%s",

Do as clang suggests and use a trivial "%s" format string.

Fixes 7b9b77a8bba9 ("gpiolib: add a per-gpio_device line state notification workqueue")
---
 drivers/gpio/gpiolib-cdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-cdev.c +2 -2
index 0ec162b0ea04..088201de9627 100644
@@ -2810,8 +2810,8 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
 	gdev->chrdev.owner = THIS_MODULE;
 	gdev->dev.devt = MKDEV(MAJOR(devt), gdev->id);
 
-	gdev->line_state_wq = alloc_ordered_workqueue(dev_name(&gdev->dev),
-						      WQ_HIGHPRI);
+	gdev->line_state_wq = alloc_ordered_workqueue("%s", WQ_HIGHPRI,
+						      dev_name(&gdev->dev));
 	if (!gdev->line_state_wq)
 		return -ENOMEM;
 
Signature · 1 line
2.39.5
#1 lore raw

From: Bartosz Golaszewski <[email protected]>

Quoted 5 lines · Arnd Bergmann

Using a string literal as a format string is a possible bug when the string contains '%' characters:

drivers/gpio/gpiolib-cdev.c:2813:48: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
2813 | gdev->line_state_wq = alloc_ordered_workqueue(dev_name(&gdev->dev),

Quoted 7 lines
      |                                                       ^~~~~~~~~~~~~~~~~~~~
drivers/gpio/gpiolib-cdev.c:2813:48: note: treat the string as an argument to avoid this
 2813 |         gdev->line_state_wq = alloc_ordered_workqueue(dev_name(&gdev->dev),
      |                                                       ^
      |                                                       "%s",

[...]

Applied, thanks!

[1/1] gpiolib: avoid format string weakness in workqueue interface

      commit: a22c9dc26d6fc522357b73858b13e29c58f49d64

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>