1 From cd9cb405e0b948363811dc74dbb2890f56f2cb87 Mon Sep 17 00:00:00 2001
2 From: Eric Biggers <ebiggers@google.com>
3 Date: Wed, 15 Mar 2017 15:08:48 -0400
4 Subject: jbd2: don't leak memory if setting up journal fails
6 From: Eric Biggers <ebiggers@google.com>
8 commit cd9cb405e0b948363811dc74dbb2890f56f2cb87 upstream.
10 In journal_init_common(), if we failed to allocate the j_wbuf array, or
11 if we failed to create the buffer_head for the journal superblock, we
12 leaked the memory allocated for the revocation tables. Fix this.
14 Fixes: f0c9fd5458bacf7b12a9a579a727dc740cbe047e
15 Signed-off-by: Eric Biggers <ebiggers@google.com>
16 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
17 Reviewed-by: Jan Kara <jack@suse.cz>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 fs/jbd2/journal.c | 22 +++++++++++-----------
22 fs/jbd2/revoke.c | 1 +
23 2 files changed, 12 insertions(+), 11 deletions(-)
25 --- a/fs/jbd2/journal.c
26 +++ b/fs/jbd2/journal.c
27 @@ -1125,10 +1125,8 @@ static journal_t *journal_init_common(st
29 /* Set up a default-sized revoke table for the new mount. */
30 err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
38 spin_lock_init(&journal->j_history_lock);
40 @@ -1145,23 +1143,25 @@ static journal_t *journal_init_common(st
41 journal->j_wbufsize = n;
42 journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *),
44 - if (!journal->j_wbuf) {
48 + if (!journal->j_wbuf)
51 bh = getblk_unmovable(journal->j_dev, start, journal->j_blocksize);
53 pr_err("%s: Cannot get buffer for journal superblock\n",
55 - kfree(journal->j_wbuf);
60 journal->j_sb_buffer = bh;
61 journal->j_superblock = (journal_superblock_t *)bh->b_data;
66 + kfree(journal->j_wbuf);
67 + jbd2_journal_destroy_revoke(journal);
72 /* jbd2_journal_init_dev and jbd2_journal_init_inode:
73 --- a/fs/jbd2/revoke.c
74 +++ b/fs/jbd2/revoke.c
75 @@ -280,6 +280,7 @@ int jbd2_journal_init_revoke(journal_t *
78 jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]);
79 + journal->j_revoke_table[0] = NULL;