Skip to contentSkip to conversation

blk-throttle: fix NULL pointer dereference in throtl_schedule_pending_timer

PATCH Applied Joseph Qi 3 participants 3 messages Jun 7, 2017

Subsystems (2)
lore
Share & tools
lore

Joseph Qi

author
#0 lore raw

PATCH 1/1 blk-throttle: fix NULL pointer dereference in throtl_schedule_pending_timer

From: Joseph Qi <[email protected]>

I have encountered a NULL pointer dereference in
throtl_schedule_pending_timer:

  [  413.735396] BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
  [  413.735535] IP: [<ffffffff812ebbbf>] throtl_schedule_pending_timer+0x3f/0x210
  [  413.735643] PGD 22c8cf067 PUD 22cb34067 PMD 0
  [  413.735713] Oops: 0000 [#1] SMP
  ......

This is caused by the following case:
blk_throtl_bio
throtl_schedule_next_dispatch <= sq is top level one without parent
throtl_schedule_pending_timer
sq_to_tg(sq)->td->throtl_slice <= sq_to_tg(sq) returns NULL

Fix it by using sq_to_td instead of sq_to_tg(sq)->td, which will always return a valid td.

Fixes 297e3d854784 ("blk-throttle: make throtl_slice tunable")
---
 block/blk-throttle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-throttle.c +1 -1
index fc13dd0..3b751f7 100644
@@ -698,7 +698,7 @@ static void throtl_dequeue_tg(struct throtl_grp *tg)
 static void throtl_schedule_pending_timer(struct throtl_service_queue *sq,
 					  unsigned long expires)
 {
-	unsigned long max_expire = jiffies + 8 * sq_to_tg(sq)->td->throtl_slice;
+	unsigned long max_expire = jiffies + 8 * sq_to_td(sq)->throtl_slice;
 
 	/*
 	 * Since we are adjusting the throttle limit dynamically, the sleep
Signature · 1 line
1.9.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Joseph Qi

From: Joseph Qi <[email protected]>

I have encountered a NULL pointer dereference in
throtl_schedule_pending_timer:

  [  413.735396] BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
  [  413.735535] IP: [<ffffffff812ebbbf>] throtl_schedule_pending_timer+0x3f/0x210
  [  413.735643] PGD 22c8cf067 PUD 22cb34067 PMD 0
  [  413.735713] Oops: 0000 [#1] SMP
  ......

This is caused by the following case:
blk_throtl_bio
throtl_schedule_next_dispatch <= sq is top level one without parent
throtl_schedule_pending_timer
sq_to_tg(sq)->td->throtl_slice <= sq_to_tg(sq) returns NULL

Quoted 5 lines

Fix it by using sq_to_td instead of sq_to_tg(sq)->td, which will always return a valid td.

Fixes 297e3d854784 ("blk-throttle: make throtl_slice tunable")

Thanks!

Quoted 19 lines
---
 block/blk-throttle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-throttle.c +1 -1
index fc13dd0..3b751f7 100644
@@ -698,7 +698,7 @@ static void throtl_dequeue_tg(struct throtl_grp *tg)
 static void throtl_schedule_pending_timer(struct throtl_service_queue *sq,
 					  unsigned long expires)
 {
-	unsigned long max_expire = jiffies + 8 * sq_to_tg(sq)->td->throtl_slice;
+	unsigned long max_expire = jiffies + 8 * sq_to_td(sq)->throtl_slice;
 
 	/*
 	 * Since we are adjusting the throttle limit dynamically, the sleep
Signature · 1 line
1.9.4
Applied
#2 lore raw
In reply to Joseph Qi
Quoted 10 lines · Joseph Qi

From: Joseph Qi <[email protected]>

I have encountered a NULL pointer dereference in
throtl_schedule_pending_timer:

  [  413.735396] BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
  [  413.735535] IP: [<ffffffff812ebbbf>] throtl_schedule_pending_timer+0x3f/0x210
  [  413.735643] PGD 22c8cf067 PUD 22cb34067 PMD 0
  [  413.735713] Oops: 0000 [#1] SMP
  ......
Quoted 8 lines

This is caused by the following case:
blk_throtl_bio
throtl_schedule_next_dispatch <= sq is top level one without parent
throtl_schedule_pending_timer
sq_to_tg(sq)->td->throtl_slice <= sq_to_tg(sq) returns NULL

Fix it by using sq_to_td instead of sq_to_tg(sq)->td, which will always return a valid td.

Applied, thanks.

Signature · 1 line
Jens Axboe