Skip to contentSkip to conversation

power: reset: reboot-mode: fix -Wformat-security warning

PATCH Applied Arnd Bergmann 2 participants 2 messages Mar 6 – Mar 11 System reset/shutdown drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: reset: reboot-mode: fix -Wformat-security warning

From: Arnd Bergmann <[email protected]>

The device_create() function expects a format string to construct a device name, so passing a variable here introduces a possible vulnerability in case the string can contain '%' characters:

drivers/power/reset/reboot-mode.c:148:22: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security] drivers/power/reset/reboot-mode.c:148:22: note: treat the string as an argument to avoid this
148 | (void *)priv, reboot->dev->driver->name);

Use an trivial "%s" format instead and pass the name as the string to be included here.

Fixes cfaf0a90789a ("power: reset: reboot-mode: Expose sysfs for registered reboot_modes")
---
 drivers/power/reset/reboot-mode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/reset/reboot-mode.c +2 -1
index ad239e96774b..d20e44db0532 100644
@@ -145,7 +145,8 @@ static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
 	}
 
 	priv->reboot_mode_device = device_create(&reboot_mode_class, NULL, 0,
-						 (void *)priv, reboot->dev->driver->name);
+						 (void *)priv, "%s",
+						 reboot->dev->driver->name);
 	if (IS_ERR(priv->reboot_mode_device)) {
 		ret = PTR_ERR(priv->reboot_mode_device);
 		goto error;
Signature · 1 line
2.39.5
#1 lore raw
Quoted 9 lines · Arnd Bergmann

The device_create() function expects a format string to construct a device name, so passing a variable here introduces a possible vulnerability in case the string can contain '%' characters:

drivers/power/reset/reboot-mode.c:148:22: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security] drivers/power/reset/reboot-mode.c:148:22: note: treat the string as an argument to avoid this
148 | (void *)priv, reboot->dev->driver->name);

[...]

Applied, thanks!

[1/1] power: reset: reboot-mode: fix -Wformat-security warning

      commit: c7e05ab38adc44d0cae4888016829359dcbba7b2

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>