Qiang Zhang
89f9a1e876
bootconfig: use memblock_free_late to free xbc memory to buddy
On the time to free xbc memory in xbc_exit(), memblock may has handed
over memory to buddy allocator. So it doesn't make sense to free memory
back to memblock. memblock_free() called by xbc_exit() even causes UAF bugs
on architectures with CONFIG_ARCH_KEEP_MEMBLOCK disabled like x86.
Following KASAN logs shows this case.
This patch fixes the xbc memory free problem by calling memblock_free()
in early xbc init error rewind path and calling memblock_free_late() in
xbc exit path to free memory to buddy allocator.
[ 9.410890] ==================================================================
[ 9.418962] BUG: KASAN: use-after-free in memblock_isolate_range+0x12d/0x260
[ 9.426850] Read of size 8 at addr ffff88845dd30000 by task swapper/0/1
[ 9.435901] CPU: 9 PID: 1 Comm: swapper/0 Tainted: G U 6.9.0-rc3-00208-g586b5dfb51b9 #5
[ 9.446403] Hardware name: Intel Corporation RPLP LP5 (CPU:RaptorLake)/RPLP LP5 (ID:13), BIOS IRPPN02.01.01.00.00.19.015.D-00000000 Dec 28 2023
[ 9.460789] Call Trace:
[ 9.463518] <TASK>
[ 9.465859] dump_stack_lvl+0x53/0x70
[ 9.469949] print_report+0xce/0x610
[ 9.473944] ? __virt_addr_valid+0xf5/0x1b0
[ 9.478619] ? memblock_isolate_range+0x12d/0x260
[ 9.483877] kasan_report+0xc6/0x100
[ 9.487870] ? memblock_isolate_range+0x12d/0x260
[ 9.493125] memblock_isolate_range+0x12d/0x260
[ 9.498187] memblock_phys_free+0xb4/0x160
[ 9.502762] ? __pfx_memblock_phys_free+0x10/0x10
[ 9.508021] ? mutex_unlock+0x7e/0xd0
[ 9.512111] ? __pfx_mutex_unlock+0x10/0x10
[ 9.516786] ? kernel_init_freeable+0x2d4/0x430
[ 9.521850] ? __pfx_kernel_init+0x10/0x10
[ 9.526426] xbc_exit+0x17/0x70
[ 9.529935] kernel_init+0x38/0x1e0
[ 9.533829] ? _raw_spin_unlock_irq+0xd/0x30
[ 9.538601] ret_from_fork+0x2c/0x50
[ 9.542596] ? __pfx_kernel_init+0x10/0x10
[ 9.547170] ret_from_fork_asm+0x1a/0x30
[ 9.551552] </TASK>
[ 9.555649] The buggy address belongs to the physical page:
[ 9.561875] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x45dd30
[ 9.570821] flags: 0x200000000000000(node=0|zone=2)
[ 9.576271] page_type: 0xffffffff()
[ 9.580167] raw: 0200000000000000 ffffea0011774c48 ffffea0012ba1848 0000000000000000
[ 9.588823] raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000
[ 9.597476] page dumped because: kasan: bad access detected
[ 9.605362] Memory state around the buggy address:
[ 9.610714] ffff88845dd2ff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9.618786] ffff88845dd2ff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 9.626857] >ffff88845dd30000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 9.634930] ^
[ 9.638534] ffff88845dd30080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 9.646605] ffff88845dd30100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[ 9.654675] ==================================================================
Link: https://lore.kernel.org/all/20240414114944.1012359-1-qiang4.zhang@linux.intel.com/
Fixes: 40caa127f3 ("init: bootconfig: Remove all bootconfig data when the init memory is removed")
Cc: Stable@vger.kernel.org
Signed-off-by: Qiang Zhang <qiang4.zhang@intel.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
2024-04-14 22:00:43 +09:00
..
2020-08-10 01:32:59 +09:00
2023-12-22 12:30:19 +08:00
2023-05-09 11:06:45 +02:00
2024-03-22 10:09:08 -07:00
2024-02-27 15:25:50 -07:00
2022-07-17 17:31:39 -07:00
2022-07-29 18:12:34 -07:00
2024-03-12 13:09:22 -07:00
2023-04-13 13:13:53 -07:00
2024-03-14 18:03:09 -07:00
2022-11-18 02:15:15 +01:00
2024-01-19 11:59:11 -08:00
2023-03-21 21:15:34 +01:00
2023-09-11 08:13:17 +00:00
2023-02-27 17:00:14 -08:00
2023-02-02 22:50:10 -08:00
2023-02-02 22:50:09 -08:00
2023-11-14 17:12:52 -08:00
2022-04-26 17:58:51 -04:00
2023-09-19 13:21:33 -07:00
2020-11-18 14:15:17 -06:00
2022-01-20 08:52:55 +02:00
2024-03-12 13:09:23 -07:00
2021-12-13 10:56:09 +01:00
2021-10-01 16:52:48 -04:00
2022-08-02 17:14:47 -06:00
2023-08-18 10:18:58 -07:00
2020-10-16 13:25:14 -06:00
2023-10-14 20:25:22 -07:00
2024-02-01 13:06:40 +01:00
2022-04-26 17:58:51 -04:00
2024-04-14 22:00:43 +09:00
2020-06-11 15:14:53 +02:00
2023-04-13 13:13:54 -07:00
2023-01-31 15:01:45 +01:00
2024-03-14 18:03:09 -07:00
2022-09-01 16:55:35 +02:00
2024-02-29 09:16:02 -08:00
2020-08-20 15:45:14 -04:00
2023-11-24 00:29:58 -05:00
2023-08-25 13:22:10 -07:00
2024-02-27 15:25:56 -07:00
2022-09-11 21:55:06 -07:00
2021-10-01 16:52:48 -04:00
2023-06-07 21:25:00 -07:00
2023-03-05 14:30:34 -08:00
2023-11-03 07:08:36 -10:00
2021-01-21 14:06:00 -07:00
2021-05-06 19:24:12 -07:00
2022-01-31 11:21:43 +11:00
2022-01-31 11:21:43 +11:00
2022-03-07 12:48:35 -07:00
2022-03-07 12:48:35 -07:00
2023-12-29 12:22:26 -08:00
2022-06-07 10:27:38 +02:00
2020-06-18 17:26:43 +10:00
2021-08-19 09:02:55 +09:00
2021-06-22 13:56:43 +02:00
2023-11-22 10:41:46 +01:00
2023-01-31 20:37:18 +01:00
2021-07-01 11:06:05 -07:00
2023-06-09 17:44:17 -07:00
2021-07-01 11:06:06 -07:00
2021-05-06 19:24:12 -07:00
2021-07-01 11:06:06 -07:00
2023-09-11 08:13:17 +00:00
2023-06-09 17:44:17 -07:00
2020-07-31 11:49:08 +02:00
2023-06-09 17:44:15 -07:00
2024-02-12 10:36:17 -06:00
2024-02-22 15:38:52 -08:00
2023-02-02 22:50:01 -08:00
2024-02-22 15:38:52 -08:00
2023-02-02 22:50:01 -08:00
2020-11-20 14:45:33 +11:00
2024-02-07 17:23:19 +01:00
2024-03-06 13:07:39 -08:00
2024-03-08 10:23:26 +00:00
2022-09-11 21:55:10 -07:00
2023-11-25 09:43:18 +01:00
2023-08-18 10:18:55 -07:00
2020-12-15 22:46:15 -08:00
2021-01-03 20:05:18 -05:00
2020-10-16 11:11:22 -07:00
2023-04-13 07:38:54 -06:00
2022-11-18 02:15:15 +01:00
2023-03-19 10:02:04 -07:00
2024-02-22 15:38:52 -08:00
2024-02-29 13:38:02 -08:00
2024-03-13 00:03:21 -07:00
2022-03-07 12:48:35 -07:00
2023-08-30 17:04:28 -07:00
2024-03-13 21:22:26 -04:00
2022-04-29 14:38:01 -07:00
2023-12-06 16:12:46 -08:00
2023-02-08 14:28:17 -07:00
2022-04-27 10:57:33 -07:00
2023-12-21 10:02:28 -08:00
2022-11-29 16:34:15 -04:00
2022-10-03 14:03:21 -07:00
2024-03-11 09:38:17 -07:00
2022-04-13 21:32:21 +02:00
2022-11-19 00:56:15 +01:00
2021-08-19 09:02:55 +09:00
2024-02-12 10:35:40 -06:00
2024-03-23 08:43:21 -07:00
2024-02-22 15:38:51 -08:00
2023-02-25 13:02:20 -08:00
2023-12-05 11:14:40 +01:00
2024-01-27 19:03:51 -08:00
2023-12-05 11:14:40 +01:00
2024-03-18 11:24:14 -07:00
2021-07-08 11:48:20 -07:00
2024-02-17 16:20:41 +01:00
2024-02-08 16:39:25 +00:00
2023-08-21 13:46:25 -07:00
2021-05-19 15:05:11 +02:00
2023-09-09 15:11:49 -07:00
2023-04-17 18:01:23 +02:00
2021-08-13 18:37:38 +02:00
2023-08-15 14:57:25 -07:00
2021-07-08 11:48:20 -07:00
2023-03-31 09:21:35 -06:00
2023-10-16 12:44:06 -04:00
2023-07-26 12:29:13 +02:00
2023-01-13 14:35:38 -06:00
2022-03-11 10:42:56 +01:00
2023-08-24 16:20:18 -07:00
2022-11-22 19:38:39 -07:00
2023-10-16 12:44:06 -04:00
2024-03-14 10:58:27 -07:00
2024-03-14 17:43:30 -07:00
2024-03-18 11:24:15 -07:00
2020-09-26 10:33:57 -07:00
2023-06-06 13:18:32 +02:00
2024-02-22 19:01:55 -08:00
2023-08-18 10:19:00 -07:00
2023-08-18 10:18:55 -07:00
2021-12-24 14:54:29 -08:00
2023-12-01 14:53:55 +09:00
2022-11-18 13:55:06 -08:00
2022-10-03 17:34:32 -07:00
2024-03-22 16:25:31 -07:00
2023-03-09 23:08:04 -08:00
2021-04-16 16:10:37 -07:00
2023-03-02 21:54:22 -08:00
2023-10-18 14:34:14 -07:00
2022-11-30 13:16:40 -08:00
2022-05-22 11:32:30 -07:00
2023-08-21 13:07:22 -07:00
2023-06-12 11:31:50 -07:00
2022-10-11 17:42:58 -06:00
2022-08-24 13:46:57 +01:00
2023-04-18 16:39:33 -07:00
2023-10-10 10:14:27 +02:00
2023-06-05 15:28:42 -07:00
2021-07-08 11:48:20 -07:00
2022-12-09 10:42:56 +00:00
2024-01-15 07:23:50 -07:00
2023-09-19 13:21:33 -07:00
2024-02-15 12:17:28 -05:00
2022-09-23 16:46:19 +02:00
2022-11-01 10:04:52 -07:00
2022-06-03 10:34:34 -07:00
2022-12-12 16:42:57 -08:00
2022-07-17 17:31:41 -07:00
2024-02-22 15:38:52 -08:00
2024-04-05 11:21:31 -07:00
2024-03-14 18:03:09 -07:00
2023-05-16 14:08:02 -07:00
2024-03-05 01:55:28 -08:00
2024-02-29 22:34:42 -08:00
2024-03-05 01:55:28 -08:00
2024-02-20 20:47:32 -08:00
2022-04-19 21:58:47 +02:00
2022-04-19 21:58:47 +02:00
2022-11-01 10:04:52 -07:00
2021-06-18 11:43:09 +02:00
2024-03-11 09:36:11 +00:00
2021-07-08 11:48:20 -07:00
2020-08-12 10:58:00 -07:00
2024-02-05 12:30:54 +00:00
2023-12-09 21:27:54 -08:00
2022-09-07 17:04:49 +02:00
2023-11-24 18:09:19 -08:00
2023-06-06 21:39:55 +09:00
2021-01-18 11:03:26 +01:00
2022-07-17 17:14:36 -07:00
2022-01-20 08:52:54 +02:00
2022-11-18 02:18:02 +01:00
2022-10-12 18:51:50 -07:00
2023-08-18 10:18:50 -07:00
2024-01-09 11:46:20 -08:00
2024-02-02 10:21:26 -08:00
2023-02-21 08:52:42 +09:00
2022-11-16 13:32:32 +00:00
2022-11-18 02:15:15 +01:00
2022-02-25 09:36:06 +01:00
2024-02-21 09:34:26 +01:00
2024-01-08 15:27:15 -08:00
2022-10-11 17:42:58 -06:00
2022-10-11 17:42:58 -06:00
2023-11-10 19:59:04 +09:00
2023-08-21 13:46:24 -07:00
2023-06-05 15:28:42 -07:00
2023-12-27 11:50:20 -05:00
2023-08-16 11:47:29 +02:00
2021-09-08 11:50:26 -07:00
2023-12-28 04:57:57 -08:00
2024-02-20 20:44:49 -08:00
2024-03-04 17:01:22 -08:00
2024-02-22 10:24:48 -08:00
2021-02-17 14:08:01 +01:00
2023-12-29 12:22:29 -08:00
2023-07-27 13:45:51 +02:00
2020-11-18 14:15:17 -06:00
2020-04-07 10:43:43 -07:00
2024-02-20 20:44:49 -08:00
2024-02-20 20:44:49 -08:00
2023-09-13 10:18:42 -07:00
2023-02-21 14:45:22 -08:00
2022-10-11 17:42:58 -06:00
2023-12-06 11:06:59 +01:00
2023-01-11 16:14:21 -08:00
2023-09-05 19:01:38 -04:00
2020-08-12 10:58:00 -07:00