aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2013-03-11 13:24:56 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-03-11 13:24:56 -0400
commitad56edad089b56300fd13bb9eeb7d0424d978239 (patch)
treebb350333433690e5a7ce3f2481c055c78ac5fef7 /fs
parent386ad67c9ac043890121c066186883d1640348a4 (diff)
jbd2: fix use after free in jbd2_journal_dirty_metadata()
jbd2_journal_dirty_metadata() didn't get a reference to journal_head it was working with. This is OK in most of the cases since the journal head should be attached to a transaction but in rare occasions when we are journalling data, __ext4_journalled_writepage() can race with jbd2_journal_invalidatepage() stripping buffers from a page and thus journal head can be freed under hands of jbd2_journal_dirty_metadata(). Fix the problem by getting own journal head reference in jbd2_journal_dirty_metadata() (and also in jbd2_journal_set_triggers() which can possibly have the same issue). Reported-by: Zheng Liu <gnehzuil.liu@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: stable@vger.kernel.org
Diffstat (limited to 'fs')
-rw-r--r--fs/jbd2/transaction.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index d6ee5aed56b1..325bc019ed88 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -1065,9 +1065,12 @@ out:
1065void jbd2_journal_set_triggers(struct buffer_head *bh, 1065void jbd2_journal_set_triggers(struct buffer_head *bh,
1066 struct jbd2_buffer_trigger_type *type) 1066 struct jbd2_buffer_trigger_type *type)
1067{ 1067{
1068 struct journal_head *jh = bh2jh(bh); 1068 struct journal_head *jh = jbd2_journal_grab_journal_head(bh);
1069 1069
1070 if (WARN_ON(!jh))
1071 return;
1070 jh->b_triggers = type; 1072 jh->b_triggers = type;
1073 jbd2_journal_put_journal_head(jh);
1071} 1074}
1072 1075
1073void jbd2_buffer_frozen_trigger(struct journal_head *jh, void *mapped_data, 1076void jbd2_buffer_frozen_trigger(struct journal_head *jh, void *mapped_data,
@@ -1119,17 +1122,18 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
1119{ 1122{
1120 transaction_t *transaction = handle->h_transaction; 1123 transaction_t *transaction = handle->h_transaction;
1121 journal_t *journal = transaction->t_journal; 1124 journal_t *journal = transaction->t_journal;
1122 struct journal_head *jh = bh2jh(bh); 1125 struct journal_head *jh;
1123 int ret = 0; 1126 int ret = 0;
1124 1127
1125 jbd_debug(5, "journal_head %p\n", jh);
1126 JBUFFER_TRACE(jh, "entry");
1127 if (is_handle_aborted(handle)) 1128 if (is_handle_aborted(handle))
1128 goto out; 1129 goto out;
1129 if (!buffer_jbd(bh)) { 1130 jh = jbd2_journal_grab_journal_head(bh);
1131 if (!jh) {
1130 ret = -EUCLEAN; 1132 ret = -EUCLEAN;
1131 goto out; 1133 goto out;
1132 } 1134 }
1135 jbd_debug(5, "journal_head %p\n", jh);
1136 JBUFFER_TRACE(jh, "entry");
1133 1137
1134 jbd_lock_bh_state(bh); 1138 jbd_lock_bh_state(bh);
1135 1139
@@ -1220,6 +1224,7 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
1220 spin_unlock(&journal->j_list_lock); 1224 spin_unlock(&journal->j_list_lock);
1221out_unlock_bh: 1225out_unlock_bh:
1222 jbd_unlock_bh_state(bh); 1226 jbd_unlock_bh_state(bh);
1227 jbd2_journal_put_journal_head(jh);
1223out: 1228out:
1224 JBUFFER_TRACE(jh, "exit"); 1229 JBUFFER_TRACE(jh, "exit");
1225 WARN_ON(ret); /* All errors are bugs, so dump the stack */ 1230 WARN_ON(ret); /* All errors are bugs, so dump the stack */