add patch fix-fencepost-in-s_first_meta_bg-validation
[ext4-patch-queue.git] / dont-leak-modified-metadata-buffers-on-an-aborted-journal
blob4f2307a5d801302079e9a70b12ae492081353bdc
1 jbd2: don't leak modified metadata buffers on an aborted journal
3 If the journal has been aborted, we shouldn't mark the underlying
4 buffer head as dirty, since that will cause the metadata block to get
5 modified.  And if the journal has been aborted, we shouldn't allow
6 this since it will almost certainly lead to a corrupted file system.
8 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 Cc: stable@vger.kernel.org
10 ---
11  fs/jbd2/transaction.c | 4 +++-
12  1 file changed, 3 insertions(+), 1 deletion(-)
14 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
15 index e1652665bd93..5e659ee08d6a 100644
16 --- a/fs/jbd2/transaction.c
17 +++ b/fs/jbd2/transaction.c
18 @@ -1863,7 +1863,9 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
20         __blist_del_buffer(list, jh);
21         jh->b_jlist = BJ_None;
22 -       if (test_clear_buffer_jbddirty(bh))
23 +       if (transaction && is_journal_aborted(transaction->t_journal))
24 +               clear_buffer_jbddirty(bh);
25 +       else if (test_clear_buffer_jbddirty(bh))
26                 mark_buffer_dirty(bh);  /* Expose it to the VM */
27  }