Zhihao Cheng
c01e527d40
quota: Check next/prev free block number after reading from quota file
...
commit 6c8ea8b8cd4722efd419f91ca46a2dc81b7d89a3 upstream.
Following process:
Init: v2_read_file_info: <3> dqi_free_blk 0 dqi_free_entry 5 dqi_blks 6
Step 1. chown bin f_a -> dquot_acquire -> v2_write_dquot:
qtree_write_dquot
do_insert_tree
find_free_dqentry
get_free_dqblk
write_blk(info->dqi_blocks) // info->dqi_blocks = 6, failure. The
content in physical block (corresponding to blk 6) is random.
Step 2. chown root f_a -> dquot_transfer -> dqput_all -> dqput ->
ext4_release_dquot -> v2_release_dquot -> qtree_delete_dquot:
dquot_release
remove_tree
free_dqentry
put_free_dqblk(6)
info->dqi_free_blk = blk // info->dqi_free_blk = 6
Step 3. drop cache (buffer head for block 6 is released)
Step 4. chown bin f_b -> dquot_acquire -> commit_dqblk -> v2_write_dquot:
qtree_write_dquot
do_insert_tree
find_free_dqentry
get_free_dqblk
dh = (struct qt_disk_dqdbheader *)buf
blk = info->dqi_free_blk // 6
ret = read_blk(info, blk, buf) // The content of buf is random
info->dqi_free_blk = le32_to_cpu(dh->dqdh_next_free) // random blk
Step 5. chown bin f_c -> notify_change -> ext4_setattr -> dquot_transfer:
dquot = dqget -> acquire_dquot -> ext4_acquire_dquot -> dquot_acquire ->
commit_dqblk -> v2_write_dquot -> dq_insert_tree:
do_insert_tree
find_free_dqentry
get_free_dqblk
blk = info->dqi_free_blk // If blk < 0 and blk is not an error
code, it will be returned as dquot
transfer_to[USRQUOTA] = dquot // A random negative value
__dquot_transfer(transfer_to)
dquot_add_inodes(transfer_to[cnt])
spin_lock(&dquot->dq_dqb_lock) // page fault
, which will lead to kernel page fault:
Quota error (device sda): qtree_write_dquot: Error -8000 occurred
while creating quota
BUG: unable to handle page fault for address: ffffffffffffe120
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
Oops: 0002 [#1 ] PREEMPT SMP
CPU: 0 PID: 5974 Comm: chown Not tainted 6.0.0-rc1-00004
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
RIP: 0010:_raw_spin_lock+0x3a/0x90
Call Trace:
dquot_add_inodes+0x28/0x270
__dquot_transfer+0x377/0x840
dquot_transfer+0xde/0x540
ext4_setattr+0x405/0x14d0
notify_change+0x68e/0x9f0
chown_common+0x300/0x430
__x64_sys_fchownat+0x29/0x40
In order to avoid accessing invalid quota memory address, this patch adds
block number checking of next/prev free block read from quota file.
Fetch a reproducer in [Link].
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216372
Fixes: 1da177e4c3f4152 ("Linux-2.6.12-rc2")
CC: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220923134555.2623931-2-chengzhihao1@huawei.com
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-10-26 13:15:37 +02:00
..
2022-06-25 11:44:57 +02:00
2019-08-06 18:29:35 +02:00
2020-09-12 11:47:39 +02:00
2020-01-29 10:24:34 +01:00
2019-12-21 10:40:46 +01:00
2018-12-01 09:44:19 +01:00
2022-09-05 10:23:56 +02:00
2020-11-10 10:24:00 +01:00
2022-10-26 13:15:35 +02:00
2022-09-28 10:55:44 +02:00
2019-08-06 18:29:38 +02:00
2022-03-02 11:32:03 +01:00
2018-11-13 11:17:03 -08:00
2021-07-20 16:21:11 +02:00
2019-05-08 07:19:10 +02:00
2019-03-23 13:19:47 +01:00
2022-10-26 13:15:37 +02:00
2021-05-26 11:29:07 +02:00
2020-12-02 08:31:28 +01:00
2018-11-27 16:09:38 +01:00
2020-01-29 10:24:03 +01:00
2022-04-20 09:06:35 +02:00
2022-09-28 10:55:47 +02:00
2021-05-22 10:40:30 +02:00
2022-06-14 16:52:30 +02:00
2018-12-17 09:38:34 +01:00
2022-08-25 11:09:24 +02:00
2022-04-27 13:14:10 +02:00
2021-08-04 11:58:02 +02:00
2020-04-24 07:58:59 +02:00
2021-06-03 08:23:33 +02:00
2021-11-12 13:18:02 +01:00
2020-09-03 11:21:19 +02:00
2022-06-14 16:52:38 +02:00
2022-06-14 16:52:30 +02:00
2019-11-25 09:52:23 +01:00
2020-12-29 13:44:57 +01:00
2020-08-21 11:02:06 +02:00
2019-03-13 14:04:52 -07:00
2022-08-25 11:09:28 +02:00
2020-12-29 13:44:59 +01:00
2022-06-06 08:19:46 +02:00
2022-10-26 13:15:35 +02:00
2022-06-14 16:52:31 +02:00
2022-10-26 13:15:32 +02:00
2022-06-14 16:52:34 +02:00
2021-11-26 11:48:38 +01:00
2021-10-17 10:05:38 +02:00
2022-08-25 11:09:21 +02:00
2020-01-12 11:24:20 +01:00
2021-10-06 10:23:41 +02:00
2022-10-26 13:15:37 +02:00
2021-08-15 13:01:04 +02:00
2020-08-26 10:29:03 +02:00
2021-05-22 10:40:32 +02:00
2022-03-23 09:00:34 +01:00
2018-12-17 09:38:32 +01:00
2022-09-20 11:50:16 +02:00
2022-04-20 09:06:40 +02:00
2022-02-08 18:15:26 +01:00
2020-08-21 11:02:11 +02:00
2022-07-12 16:26:24 +02:00
2018-12-21 14:11:31 +01:00
2022-08-25 11:09:23 +02:00
2017-01-09 08:32:24 +01:00
2020-06-03 08:16:42 +02:00
2019-07-10 09:55:38 +02:00
2021-03-17 16:10:18 +01:00
2019-11-06 12:18:04 +01:00
2020-10-01 20:40:12 +02:00
2020-11-10 10:23:56 +01:00
2020-05-20 08:15:32 +02:00
2018-02-25 11:05:55 +01:00
2020-06-30 15:38:35 -04:00
2017-07-05 14:40:26 +02:00
2018-02-28 10:18:33 +01:00
2019-03-27 14:13:04 +09:00
2021-04-16 11:59:07 +02:00
2019-03-13 14:04:58 -07:00
2020-10-14 09:48:13 +02:00
2022-06-06 08:19:46 +02:00
2018-01-31 12:55:52 +01:00
2021-12-08 08:45:06 +01:00
2022-03-02 11:32:07 +01:00
2022-06-14 16:52:34 +02:00
2022-10-26 13:15:34 +02:00
2017-09-20 08:20:01 +02:00
2017-09-20 08:19:59 +02:00
2020-11-24 13:03:05 +01:00
2020-01-12 11:24:13 +01:00
2018-02-22 15:43:48 +01:00
2017-07-21 07:42:22 +02:00
2017-10-18 09:35:39 +02:00
2020-03-11 07:53:07 +01:00
2021-08-26 08:37:29 -04:00
2018-02-17 13:21:15 +01:00
2020-03-20 09:07:44 +01:00
2021-08-15 13:01:03 +02:00
2020-05-02 17:23:20 +02:00
2017-03-15 10:02:43 +08:00
2017-01-26 08:24:37 +01:00
2019-06-11 12:22:49 +02:00
2020-01-04 13:41:06 +01:00
2021-03-24 10:59:25 +01:00
2021-07-20 16:21:16 +02:00
2021-12-14 10:04:48 +01:00
2019-06-11 12:22:45 +02:00
2017-06-14 15:06:01 +02:00
2022-02-23 11:56:39 +01:00
2017-05-08 07:47:54 +02:00
2019-09-06 10:19:37 +02:00
2020-08-21 11:01:55 +02:00