Re: KASAN: use-after-free Write in jbd2_log_do_checkpoint

From: Jan Kara
Date: Thu Oct 04 2018 - 06:27:51 EST


On Mon 17-09-18 04:19:02, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit: 2e2a0c961a87 Merge branch 'progarray_mapinmap_dump'
> git tree: bpf-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=17622811400000
> kernel config: https://syzkaller.appspot.com/x/.config?x=8f59875069d721b6
> dashboard link: https://syzkaller.appspot.com/bug?extid=7f4a27091759e2fe7453
> compiler: gcc (GCC) 8.0.1 20180413 (experimental)
>
> Unfortunately, I don't have any reproducer for this crash yet.
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+7f4a27091759e2fe7453@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> ==================================================================
> BUG: KASAN: use-after-free in atomic_inc
> include/asm-generic/atomic-instrumented.h:109 [inline]
> BUG: KASAN: use-after-free in get_bh include/linux/buffer_head.h:283
> [inline]
> BUG: KASAN: use-after-free in jbd2_log_do_checkpoint+0x113d/0x13e0
> fs/jbd2/checkpoint.c:337
> Write of size 4 at addr ffff8801b6d96300 by task syz-executor1/904

This is at:

if (buffer_locked(bh)) {
spin_unlock(&journal->j_list_lock);
get_bh(bh);
wait_on_buffer(bh);
/* the journal_head may have gone by now */
BUFFER_TRACE(bh, "brelse");
__brelse(bh);
spin_lock(&journal->j_list_lock);
goto restart2;
}

And indeed that get_bh() should be called before we unlock j_list_lock as
otherwise we can race with jbd2_journal_try_to_free_buffers(). I'll send a
fix.

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR