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


Groups > linux.kernel > #1219626

[PATCH block/for-linus] block: blkg_destroy_all() should clear q->root_blkg and ->root_rl.blkg

From Tejun Heo <tj@kernel.org>
Newsgroups linux.kernel
Subject [PATCH block/for-linus] block: blkg_destroy_all() should clear q->root_blkg and ->root_rl.blkg
Date 2015-09-05 21:50 +0200
Message-ID <q5rDk-1Dm-7@gated-at.bofh.it> (permalink)
References (4 earlier) <q52OB-53-1@gated-at.bofh.it> <q565Q-4De-13@gated-at.bofh.it> <q5nJo-4zK-5@gated-at.bofh.it> <q5nT4-4L2-19@gated-at.bofh.it> <q5qxz-6Y-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


While making the root blkg unconditional, ec13b1d6f0a0 ("blkcg: always
create the blkcg_gq for the root blkcg") removed the part which clears
q->root_blkg and ->root_rl.blkg during q exit.  This leaves the two
pointers dangling after blkg_destroy_all().  blk-throttle exit path
performs blkg traversals and dereferences ->root_blkg and can lead to
the following oops.

 BUG: unable to handle kernel NULL pointer dereference at 0000000000000558
 IP: [<ffffffff81389746>] __blkg_lookup+0x26/0x70
 ...
 task: ffff88001b4e2580 ti: ffff88001ac0c000 task.ti: ffff88001ac0c000
 RIP: 0010:[<ffffffff81389746>]  [<ffffffff81389746>] __blkg_lookup+0x26/0x70
 ...
 Call Trace:
  [<ffffffff8138d14a>] blk_throtl_drain+0x5a/0x110
  [<ffffffff8138a108>] blkcg_drain_queue+0x18/0x20
  [<ffffffff81369a70>] __blk_drain_queue+0xc0/0x170
  [<ffffffff8136a101>] blk_queue_bypass_start+0x61/0x80
  [<ffffffff81388c59>] blkcg_deactivate_policy+0x39/0x100
  [<ffffffff8138d328>] blk_throtl_exit+0x38/0x50
  [<ffffffff8138a14e>] blkcg_exit_queue+0x3e/0x50
  [<ffffffff8137016e>] blk_release_queue+0x1e/0xc0
 ...

While the bug is a straigh-forward use-after-free bug, it is tricky to
reproduce because blkg release is RCU protected and the rest of exit
path usually finishes before RCU grace period.

This patch fixes the bug by updating blkg_destro_all() to clear
q->root_blkg and ->root_rl.blkg.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: "Richard W.M. Jones" <rjones@redhat.com>
Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
Link: http://lkml.kernel.org/g/CA+5PVA5rzQ0s4723n5rHBcxQa9t0cW8BPPBekr_9aMRoWt2aYg@mail.gmail.com
Fixes: ec13b1d6f0a0 ("blkcg: always create the blkcg_gq for the root blkcg")
Cc: stable@vger.kernel.org # v4.2+
---
Hello,

Richard, can you please verify that this patch fixes the bug?

Thanks a lot!

 block/blk-cgroup.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index d6283b3..9cc48d1d 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -387,6 +387,9 @@ static void blkg_destroy_all(struct request_queue *q)
 		blkg_destroy(blkg);
 		spin_unlock(&blkcg->lock);
 	}
+
+	q->root_blkg = NULL;
+	q->root_rl.blkg = NULL;
 }
 
 /*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

__blkg_lookup oops with 4.2-rcX Josh Boyer <jwboyer@fedoraproject.org> - 2015-08-30 14:40 +0200
  Re: __blkg_lookup oops with 4.2-rcX "Richard W.M. Jones" <rjones@redhat.com> - 2015-08-30 20:10 +0200
  Re: __blkg_lookup oops with 4.2-rcX Tejun Heo <tj@kernel.org> - 2015-09-02 17:00 +0200
    Re: __blkg_lookup oops with 4.2-rcX Tejun Heo <tj@kernel.org> - 2015-09-02 17:40 +0200
      Re: __blkg_lookup oops with 4.2-rcX "Richard W.M. Jones" <rjones@redhat.com> - 2015-09-04 12:50 +0200
        Re: __blkg_lookup oops with 4.2-rcX Tejun Heo <tj@kernel.org> - 2015-09-04 19:20 +0200
          Re: __blkg_lookup oops with 4.2-rcX "Richard W.M. Jones" <rjones@redhat.com> - 2015-09-04 22:50 +0200
            Re: __blkg_lookup oops with 4.2-rcX "Richard W.M. Jones" <rjones@redhat.com> - 2015-09-05 17:50 +0200
              Re: __blkg_lookup oops with 4.2-rcX Tejun Heo <tj@kernel.org> - 2015-09-05 20:40 +0200
                [PATCH block/for-linus] block: blkg_destroy_all() should clear  q->root_blkg and ->root_rl.blkg Tejun Heo <tj@kernel.org> - 2015-09-05 21:50 +0200
                Re: [PATCH block/for-linus] block: blkg_destroy_all() should clear  q->root_blkg and ->root_rl.blkg "Richard W.M. Jones" <rjones@redhat.com> - 2015-09-06 10:40 +0200
                Re: [PATCH block/for-linus] block: blkg_destroy_all() should clear  q->root_blkg and ->root_rl.blkg Jens Axboe <axboe@kernel.dk> - 2015-09-08 17:40 +0200
                Re: [PATCH block/for-linus] block: blkg_destroy_all() should clear  q->root_blkg and ->root_rl.blkg Tejun Heo <tj@kernel.org> - 2015-09-08 17:40 +0200

csiph-web