2019-06-13 23:34:08

by Leonardo Bras

[permalink] [raw]
Subject: [RFC PATCH 1/1] block/cfq : Include check to avoid NULL Pointer Dereferencing

Checks if cfqg is a valid pointer before dereferencing.

There is a explicit chance for cfqg = cfq_get_next_cfqg() to return NULL,
so 'cfqg->saved_wl_slice' would be a Null dereferencing.

Signed-off-by: Leonardo Bras <[email protected]>
---
block/cfq-iosched.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 2eb87444b157..2c5dd5a295ee 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -3210,9 +3210,13 @@ static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd)

static void cfq_choose_cfqg(struct cfq_data *cfqd)
{
- struct cfq_group *cfqg = cfq_get_next_cfqg(cfqd);
+ struct cfq_group *cfqg;
u64 now = ktime_get_ns();

+ cfqg = cfq_get_next_cfqg(cfqd);
+ if (unlikely(!cfqg))
+ return;
+
cfqd->serving_group = cfqg;

/* Restore the workload type data */
--
2.20.1