Skip to contentSkip to conversation

leds: mlxreg: Fix possible buffer overflow

PATCH RESEND Applied Oleh Kravchenko 2 participants 3 messages Oct 16, 2019 – Nov 4, 2019

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

PATCH RESEND 1/1 leds: mlxreg: Fix possible buffer overflow

Error was detected by PVS-Studio:
V512 A call of the 'sprintf' function will lead to overflow of the buffer 'led_data->led_cdev_name'.

---
 drivers/leds/leds-mlxreg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/leds-mlxreg.c +2 -2
index cabe379071a7..82aea1cd0c12 100644
@@ -228,8 +228,8 @@ static int mlxreg_led_config(struct mlxreg_led_priv_data *priv)
 			brightness = LED_OFF;
 			led_data->base_color = MLXREG_LED_GREEN_SOLID;
 		}
-		sprintf(led_data->led_cdev_name, "%s:%s", "mlxreg",
-			data->label);
+		snprintf(led_data->led_cdev_name, sizeof(led_data->led_cdev_name),
+			 "mlxreg:%s", data->label);
 		led_cdev->name = led_data->led_cdev_name;
 		led_cdev->brightness = brightness;
 		led_cdev->max_brightness = LED_ON;
Signature · 1 line
2.21.0
Applied
#1 lore raw
Quoted 7 lines · Oleh Kravchenko

Error was detected by PVS-Studio:
V512 A call of the 'sprintf' function will lead to overflow of the buffer 'led_data->led_cdev_name'.

Thanks for resend, and sorry for the delay.

Note that this would only be security issue if someone did malicious device tree... so... not a security issue :-).

Applied.

Pavel

Quoted 16 lines

index cabe379071a7..82aea1cd0c12 100644

drivers/leds/leds-mlxreg.c +2 -2
@@ -228,8 +228,8 @@ static int mlxreg_led_config(struct mlxreg_led_priv_data *priv)
 			brightness = LED_OFF;
 			led_data->base_color = MLXREG_LED_GREEN_SOLID;
 		}
-		sprintf(led_data->led_cdev_name, "%s:%s", "mlxreg",
-			data->label);
+		snprintf(led_data->led_cdev_name, sizeof(led_data->led_cdev_name),
+			 "mlxreg:%s", data->label);
 		led_cdev->name = led_data->led_cdev_name;
 		led_cdev->brightness = brightness;
 		led_cdev->max_brightness = LED_ON;
Signature · 1 line
2.21.0
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw

Hello Pavel,

Quoted 5 lines · Pavel Machek
Quoted 4 lines · Oleh Kravchenko

Error was detected by PVS-Studio:
V512 A call of the 'sprintf' function will lead to overflow of the buffer 'led_data->led_cdev_name'.

Quoted 7 lines
Quoted 3 lines

Thanks for resend, and sorry for the delay.

Note that this would only be security issue if someone did malicious device tree... so... not a security issue :-).

Agree, very limited case.
But I just want make our kernel more robust and reliable :-)

Quoted 2 lines

Applied.

Thanks!

Quoted 1 line

Pavel