Skip to contentSkip to conversation

cfq: fix NULL pointer dereference in cfq_choose_cfqg.

PATCH In review Namjae Jeon 2 participants 3 messages Mar 4, 2012 – Mar 5, 2012 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfq: fix NULL pointer dereference in cfq_choose_cfqg.

I found null pointer dereferencing possibility while reviewing.
If cfq_get_next_cfqg return null by RB_EMPTY_ROOT, null pointer dereferencing error can occur.

---
 block/cfq-iosched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block/cfq-iosched.c +1 -1
index d0ba505..d924272 100644
@@ -2306,7 +2306,7 @@ static void cfq_choose_cfqg(struct cfq_data *cfqd)
 	cfqd->serving_group = cfqg;
 
 	/* Restore the workload type data */
-	if (cfqg->saved_workload_slice) {
+	if (!cfqg && cfqg->saved_workload_slice) {
 		cfqd->workload_expires = jiffies + cfqg->saved_workload_slice;
 		cfqd->serving_type = cfqg->saved_workload;
 		cfqd->serving_prio = cfqg->saved_serving_prio;
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 13 lines · Namjae Jeon

I found null pointer dereferencing possibility while reviewing.
If cfq_get_next_cfqg return null by RB_EMPTY_ROOT, null pointer dereferencing error can occur.

---
 block/cfq-iosched.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
block/cfq-iosched.c +0 -0
index d0ba505..d924272 100644

block/cfq-iosched.c static void cfq_choose_cfqg(struct cfq_data *cfqd) · line 2312

Quoted 8 lines
block/cfq-iosched.c +1 -1
@@ -2306,7 +2306,7 @@ static void cfq_choose_cfqg(struct cfq_data *cfqd)
        cfqd->serving_group = cfqg;
 
        /* Restore the workload type data */
-       if (cfqg->saved_workload_slice) {
+       if (!cfqg && cfqg->saved_workload_slice) {
                cfqd->workload_expires = jiffies + cfqg->saved_workload_slice;
                cfqd->serving_type = cfqg->saved_workload;
                cfqd->serving_prio = cfqg->saved_serving_prio;

I don't think that this is a correct fix.

1. Can it really happen that cfq_get_next_cfqg() returns NULL at this point?

2. Adding a if(!cfgg ...) does not solve the problem, it ignores it. After the if block we call choose_service_tree().
I'm sure choose_service_tree() it not happy when we pass a NULL pointer to it...

Signature · 2 lines
Thanks,
//richard
#2 lore raw

Hi. Richard.

You're right. need to add exception code more. I will look for more.

Thanks.

2012/3/4 richard -rw- weinberger <[email protected]>:

Quoted 34 lines · Namjae Jeon
Quoted 13 lines

I found null pointer dereferencing possibility while reviewing.
If cfq_get_next_cfqg return null by RB_EMPTY_ROOT, null pointer dereferencing error can occur.

---
 block/cfq-iosched.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
block/cfq-iosched.c +0 -0
index d0ba505..d924272 100644

block/cfq-iosched.c static void cfq_choose_cfqg(struct cfq_data *cfqd) · line 2312

Quoted 8 lines
block/cfq-iosched.c +1 -1
@@ -2306,7 +2306,7 @@ static void cfq_choose_cfqg(struct cfq_data *cfqd)
        cfqd->serving_group = cfqg;
 
        /* Restore the workload type data */
-       if (cfqg->saved_workload_slice) {
+       if (!cfqg && cfqg->saved_workload_slice) {
                cfqd->workload_expires = jiffies + cfqg->saved_workload_slice;
                cfqd->serving_type = cfqg->saved_workload;
                cfqd->serving_prio = cfqg->saved_serving_prio;

I don't think that this is a correct fix.

1. Can it really happen that cfq_get_next_cfqg() returns NULL at this point?

2. Adding a if(!cfgg ...) does not solve the problem, it ignores it. After the if block we call choose_service_tree().
I'm sure choose_service_tree() it not happy when we pass a NULL pointer to it...

--
Thanks,
//richard