]> git.baikalelectronics.ru Git - kernel.git/commit
jbd2: fix use after free in jbd2_log_do_checkpoint()
authorJan Kara <jack@suse.cz>
Fri, 5 Oct 2018 22:44:40 +0000 (18:44 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 5 Oct 2018 22:44:40 +0000 (18:44 -0400)
commit7cc2f65e536d53de4bd1ce618a7c71fd7514a9eb
treeef20ba8dba7c3d9346f31a2a559366beb71eac29
parent78e40ef5de73f6e0bd981b5c7143ad9469cd643c
jbd2: fix use after free in jbd2_log_do_checkpoint()

The code cleaning transaction's lists of checkpoint buffers has a bug
where it increases bh refcount only after releasing
journal->j_list_lock. Thus the following race is possible:

CPU0 CPU1
jbd2_log_do_checkpoint()
jbd2_journal_try_to_free_buffers()
  __journal_try_to_free_buffer(bh)
  ...
  while (transaction->t_checkpoint_io_list)
  ...
    if (buffer_locked(bh)) {

<-- IO completes now, buffer gets unlocked -->

      spin_unlock(&journal->j_list_lock);
    spin_lock(&journal->j_list_lock);
    __jbd2_journal_remove_checkpoint(jh);
    spin_unlock(&journal->j_list_lock);
  try_to_free_buffers(page);
      get_bh(bh) <-- accesses freed bh

Fix the problem by grabbing bh reference before unlocking
journal->j_list_lock.

Fixes: 5267d0791831 ("jbd2: don't call get_bh() before calling __jbd2_journal_remove_checkpoint()")
Fixes: 8799ee584366 ("jbd2: fold __process_buffer() into jbd2_log_do_checkpoint()")
Reported-by: syzbot+7f4a27091759e2fe7453@syzkaller.appspotmail.com
CC: stable@vger.kernel.org
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/checkpoint.c