Chen Zhongjin
55404cf492
profiling: fix shift too large makes kernel panic
...
[ Upstream commit 0fe6ee8f123a4dfb529a5aff07536bb481f34043 ]
2d186afd04d6 ("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: 1da177e4c3f4 ("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-17 15:15:46 +02:00
..
2022-08-17 15:14:51 +02:00
2022-06-16 09:37:02 -10:00
2022-07-27 18:09:11 +02:00
2022-05-26 17:13:43 -07:00
2022-06-23 15:26:59 +02:00
2022-06-08 09:16:31 -07:00
2022-07-13 11:29:12 +02:00
2022-05-25 16:18:27 -07:00
2021-12-02 17:25:21 +09:00
2022-08-17 15:14:19 +02:00
2022-05-25 11:32:53 -07:00
2022-06-02 08:55:01 -07:00
2022-08-17 15:14:10 +02:00
2022-07-11 10:19:09 -07:00
2022-08-17 15:14:06 +02:00
2022-07-15 10:52:11 +02:00
2022-08-17 15:14:33 +02:00
2022-08-17 15:14:20 +02:00
2022-08-17 15:14:59 +02:00
2022-08-17 15:14:17 +02:00
2022-04-06 13:43:44 -07:00
2022-02-03 11:20:34 -08:00
2022-04-25 14:37:18 +02:00
2022-04-25 14:37:28 +02:00
2022-04-25 14:37:12 +02:00
2022-01-25 13:22:51 -05:00
2022-02-22 13:51:40 -05:00
2022-01-11 13:08:21 -08:00
2022-06-15 19:28:44 -04:00
2022-03-09 10:32:06 -08:00
2022-06-13 09:18:46 -07:00
2022-05-23 17:51:12 -07:00
2022-05-27 11:22:03 -07:00
2022-03-15 10:32:44 +01:00
2022-06-01 15:55:25 -07:00
2022-07-11 09:52:59 -07:00
2022-02-16 23:25:12 +11:00
2022-06-03 16:03:05 -07:00
2022-05-08 03:16:59 +09:00
2022-06-23 19:11:28 +02:00
2022-04-15 14:49:55 -07:00
2022-05-10 14:42:06 -07:00
2022-03-31 10:36:55 +02:00
2022-05-25 13:05:42 -07:00
2022-05-27 11:22:03 -07:00
2022-07-13 10:13:41 -04:00
2022-05-29 10:31:36 -07:00
2022-03-23 19:00:33 -07:00
2022-06-16 19:11:30 -07:00
2022-04-21 11:40:59 -07:00
2022-06-06 08:06:00 +02:00
2022-05-19 19:30:30 +02:00
2022-01-31 11:21:46 +11:00
2022-06-23 19:11:28 +02:00
2021-12-28 11:26:18 +01:00
2022-04-29 14:38:00 -07:00
2022-06-06 08:06:00 +02:00
2022-08-17 15:15:46 +02:00
2022-07-09 11:06:19 -07:00
2022-06-23 19:11:28 +02:00
2022-05-12 20:38:37 -07:00
2022-03-23 19:00:35 -07:00
2022-02-02 13:11:34 +01:00
2022-04-11 17:07:29 -07:00
2022-03-24 19:06:48 -07:00
2022-05-03 14:11:58 -07:00
2022-07-07 09:53:43 -07:00
2022-05-24 11:11:13 -07:00
2022-04-12 14:13:01 +02:00
2022-05-01 10:03:43 +02:00
2022-05-08 01:33:09 -07:00
2022-02-25 09:36:06 +01:00
2022-04-05 09:59:38 +02:00
2022-04-05 09:59:38 +02:00
2022-05-24 11:11:13 -07:00
2022-01-15 16:30:30 +02:00
2022-04-22 18:50:54 +01:00
2022-07-15 09:52:35 -07:00
2022-04-30 08:39:32 -06:00
2022-04-29 14:38:03 -07:00
2022-02-01 17:24:39 -08:00
2022-04-29 14:38:03 -07:00
2022-02-17 09:11:57 -06:00
2022-05-06 14:49:44 -05:00
2022-02-25 10:40:14 -06:00
2022-05-19 23:25:47 -04:00
2022-07-28 10:06:49 -07:00
2022-06-23 18:41:40 +02:00
2022-06-23 19:11:28 +02:00
2022-07-29 07:49:02 -10:00