Ye Bin
572761645b
jbd2: fix a potential race while discarding reserved buffers after an abort
...
commit 23e3d7f7061f8682c751c46512718f47580ad8f0 upstream.
we got issue as follows:
[ 72.796117] EXT4-fs error (device sda): ext4_journal_check_start:83: comm fallocate: Detected aborted journal
[ 72.826847] EXT4-fs (sda): Remounting filesystem read-only
fallocate: fallocate failed: Read-only file system
[ 74.791830] jbd2_journal_commit_transaction: jh=0xffff9cfefe725d90 bh=0x0000000000000000 end delay
[ 74.793597] ------------[ cut here ]------------
[ 74.794203] kernel BUG at fs/jbd2/transaction.c:2063!
[ 74.794886] invalid opcode: 0000 [#1 ] PREEMPT SMP PTI
[ 74.795533] CPU: 4 PID: 2260 Comm: jbd2/sda-8 Not tainted 5.17.0-rc8-next-20220315-dirty #150
[ 74.798327] RIP: 0010:__jbd2_journal_unfile_buffer+0x3e/0x60
[ 74.801971] RSP: 0018:ffffa828c24a3cb8 EFLAGS: 00010202
[ 74.802694] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 74.803601] RDX: 0000000000000001 RSI: ffff9cfefe725d90 RDI: ffff9cfefe725d90
[ 74.804554] RBP: ffff9cfefe725d90 R08: 0000000000000000 R09: ffffa828c24a3b20
[ 74.805471] R10: 0000000000000001 R11: 0000000000000001 R12: ffff9cfefe725d90
[ 74.806385] R13: ffff9cfefe725d98 R14: 0000000000000000 R15: ffff9cfe833a4d00
[ 74.807301] FS: 0000000000000000(0000) GS:ffff9d01afb00000(0000) knlGS:0000000000000000
[ 74.808338] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 74.809084] CR2: 00007f2b81bf4000 CR3: 0000000100056000 CR4: 00000000000006e0
[ 74.810047] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 74.810981] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 74.811897] Call Trace:
[ 74.812241] <TASK>
[ 74.812566] __jbd2_journal_refile_buffer+0x12f/0x180
[ 74.813246] jbd2_journal_refile_buffer+0x4c/0xa0
[ 74.813869] jbd2_journal_commit_transaction.cold+0xa1/0x148
[ 74.817550] kjournald2+0xf8/0x3e0
[ 74.819056] kthread+0x153/0x1c0
[ 74.819963] ret_from_fork+0x22/0x30
Above issue may happen as follows:
write truncate kjournald2
generic_perform_write
ext4_write_begin
ext4_walk_page_buffers
do_journal_get_write_access ->add BJ_Reserved list
ext4_journalled_write_end
ext4_walk_page_buffers
write_end_fn
ext4_handle_dirty_metadata
***************JBD2 ABORT**************
jbd2_journal_dirty_metadata
-> return -EROFS, jh in reserved_list
jbd2_journal_commit_transaction
while (commit_transaction->t_reserved_list)
jh = commit_transaction->t_reserved_list;
truncate_pagecache_range
do_invalidatepage
ext4_journalled_invalidatepage
jbd2_journal_invalidatepage
journal_unmap_buffer
__dispose_buffer
__jbd2_journal_unfile_buffer
jbd2_journal_put_journal_head ->put last ref_count
__journal_remove_journal_head
bh->b_private = NULL;
jh->b_bh = NULL;
jbd2_journal_refile_buffer(journal, jh);
bh = jh2bh(jh);
->bh is NULL, later will trigger null-ptr-deref
journal_free_journal_head(jh);
After commit 96f1e0974575, we no longer hold the j_state_lock while
iterating over the list of reserved handles in
jbd2_journal_commit_transaction(). This potentially allows the
journal_head to be freed by journal_unmap_buffer while the commit
codepath is also trying to free the BJ_Reserved buffers. Keeping
j_state_lock held while trying extends hold time of the lock
minimally, and solves this issue.
Fixes: 96f1e0974575("jbd2: avoid long hold times of j_state_lock while committing a transaction")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220317142137.1821590-1-yebin10@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-27 13:53:57 +02:00
..
2022-01-20 09:17:50 +01:00
2020-10-24 12:26:05 -07:00
2021-03-04 11:38:37 +01:00
2021-09-30 10:11:01 +02:00
2020-10-16 11:11:22 -07:00
2020-09-18 16:45:50 -04:00
2021-01-06 14:56:52 +01:00
2022-04-20 09:23:27 +02:00
2021-03-30 14:32:07 +02:00
2022-04-13 21:01:00 +02:00
2022-04-27 13:53:53 +02:00
2022-03-02 11:42:52 +01:00
2020-09-18 16:45:50 -04:00
2021-11-18 14:03:54 +01:00
2022-01-27 10:54:02 +01:00
2022-02-01 17:25:39 +01:00
2022-01-27 10:54:10 +01:00
2021-05-26 12:06:55 +02:00
2020-11-25 16:55:02 +01:00
2020-09-18 16:45:50 -04:00
2021-12-01 09:19:05 +01:00
2022-03-28 09:57:07 +02:00
2022-04-08 14:40:18 +02:00
2022-04-27 13:53:57 +02:00
2022-04-08 14:40:33 +02:00
2020-09-18 16:45:50 -04:00
2021-09-18 13:40:15 +02:00
2022-03-16 14:16:01 +01:00
2022-04-27 13:53:46 +02:00
2021-07-31 08:16:12 +02:00
2021-05-19 10:13:10 +02:00
2021-04-14 08:42:06 +02:00
2020-09-18 16:45:50 -04:00
2022-04-27 13:53:54 +02:00
2021-09-30 10:11:04 +02:00
2021-11-12 14:58:33 +01:00
2022-04-27 13:53:57 +02:00
2022-04-08 14:39:52 +02:00
2022-04-13 21:01:03 +02:00
2021-01-27 11:55:29 +01:00
2021-09-18 13:40:30 +02:00
2022-04-13 21:01:01 +02:00
2022-04-13 21:01:04 +02:00
2020-12-30 11:53:45 +01:00
2022-04-08 14:40:33 +02:00
2021-09-26 14:09:01 +02:00
2022-02-05 12:37:56 +01:00
2022-04-08 14:40:33 +02:00
2022-03-23 09:13:27 +01:00
2020-09-22 23:39:45 -04:00
2022-01-20 09:17:50 +01:00
2021-12-22 09:30:58 +01:00
2022-04-08 14:40:42 +02:00
2022-04-08 14:39:56 +02:00
2021-09-30 10:11:08 +02:00
2020-09-18 16:45:50 -04:00
2022-02-23 12:00:59 +01:00
2020-10-16 11:11:22 -07:00
2021-08-12 13:22:19 +02:00
2020-10-24 12:26:05 -07:00
2021-05-19 10:13:10 +02:00
2020-10-02 12:02:30 +02:00
2020-09-18 16:45:50 -04:00
2022-03-02 11:42:54 +01:00
2022-04-13 21:00:53 +02:00
2022-02-01 17:25:39 +01:00
2020-10-24 12:26:05 -07:00
2020-09-10 14:03:31 -07:00
2021-10-17 10:43:33 +02:00
2021-10-06 15:55:46 +02:00
2022-01-11 15:25:01 +01:00
2021-12-22 09:30:57 +01:00
2021-12-14 11:32:40 +01:00
2022-04-08 14:40:44 +02:00
2022-04-08 14:40:45 +02:00
2020-08-24 08:49:13 +10:00
2021-03-17 17:06:35 +01:00
2021-06-03 09:00:45 +02:00
2020-10-18 09:27:09 -07:00
2022-04-08 14:40:45 +02:00
2020-10-14 14:54:45 -07:00
2021-07-14 16:56:13 +02:00
2020-07-29 16:14:27 +02:00
2021-04-14 08:41:58 +02:00
2021-05-11 14:47:12 +02:00
2022-04-08 14:39:57 +02:00
2021-09-15 09:50:27 +02:00
2020-10-17 15:05:30 -06:00
2022-04-08 14:40:30 +02:00
2022-02-08 18:30:36 +01:00
2020-10-13 18:38:27 -07:00
2020-07-29 16:14:27 +02:00
2021-07-14 16:56:31 +02:00
2020-08-23 17:36:59 -05:00
2020-08-04 21:02:38 -04:00
2021-11-26 10:39:22 +01:00
2021-07-31 08:16:11 +02:00
2022-04-13 21:01:08 +02:00
2021-09-18 13:40:06 +02:00
2021-02-13 13:54:56 +01:00
2020-07-31 08:16:01 +02:00
2021-02-17 11:02:21 +01:00
2021-10-27 09:56:51 +02:00
2020-11-22 10:48:22 -08:00
2021-03-20 10:43:44 +01:00
2020-10-23 11:33:41 -07:00
2022-02-01 17:25:48 +01:00
2021-08-26 08:35:57 -04:00
2021-07-14 16:55:59 +02:00
2022-03-16 14:16:02 +01:00
2021-03-17 17:06:13 +01:00
2020-12-30 11:54:02 +01:00
2020-10-23 11:33:41 -07:00
2021-04-21 13:00:54 +02:00
2020-10-15 09:48:49 -07:00
2022-01-29 10:26:11 +01:00
2021-07-20 16:05:59 +02:00
2021-12-14 11:32:40 +01:00
2020-10-24 12:40:18 -07:00
2022-04-27 13:53:54 +02:00
2020-08-27 16:06:47 -04:00
2022-02-23 12:00:59 +01:00
2021-10-27 09:56:51 +02:00
2020-07-31 08:16:01 +02:00
2020-10-13 18:38:27 -07:00