Qian Cai
6772387e82
ext4: fix a data race at inode->i_blocks
...
commit 28936b62e71e41600bab319f262ea9f9b1027629 upstream.
inode->i_blocks could be accessed concurrently as noticed by KCSAN,
BUG: KCSAN: data-race in ext4_do_update_inode [ext4] / inode_add_bytes
write to 0xffff9a00d4b982d0 of 8 bytes by task 22100 on cpu 118:
inode_add_bytes+0x65/0xf0
__inode_add_bytes at fs/stat.c:689
(inlined by) inode_add_bytes at fs/stat.c:702
ext4_mb_new_blocks+0x418/0xca0 [ext4]
ext4_ext_map_blocks+0x1a6b/0x27b0 [ext4]
ext4_map_blocks+0x1a9/0x950 [ext4]
_ext4_get_block+0xfc/0x270 [ext4]
ext4_get_block_unwritten+0x33/0x50 [ext4]
__block_write_begin_int+0x22e/0xae0
__block_write_begin+0x39/0x50
ext4_write_begin+0x388/0xb50 [ext4]
ext4_da_write_begin+0x35f/0x8f0 [ext4]
generic_perform_write+0x15d/0x290
ext4_buffered_write_iter+0x11f/0x210 [ext4]
ext4_file_write_iter+0xce/0x9e0 [ext4]
new_sync_write+0x29c/0x3b0
__vfs_write+0x92/0xa0
vfs_write+0x103/0x260
ksys_write+0x9d/0x130
__x64_sys_write+0x4c/0x60
do_syscall_64+0x91/0xb05
entry_SYSCALL_64_after_hwframe+0x49/0xbe
read to 0xffff9a00d4b982d0 of 8 bytes by task 8 on cpu 65:
ext4_do_update_inode+0x4a0/0xf60 [ext4]
ext4_inode_blocks_set at fs/ext4/inode.c:4815
ext4_mark_iloc_dirty+0xaf/0x160 [ext4]
ext4_mark_inode_dirty+0x129/0x3e0 [ext4]
ext4_convert_unwritten_extents+0x253/0x2d0 [ext4]
ext4_convert_unwritten_io_end_vec+0xc5/0x150 [ext4]
ext4_end_io_rsv_work+0x22c/0x350 [ext4]
process_one_work+0x54f/0xb90
worker_thread+0x80/0x5f0
kthread+0x1cd/0x1f0
ret_from_fork+0x27/0x50
4 locks held by kworker/u256:0/8:
#0 : ffff9a025abc4328 ((wq_completion)ext4-rsv-conversion){+.+.}, at: process_one_work+0x443/0xb90
#1 : ffffab5a862dbe20 ((work_completion)(&ei->i_rsv_conversion_work)){+.+.}, at: process_one_work+0x443/0xb90
#2 : ffff9a025a9d0f58 (jbd2_handle){++++}, at: start_this_handle+0x1c1/0x9d0 [jbd2]
#3 : ffff9a00d4b985d8 (&(&ei->i_raw_lock)->rlock){+.+.}, at: ext4_do_update_inode+0xaa/0xf60 [ext4]
irq event stamp: 3009267
hardirqs last enabled at (3009267): [<ffffffff980da9b7>] __find_get_block+0x107/0x790
hardirqs last disabled at (3009266): [<ffffffff980da8f9>] __find_get_block+0x49/0x790
softirqs last enabled at (3009230): [<ffffffff98a0034c>] __do_softirq+0x34c/0x57c
softirqs last disabled at (3009223): [<ffffffff97cc67a2>] irq_exit+0xa2/0xc0
Reported by Kernel Concurrency Sanitizer on:
CPU: 65 PID: 8 Comm: kworker/u256:0 Tainted: G L 5.6.0-rc2-next-20200221+ #7
Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019
Workqueue: ext4-rsv-conversion ext4_end_io_rsv_work [ext4]
The plain read is outside of inode->i_lock critical section which
results in a data race. Fix it by adding READ_ONCE() there.
Link: https://lore.kernel.org/r/20200222043258.2279-1-cai@lca.pw
Signed-off-by: Qian Cai <cai@lca.pw>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-17 10:50:21 +02:00
..
2019-09-27 15:10:34 -07:00
2019-07-19 11:33:22 -07:00
2020-01-17 19:48:50 +01:00
2020-04-17 10:49:57 +02:00
2019-10-25 00:03:11 -04:00
2019-08-30 07:27:17 -07:00
2019-08-30 07:27:17 -07:00
2020-04-17 10:50:15 +02:00
2020-04-13 10:48:11 +02:00
2020-04-17 10:50:14 +02:00
2019-09-19 09:42:37 -07:00
2020-02-11 04:35:12 -08:00
2019-11-23 21:44:49 -05:00
2020-03-18 07:17:53 +01:00
2020-04-17 10:50:02 +02:00
2019-09-03 09:30:56 -04:00
2019-07-12 17:37:53 -07:00
2020-02-28 17:22:26 +01:00
2019-07-19 10:42:02 -07:00
2019-08-30 07:27:17 -07:00
2020-04-17 10:50:16 +02:00
2019-11-10 11:56:05 -05:00
2020-02-11 04:35:45 -08:00
2020-04-17 10:50:21 +02:00
2020-03-05 16:43:48 +01:00
2020-03-12 13:00:19 +01:00
2019-08-30 07:27:17 -07:00
2019-07-10 18:43:43 -07:00
2020-03-18 07:17:52 +01:00
2020-04-17 10:50:03 +02:00
2019-07-16 19:23:23 -07:00
2019-08-30 08:11:25 -07:00
2020-01-04 19:19:19 +01:00
2020-01-04 19:17:31 +01:00
2019-09-19 09:42:37 -07:00
2020-03-21 08:11:57 +01:00
2019-12-04 22:31:06 +01:00
2019-09-19 09:42:37 -07:00
2019-12-13 08:42:53 +01:00
2019-07-03 17:52:09 -04:00
2019-08-30 07:27:17 -07:00
2020-04-17 10:50:20 +02:00
2020-04-17 10:50:20 +02:00
2019-07-01 08:25:34 -07:00
2020-01-12 12:21:38 +01:00
2020-02-11 04:35:12 -08:00
2020-02-24 08:37:00 +01:00
2019-08-30 08:11:25 -07:00
2019-07-19 10:42:02 -07:00
2020-02-24 08:37:02 +01:00
2020-02-11 04:35:24 -08:00
2019-10-19 06:32:32 -04:00
2020-04-17 10:50:12 +02:00
2019-08-30 07:27:17 -07:00
2019-08-30 07:27:17 -07:00
2020-01-12 12:21:37 +01:00
2019-09-12 21:05:34 -04:00
2020-02-24 08:37:00 +01:00
2019-09-19 10:06:57 -07:00
2019-09-19 10:06:57 -07:00
2019-07-19 10:42:02 -07:00
2019-08-30 07:27:18 -07:00
2019-10-12 20:49:07 -04:00
2020-03-05 16:43:50 +01:00
2020-02-24 08:36:44 +01:00
2019-09-19 09:42:37 -07:00
2019-09-17 11:48:24 -04:00
2019-08-12 19:33:50 -07:00
2020-03-05 16:43:51 +01:00
2020-02-11 04:35:37 -08:00
2019-07-19 10:42:02 -07:00
2020-02-11 04:35:12 -08:00
2019-05-30 11:26:32 -07:00
2019-10-06 13:53:27 -07:00
2019-07-16 19:23:22 -07:00
2019-07-19 10:42:02 -07:00
2019-12-13 08:43:19 +01:00
2020-01-17 19:48:21 +01:00
2020-01-14 20:08:18 +01:00
2019-05-30 11:29:21 -07:00
2020-01-09 10:20:05 +01:00
2019-06-19 17:09:55 +02:00
2019-08-03 07:02:01 -07:00
2019-08-30 19:31:09 -04:00
2020-03-05 16:43:36 +01:00
2019-07-20 09:15:51 -07:00
2019-10-14 15:04:01 -07:00
2020-01-12 12:21:37 +01:00
2020-02-11 04:35:37 -08:00
2020-03-25 08:25:57 +01:00
2020-04-17 10:50:12 +02:00
2019-08-07 21:51:47 -04:00
2019-08-19 11:00:39 -04:00
2019-09-06 21:28:49 +02:00
2019-09-12 21:06:14 -04:00
2019-07-16 22:52:37 -04:00
2020-02-11 04:35:11 -08:00
2019-07-19 10:42:02 -07:00
2020-03-25 08:25:58 +01:00
2020-01-17 19:48:21 +01:00
2020-04-17 10:50:16 +02:00
2019-12-17 19:55:30 +01:00
2019-09-18 16:59:14 -07:00
2019-06-24 09:16:47 +10:00
2020-04-01 11:02:17 +02:00
2020-03-25 08:25:41 +01:00
2019-09-18 16:59:14 -07:00
2019-07-16 22:52:37 -04:00
2020-01-17 19:48:21 +01:00
2020-03-05 16:43:48 +01:00
2019-10-16 23:15:09 -04:00
2019-05-30 11:26:32 -07:00
2019-05-25 18:00:06 -04:00
2020-03-18 07:17:51 +01:00
2019-05-25 18:00:07 -04:00
2019-06-17 17:36:09 -04:00
2019-05-30 11:29:53 -07:00
2019-09-06 21:28:49 +02:00
2020-02-11 04:35:23 -08:00
2020-01-29 16:45:31 +01:00
2019-07-16 19:23:25 -07:00
2019-08-13 16:06:52 -07:00
2019-12-17 19:56:52 +01:00
2019-10-03 14:21:35 -07:00
2020-01-12 12:21:38 +01:00
2019-08-01 20:51:23 +02:00
2020-01-04 19:18:32 +01:00
2020-02-11 04:35:12 -08:00