Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1638010 > unrolled thread

[PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set

Started byPaolo Valente <paolo.valente@linaro.org>
First post2017-05-09 11:40 +0200
Last post2017-05-09 17:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set Paolo Valente <paolo.valente@linaro.org> - 2017-05-09 11:40 +0200
    Re: [PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if  set Jens Axboe <axboe@kernel.dk> - 2017-05-09 17:00 +0200

#1638010 — [PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set

FromPaolo Valente <paolo.valente@linaro.org>
Date2017-05-09 11:40 +0200
Subject[PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set
Message-ID<tF9MC-8jT-9@gated-at.bofh.it>
In the function __bfq_deactivate_entity, the pointer
entity->sched_data could happen to be used before being properly
initialized. This led to a NULL pointer dereference. This commit fixes
this bug by just using this pointer only where it is safe to do so.

Reported-by: Tom Harrison <l12436.tw@gmail.com>
Tested-by: Tom Harrison <l12436.tw@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
---
 block/bfq-wf2q.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index b4fc3e4..8726ede 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -1114,12 +1114,21 @@ static void bfq_activate_requeue_entity(struct bfq_entity *entity,
 bool __bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree)
 {
 	struct bfq_sched_data *sd = entity->sched_data;
-	struct bfq_service_tree *st = bfq_entity_service_tree(entity);
-	int is_in_service = entity == sd->in_service_entity;
+	struct bfq_service_tree *st;
+	bool is_in_service;
 
 	if (!entity->on_st) /* entity never activated, or already inactive */
 		return false;
 
+	/*
+	 * If we get here, then entity is active, which implies that
+	 * bfq_group_set_parent has already been invoked for the group
+	 * represented by entity. Therefore, the field
+	 * entity->sched_data has been set, and we can safely use it.
+	 */
+	st = bfq_entity_service_tree(entity);
+	is_in_service = entity == sd->in_service_entity;
+
 	if (is_in_service)
 		bfq_calc_finish(entity, entity->service);
 
-- 
2.10.0

[toc] | [next] | [standalone]


#1638178 — Re: [PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set

FromJens Axboe <axboe@kernel.dk>
Date2017-05-09 17:00 +0200
SubjectRe: [PATCH BUGFIX] block, bfq: use pointer entity->sched_data only if set
Message-ID<tFeMi-37Z-13@gated-at.bofh.it>
In reply to#1638010
On 05/09/2017 03:37 AM, Paolo Valente wrote:
> In the function __bfq_deactivate_entity, the pointer
> entity->sched_data could happen to be used before being properly
> initialized. This led to a NULL pointer dereference. This commit fixes
> this bug by just using this pointer only where it is safe to do so.

Added, thanks.

-- 
Jens Axboe

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web