Chen Zhongjin
8eb2fd54d1
profiling: fix shift too large makes kernel panic
...
[ Upstream commit 0fe6ee8f12
]
2d186afd04
("profiling: fix shift-out-of-bounds bugs") limits shift
value by [0, BITS_PER_LONG -1], which means [0, 63].
However, syzbot found that the max shift value should be the bit number of
(_etext - _stext). If shift is outside of this, the "buffer_bytes" will
be zero and will cause kzalloc(0). Then the kernel panics due to
dereferencing the returned pointer 16.
This can be easily reproduced by passing a large number like 60 to enable
profiling and then run readprofile.
LOGS:
BUG: kernel NULL pointer dereference, address: 0000000000000010
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
PGD 6148067 P4D 6148067 PUD 6142067 PMD 0
PREEMPT SMP
CPU: 4 PID: 184 Comm: readprofile Not tainted 5.18.0+ #162
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014
RIP: 0010:read_profile+0x104/0x220
RSP: 0018:ffffc900006fbe80 EFLAGS: 00000202
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff888006150000 RSI: 0000000000000001 RDI: ffffffff82aba4a0
RBP: 000000000188bb60 R08: 0000000000000010 R09: ffff888006151000
R10: 0000000000000000 R11: 0000000000000000 R12: ffffffff82aba4a0
R13: 0000000000000000 R14: ffffc900006fbf08 R15: 0000000000020c30
FS: 000000000188a8c0(0000) GS:ffff88803ed00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000010 CR3: 0000000006144000 CR4: 00000000000006e0
Call Trace:
<TASK>
proc_reg_read+0x56/0x70
vfs_read+0x9a/0x1b0
ksys_read+0xa1/0xe0
? fpregs_assert_state_consistent+0x1e/0x40
do_syscall_64+0x3a/0x80
entry_SYSCALL_64_after_hwframe+0x46/0xb0
RIP: 0033:0x4d4b4e
RSP: 002b:00007ffebb668d58 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 000000000188a8a0 RCX: 00000000004d4b4e
RDX: 0000000000000400 RSI: 000000000188bb60 RDI: 0000000000000003
RBP: 0000000000000003 R08: 000000000000006e R09: 0000000000000000
R10: 0000000000000041 R11: 0000000000000246 R12: 000000000188bb60
R13: 0000000000000400 R14: 0000000000000000 R15: 000000000188bb60
</TASK>
Modules linked in:
CR2: 0000000000000010
Killed
---[ end trace 0000000000000000 ]---
Check prof_len in profile_init() to prevent it be zero.
Link: https://lkml.kernel.org/r/20220531012854.229439-1-chenzhongjin@huawei.com
Fixes: 1da177e4c3
("Linux-2.6.12-rc2")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Sasha Levin <sashal@kernel.org >
2022-08-25 11:15:20 +02:00
..
2022-08-25 11:14:55 +02:00
2022-07-21 21:09:26 +02:00
2018-06-15 07:15:28 +09:00
2021-03-04 09:39:31 +01:00
2022-07-02 16:27:40 +02:00
2022-07-29 17:10:31 +02:00
2020-09-17 13:45:31 +02:00
2022-06-25 11:49:01 +02:00
2019-10-07 18:57:10 +02:00
2021-11-26 11:36:04 +01:00
2022-08-25 11:15:00 +02:00
2022-04-15 14:14:45 +02:00
2021-09-26 13:39:46 +02:00
2022-08-25 11:15:02 +02:00
2022-06-25 11:49:10 +02:00
2022-07-21 21:09:25 +02:00
2019-05-31 06:46:05 -07:00
2022-02-23 11:58:38 +01:00
2018-05-18 14:58:22 +02:00
2019-12-13 08:51:11 +01:00
2020-10-01 13:14:33 +02:00
2022-02-08 18:23:13 +01:00
2020-06-22 09:05:13 +02:00
2020-06-22 09:05:13 +02:00
2019-12-01 09:17:17 +01:00
2018-11-13 11:08:47 -08:00
2020-01-23 08:21:29 +01:00
2020-06-22 09:04:58 +02:00
2020-06-22 09:05:28 +02:00
2022-06-25 11:49:07 +02:00
2018-08-22 10:52:47 -07:00
2020-01-09 10:19:00 +01:00
2018-05-16 07:23:35 +02:00
2018-05-16 07:23:35 +02:00
2021-01-30 13:32:11 +01:00
2020-11-24 13:27:23 +01:00
2021-09-22 11:48:09 +02:00
2018-08-06 12:35:20 +02:00
2021-07-11 12:49:30 +02:00
2019-04-20 09:16:02 +02:00
2018-05-15 23:08:33 -07:00
2019-05-31 06:46:19 -07:00
2021-03-04 09:39:30 +01:00
2020-07-16 08:17:26 +02:00
2018-08-02 08:06:54 +09:00
2019-02-12 19:47:20 +01:00
2021-02-03 23:23:23 +01:00
2022-07-02 16:27:39 +02:00
2018-07-16 12:31:57 -07:00
2020-04-17 10:48:52 +02:00
2021-12-08 08:50:12 +01:00
2021-07-11 12:49:31 +02:00
2021-02-10 09:21:06 +01:00
2020-01-29 16:43:27 +01:00
2018-07-02 11:36:17 +02:00
2018-07-02 11:36:17 +02:00
2022-02-23 11:58:38 +01:00
2020-03-25 08:06:13 +01:00
2021-08-08 08:54:30 +02:00
2019-12-01 09:17:10 +01:00
2021-09-22 11:48:09 +02:00
2019-01-13 09:51:06 +01:00
2022-08-25 11:15:20 +02:00
2022-06-14 16:59:14 +02:00
2020-11-18 19:18:52 +01:00
2020-08-26 10:30:59 +02:00
2019-09-16 08:22:20 +02:00
2018-07-10 22:18:52 +02:00
2022-02-16 12:51:47 +01:00
2022-07-21 21:09:32 +02:00
2022-04-20 09:12:50 +02:00
2021-02-07 14:48:38 +01:00
2018-08-03 15:52:10 +02:00
2018-08-13 11:25:07 -07:00
2018-06-10 10:17:09 -07:00
2021-09-26 13:39:47 +02:00
2022-03-11 10:15:11 +01:00
2020-01-09 10:18:59 +01:00
2018-06-21 12:33:05 +02:00
2018-06-25 11:30:10 -07:00
2021-07-20 16:15:42 +02:00
2022-02-23 11:58:39 +01:00
2020-10-14 10:31:21 +02:00
2021-05-22 10:59:39 +02:00
2018-11-13 11:09:00 -08:00
2018-08-22 10:52:47 -07:00
2018-08-11 02:05:53 -05:00
2018-08-30 12:56:40 +02:00
2020-02-24 08:34:49 +01:00
2018-05-18 08:47:13 -07:00
2021-11-26 11:36:06 +01:00