ALSA: control - fix a leak in snd_ctl_led_init()
Subsystems (2)
PATCH 1/2 ALSA: control - fix a leak in snd_ctl_led_init()
This unwind loop needs to free snd_ctl_leds[0] as well.
--- sound/core/control_led.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/control_led.c +2 -2
@@ -712,7 +712,7 @@ static struct snd_ctl_layer_ops snd_ctl_led_lops = {static int __init snd_ctl_led_init (void ) {struct snd_ctl_led *led; -unsigned int group; +int group;device_initialize (&snd_ctl_led_dev); snd_ctl_led_dev.class = sound_class;
@@ -730,7 +730,7 @@ static int __init snd_ctl_led_init(void)dev_set_name (&led->dev, led->name);if (device_add (&led->dev)) {put_device (&led->dev); -for (; group >0 ; group--) { +for (; group >=0 ; group--) { led = &snd_ctl_leds[group];device_del (&led->dev); }
Signature · 1 line
2.30.2
PATCH 2/2 ALSA: control - off by one in store_mode()
If count is 16 then this will put the NUL terminator one element beyond the end of the array.
--- sound/core/control_led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/control_led.c +1 -1
@@ -391,7 +391,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *attr, { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);char _buf[16 ]; -size_t l =min (count,sizeof (_buf) -1 ) +1 ; +size_t l =min (count,sizeof (_buf) -1 );enum snd_ctl_led_mode mode;memcpy (_buf, buf, l);
Signature · 1 line
2.30.2
Re: [PATCH 2/2] ALSA: control - off by one in store_mode()
Dne 02. 04. 21 v 13:42 Dan Carpenter napsal(a):
Quoted 5 lines
If count is 16 then this will put the NUL terminator one element beyond the end of the array.
Fixes cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")Signed-off-by Dan Carpenter <[email protected]>
No idea why I added + 1... Thanks for your correction.
Quoted 18 lines
--- sound/core/control_led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/core/control_led.c +1
-1@@ -391,7 +391,7 @@ static ssize_t store_mode(struct device *dev, struct device_attribute *attr, { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev);char _buf[16 ]; -size_t l =min (count,sizeof (_buf) -1 ) +1 ; +size_t l =min (count,sizeof (_buf) -1 );enum snd_ctl_led_mode mode;memcpy (_buf, buf, l);
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH 2/2] ALSA: control - off by one in store_mode()
Quoted 11 lines · Jaroslav Kysela
Dne 02. 04. 21 v 13:42 Dan Carpenter napsal(a):
Quoted 5 lines
If count is 16 then this will put the NUL terminator one element beyond the end of the array.
Fixes cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")Signed-off-by Dan Carpenter <[email protected]>No idea why I added + 1... Thanks for your correction.
Reviewed-by Jaroslav Kysela <[email protected]>
Applied now. Thanks.
Takashi
Jaroslav Kysela
maintainerDne 02. 04. 21 v 13:42 Dan Carpenter napsal(a):
Quoted 22 lines
This unwind loop needs to free snd_ctl_leds[0] as well.
Fixes cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")Signed-off-by Dan Carpenter <[email protected]>--- sound/core/control_led.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)sound/core/control_led.c +1
-1@@ -712,7 +712,7 @@ static struct snd_ctl_layer_ops snd_ctl_led_lops = {static int __init snd_ctl_led_init (void ) {struct snd_ctl_led *led; -unsigned int group; +int group;device_initialize (&snd_ctl_led_dev); snd_ctl_led_dev.class = sound_class;
sound/core/control_led.c static int __init snd_ctl_led_init(void) · line 734
Quoted 6 lines
sound/core/control_led.c +1
-1@@ -730,7 +730,7 @@ static int __init snd_ctl_led_init(void)dev_set_name (&led->dev, led->name);if (device_add (&led->dev)) {put_device (&led->dev); -for (; group >0 ; group--) { +for (; group >=0 ; group--) { led = &snd_ctl_leds[group];
It's not correct. This assignent should be 'led = &snd_ctl_leds[group - 1];' without other changes, because the put_device() is enough when device_add() fails.
Could you resend the correction?
Jaroslav
Quoted 3 lines
sound/core/control_led.c +0
-0device_del (&led->dev); }
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
PATCH v2 1/2 ALSA: control - double free in snd_ctl_led_init()
"group - 1" was intended here instead of "group". The current error handling will double free the first item in the array and leak the last item.
---
v2: The first patch wasn't right. It fixed the leak but left the double free.
sound/core/control_led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/control_led.c +1 -1
@@ -734,7 +734,7 @@ static int __init snd_ctl_led_init(void)if (device_add (&led->dev)) {put_device (&led->dev);for (; group >0 ; group--) { - led = &snd_ctl_leds[group]; + led = &snd_ctl_leds[group -1 ];device_del (&led->dev); }device_del (&snd_ctl_led_dev);
Signature · 1 line
2.30.2
Re: [PATCH 1/2 v2] ALSA: control - double free in snd_ctl_led_init()
Dne 09. 04. 21 v 14:34 Dan Carpenter napsal(a):
Quoted 6 lines
"group - 1" was intended here instead of "group". The current error handling will double free the first item in the array and leak the last item.
Fixes cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")Signed-off-by Dan Carpenter <[email protected]>
Quoted 21 lines
---
v2: The first patch wasn't right. It fixed the leak but left the double free.sound/core/control_led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/core/control_led.c +1
-1@@ -734,7 +734,7 @@ static int __init snd_ctl_led_init(void)if (device_add (&led->dev)) {put_device (&led->dev);for (; group >0 ; group--) { - led = &snd_ctl_leds[group]; + led = &snd_ctl_leds[group -1 ];device_del (&led->dev); }device_del (&snd_ctl_led_dev);
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH 1/2 v2] ALSA: control - double free in snd_ctl_led_init()
In reply to Dan CarpenterQuoted 10 lines · Dan Carpenter
"group - 1" was intended here instead of "group". The current error handling will double free the first item in the array and leak the last item.
Fixes cb17fe0045aa ("ALSA: control - add sysfs support to the LED trigger module")Signed-off-by Dan Carpenter <[email protected]>---
v2: The first patch wasn't right. It fixed the leak but left the double free.
Applied now. Thanks.
Takashi