* FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree
@ 2019-10-12 8:17 gregkh
2019-10-12 14:34 ` Sasha Levin
2019-10-12 21:54 ` Linus Torvalds
0 siblings, 2 replies; 4+ messages in thread
From: gregkh @ 2019-10-12 8:17 UTC (permalink / raw)
To: tj, akpm, axboe, clm, jack, stable, torvalds; +Cc: stable
The patch below does not apply to the 5.3-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8e00c4e9dd852f7a9bf12234fad65a2f2f93788f Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj@kernel.org>
Date: Sun, 6 Oct 2019 17:58:09 -0700
Subject: [PATCH] writeback: fix use-after-free in finish_writeback_work()
finish_writeback_work() reads @done->waitq after decrementing
@done->cnt. However, once @done->cnt reaches zero, @done may be freed
(from stack) at any moment and @done->waitq can contain something
unrelated by the time finish_writeback_work() tries to read it. This
led to the following crash.
"BUG: kernel NULL pointer dereference, address: 0000000000000002"
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
PGD 0 P4D 0
Oops: 0002 [#1] SMP DEBUG_PAGEALLOC
CPU: 40 PID: 555153 Comm: kworker/u98:50 Kdump: loaded Not tainted
...
Workqueue: writeback wb_workfn (flush-btrfs-1)
RIP: 0010:_raw_spin_lock_irqsave+0x10/0x30
Code: 48 89 d8 5b c3 e8 50 db 6b ff eb f4 0f 1f 40 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 53 9c 5b fa 31 c0 ba 01 00 00 00 <f0> 0f b1 17 75 05 48 89 d8 5b c3 89 c6 e8 fe ca 6b ff eb f2 66 90
RSP: 0018:ffffc90049b27d98 EFLAGS: 00010046
RAX: 0000000000000000 RBX: 0000000000000246 RCX: 0000000000000000
RDX: 0000000000000001 RSI: 0000000000000003 RDI: 0000000000000002
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001
R10: ffff889fff407600 R11: ffff88ba9395d740 R12: 000000000000e300
R13: 0000000000000003 R14: 0000000000000000 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff88bfdfa00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000002 CR3: 0000000002409005 CR4: 00000000001606e0
Call Trace:
__wake_up_common_lock+0x63/0xc0
wb_workfn+0xd2/0x3e0
process_one_work+0x1f5/0x3f0
worker_thread+0x2d/0x3d0
kthread+0x111/0x130
ret_from_fork+0x1f/0x30
Fix it by reading and caching @done->waitq before decrementing
@done->cnt.
Link: http://lkml.kernel.org/r/20190924010631.GH2233839@devbig004.ftw2.facebook.com
Fixes: 5b9cce4c7eb069 ("writeback: Generalize and expose wb_completion")
Signed-off-by: Tejun Heo <tj@kernel.org>
Debugged-by: Chris Mason <clm@fb.com>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Cc: Jan Kara <jack@suse.cz>
Cc: <stable@vger.kernel.org> [5.2+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 8aaa7eec7b74..e88421d9a48d 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -164,8 +164,13 @@ static void finish_writeback_work(struct bdi_writeback *wb,
if (work->auto_free)
kfree(work);
- if (done && atomic_dec_and_test(&done->cnt))
- wake_up_all(done->waitq);
+ if (done) {
+ wait_queue_head_t *waitq = done->waitq;
+
+ /* @done can't be accessed after the following dec */
+ if (atomic_dec_and_test(&done->cnt))
+ wake_up_all(waitq);
+ }
}
static void wb_queue_work(struct bdi_writeback *wb,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree
2019-10-12 8:17 FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree gregkh
@ 2019-10-12 14:34 ` Sasha Levin
2019-10-12 21:54 ` Linus Torvalds
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2019-10-12 14:34 UTC (permalink / raw)
To: gregkh; +Cc: tj, akpm, axboe, clm, jack, stable, torvalds
On Sat, Oct 12, 2019 at 10:17:58AM +0200, gregkh@linuxfoundation.org wrote:
>
>The patch below does not apply to the 5.3-stable tree.
>If someone wants it applied there, or to any other stable or longterm
>tree, then please email the backport, including the original git commit
>id to <stable@vger.kernel.org>.
>
>thanks,
>
>greg k-h
>
>------------------ original commit in Linus's tree ------------------
>
>From 8e00c4e9dd852f7a9bf12234fad65a2f2f93788f Mon Sep 17 00:00:00 2001
>From: Tejun Heo <tj@kernel.org>
>Date: Sun, 6 Oct 2019 17:58:09 -0700
>Subject: [PATCH] writeback: fix use-after-free in finish_writeback_work()
>
>finish_writeback_work() reads @done->waitq after decrementing
>@done->cnt. However, once @done->cnt reaches zero, @done may be freed
>(from stack) at any moment and @done->waitq can contain something
>unrelated by the time finish_writeback_work() tries to read it. This
>led to the following crash.
>
> "BUG: kernel NULL pointer dereference, address: 0000000000000002"
> #PF: supervisor write access in kernel mode
> #PF: error_code(0x0002) - not-present page
> PGD 0 P4D 0
> Oops: 0002 [#1] SMP DEBUG_PAGEALLOC
> CPU: 40 PID: 555153 Comm: kworker/u98:50 Kdump: loaded Not tainted
> ...
> Workqueue: writeback wb_workfn (flush-btrfs-1)
> RIP: 0010:_raw_spin_lock_irqsave+0x10/0x30
> Code: 48 89 d8 5b c3 e8 50 db 6b ff eb f4 0f 1f 40 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 53 9c 5b fa 31 c0 ba 01 00 00 00 <f0> 0f b1 17 75 05 48 89 d8 5b c3 89 c6 e8 fe ca 6b ff eb f2 66 90
> RSP: 0018:ffffc90049b27d98 EFLAGS: 00010046
> RAX: 0000000000000000 RBX: 0000000000000246 RCX: 0000000000000000
> RDX: 0000000000000001 RSI: 0000000000000003 RDI: 0000000000000002
> RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000001
> R10: ffff889fff407600 R11: ffff88ba9395d740 R12: 000000000000e300
> R13: 0000000000000003 R14: 0000000000000000 R15: 0000000000000000
> FS: 0000000000000000(0000) GS:ffff88bfdfa00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000000000002 CR3: 0000000002409005 CR4: 00000000001606e0
> Call Trace:
> __wake_up_common_lock+0x63/0xc0
> wb_workfn+0xd2/0x3e0
> process_one_work+0x1f5/0x3f0
> worker_thread+0x2d/0x3d0
> kthread+0x111/0x130
> ret_from_fork+0x1f/0x30
>
>Fix it by reading and caching @done->waitq before decrementing
>@done->cnt.
>
>Link: http://lkml.kernel.org/r/20190924010631.GH2233839@devbig004.ftw2.facebook.com
>Fixes: 5b9cce4c7eb069 ("writeback: Generalize and expose wb_completion")
Hm... 5b9cce4c7eb069 went upstream during the 5.4 merge window, but:
>Signed-off-by: Tejun Heo <tj@kernel.org>
>Debugged-by: Chris Mason <clm@fb.com>
>Reviewed-by: Jens Axboe <axboe@kernel.dk>
>Cc: Jan Kara <jack@suse.cz>
>Cc: <stable@vger.kernel.org> [5.2+]
This tag says that 8e00c4e9dd85 should be backported to 5.3.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree
2019-10-12 8:17 FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree gregkh
2019-10-12 14:34 ` Sasha Levin
@ 2019-10-12 21:54 ` Linus Torvalds
2019-10-14 15:40 ` Tejun Heo
1 sibling, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2019-10-12 21:54 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Tejun Heo, Andrew Morton, Jens Axboe, Chris Mason, Jan Kara, stable
On Sat, Oct 12, 2019 at 1:18 AM <gregkh@linuxfoundation.org> wrote:
>
> The patch below does not apply to the 5.3-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
Hmm. It looks to me like 5.3 doesn't have the use-after-free problem,
and that it was introduced by 5b9cce4c7eb0696558 ("writeback:
Generalize and expose wb_completion")
So I think the "Fixes" tag is right, and the "Cc: stable" is wrong.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree
2019-10-12 21:54 ` Linus Torvalds
@ 2019-10-14 15:40 ` Tejun Heo
0 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2019-10-14 15:40 UTC (permalink / raw)
To: Linus Torvalds
Cc: Greg Kroah-Hartman, Andrew Morton, Jens Axboe, Chris Mason,
Jan Kara, stable
On Sat, Oct 12, 2019 at 02:54:26PM -0700, Linus Torvalds wrote:
> On Sat, Oct 12, 2019 at 1:18 AM <gregkh@linuxfoundation.org> wrote:
> >
> > The patch below does not apply to the 5.3-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
>
> Hmm. It looks to me like 5.3 doesn't have the use-after-free problem,
> and that it was introduced by 5b9cce4c7eb0696558 ("writeback:
> Generalize and expose wb_completion")
>
> So I think the "Fixes" tag is right, and the "Cc: stable" is wrong.
Yeap, sorry about that. I think I forgot --contains when running
git-describe and mindlessly copied the output.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-10-14 15:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-12 8:17 FAILED: patch "[PATCH] writeback: fix use-after-free in finish_writeback_work()" failed to apply to 5.3-stable tree gregkh
2019-10-12 14:34 ` Sasha Levin
2019-10-12 21:54 ` Linus Torvalds
2019-10-14 15:40 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).