Skip to contentSkip to conversation

parisc: led: Fix potential null-ptr-deref in start_task()

PATCH Applied Shang XiaoJing 2 participants 2 messages Nov 17, 2022 – Nov 18, 2022 PA-RISC architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parisc: led: Fix potential null-ptr-deref in start_task()

start_task() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:

start_task()
create_singlethread_workqueue() # failed, led_wq is NULL queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-deref

Check the ret value and return -ENOMEM if it is NULL.

Fixes 3499495205a6 ("[PARISC] Use work queue in LED/LCD driver instead of tasklet.")
---
 drivers/parisc/led.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/parisc/led.c +3 -0
index d4be9d2ee74d..8bdc5e043831 100644
@@ -137,6 +137,9 @@ static int start_task(void)
 
 	/* Create the work queue and queue the LED task */
 	led_wq = create_singlethread_workqueue("led_wq");	
+	if (!led_wq)
+		return -ENOMEM;
+
 	queue_delayed_work(led_wq, &led_task, 0);
 
 	return 0;
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Shang XiaoJing

start_task() calls create_singlethread_workqueue() and not checked the ret value, which may return NULL. And a null-ptr-deref may happen:

start_task()
create_singlethread_workqueue() # failed, led_wq is NULL queue_delayed_work()
queue_delayed_work_on()
__queue_delayed_work() # warning here, but continue
__queue_work() # access wq->flags, null-ptr-deref

Quoted 4 lines

Check the ret value and return -ENOMEM if it is NULL.

Fixes 3499495205a6 ("[PARISC] Use work queue in LED/LCD driver instead of tasklet.")

applied.

Thanks!
Helge

Quoted 18 lines
---
  drivers/parisc/led.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/parisc/led.c +3 -0
index d4be9d2ee74d..8bdc5e043831 100644
@@ -137,6 +137,9 @@ static int start_task(void)
 
  	/* Create the work queue and queue the LED task */
  	led_wq = create_singlethread_workqueue("led_wq");
+	if (!led_wq)
+		return -ENOMEM;
+
  	queue_delayed_work(led_wq, &led_task, 0);
 
  	return 0;