Mostafa Saleh
aa0cf04b69
ubsan: Fix panic from test_ubsan_out_of_bounds
...
[ Upstream commit 9b044614be12d78d3a93767708b8d02fb7dfa9b0 ]
Running lib_ubsan.ko on arm64 (without CONFIG_UBSAN_TRAP) panics the
kernel:
[ 31.616546] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: test_ubsan_out_of_bounds+0x158/0x158 [test_ubsan]
[ 31.646817] CPU: 3 UID: 0 PID: 179 Comm: insmod Not tainted 6.15.0-rc2 #1 PREEMPT
[ 31.648153] Hardware name: linux,dummy-virt (DT)
[ 31.648970] Call trace:
[ 31.649345] show_stack+0x18/0x24 (C)
[ 31.650960] dump_stack_lvl+0x40/0x84
[ 31.651559] dump_stack+0x18/0x24
[ 31.652264] panic+0x138/0x3b4
[ 31.652812] __ktime_get_real_seconds+0x0/0x10
[ 31.653540] test_ubsan_load_invalid_value+0x0/0xa8 [test_ubsan]
[ 31.654388] init_module+0x24/0xff4 [test_ubsan]
[ 31.655077] do_one_initcall+0xd4/0x280
[ 31.655680] do_init_module+0x58/0x2b4
That happens because the test corrupts other data in the stack:
400: d5384108 mrs x8, sp_el0
404: f9426d08 ldr x8, [x8, #1240 ]
408: f85f83a9 ldur x9, [x29, #-8]
40c: eb09011f cmp x8, x9
410: 54000301 b.ne 470 <test_ubsan_out_of_bounds+0x154> // b.any
As there is no guarantee the compiler will order the local variables
as declared in the module:
volatile char above[4] = { }; /* Protect surrounding memory. */
volatile int arr[4];
volatile char below[4] = { }; /* Protect surrounding memory. */
There is another problem where the out-of-bound index is 5 which is larger
than the extra surrounding memory for protection.
So, use a struct to enforce the ordering, and fix the index to be 4.
Also, remove some of the volatiles and rely on OPTIMIZER_HIDE_VAR()
Signed-off-by: Mostafa Saleh <smostafa@google.com >
Link: https://lore.kernel.org/r/20250415203354.4109415-1-smostafa@google.com
Signed-off-by: Kees Cook <kees@kernel.org >
Signed-off-by: Sasha Levin <sashal@kernel.org >
2025-05-02 07:51:02 +02:00
..
2025-04-10 14:37:30 +02:00
2024-01-31 16:18:49 -08:00
2023-05-09 11:06:45 +02:00
2022-11-18 13:55:09 -08:00
2024-07-11 12:49:08 +02:00
2022-06-15 10:29:10 +02:00
2022-07-17 17:31:39 -07:00
2022-07-29 18:12:34 -07:00
2024-08-29 17:33:14 +02:00
2023-04-13 13:13:53 -07:00
2023-09-06 22:53:55 +08:00
2022-11-18 02:15:15 +01:00
2022-02-13 16:50:06 -08:00
2023-03-21 21:15:34 +01:00
2024-10-04 16:29:19 +02: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
2025-04-25 10:45:11 +02:00
2022-04-26 17:58:51 -04:00
2023-09-19 13:21:33 -07:00
2019-05-24 17:39:02 +02:00
2019-05-24 17:39:02 +02:00
2020-11-18 14:15:17 -06:00
2022-06-01 18:29:06 -07:00
2019-05-30 11:26:32 -07:00
2021-10-01 16:52:48 -04:00
2022-08-02 17:14:47 -06:00
2017-11-02 11:10:55 +01:00
2023-08-18 10:18:58 -07:00
2023-06-22 13:57:41 -07:00
2022-04-26 17:58:51 -04:00
2024-10-17 15:24:12 +02:00
2023-04-13 13:13:54 -07:00
2023-01-31 15:01:45 +01:00
2024-10-17 15:24:13 +02:00
2025-03-22 12:50:48 -07:00
2022-09-01 16:55:35 +02:00
2023-08-25 10:14:34 +01:00
2020-08-20 15:45:14 -04:00
2023-08-25 13:22:10 -07:00
2017-11-02 11:10:55 +01:00
2024-03-26 18:19:18 -04:00
2022-09-11 21:55:06 -07:00
2019-05-24 17:39:02 +02:00
2023-06-07 21:25:00 -07:00
2023-03-05 14:30:34 -08:00
2024-08-29 17:33:24 +02:00
2019-06-19 17:09:06 +02:00
2019-06-19 17:09:06 +02: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
2022-06-07 10:27:38 +02:00
2017-11-02 11:10:55 +01:00
2021-06-22 13:56:43 +02:00
2024-10-04 16:29:53 +02:00
2023-01-31 20:37:18 +01:00
2024-08-03 08:54:24 +02:00
2023-06-09 17:44:17 -07:00
2023-06-09 17:44:17 -07:00
2023-06-09 17:44:17 -07:00
2023-06-09 17:44:15 -07:00
2023-06-23 17:04:04 -07:00
2023-07-08 09:29:32 -07:00
2023-02-02 22:50:01 -08:00
2023-03-23 17:18:35 -07:00
2023-02-02 22:50:01 -08:00
2020-11-20 14:45:33 +11:00
2022-04-22 21:30:57 +02:00
2024-05-17 12:02:33 +02:00
2020-10-16 11:11:20 -07:00
2022-09-11 21:55:10 -07:00
2023-12-08 08:52:20 +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
2023-04-13 07:38:54 -06:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2012-07-23 13:54:52 +01:00
2022-11-18 02:15:15 +01:00
2023-03-19 10:02:04 -07:00
2022-09-19 14:35:08 +02:00
2024-06-12 11:11:34 +02:00
2022-03-07 12:48:35 -07:00
2023-08-30 17:04:28 -07:00
2024-09-12 11:11:39 +02:00
2022-04-29 14:38:01 -07:00
2017-02-24 17:46:57 -08:00
2023-12-13 18:45:22 +01:00
2023-02-08 14:28:17 -07:00
2022-04-27 10:57:33 -07:00
2019-05-13 11:07:33 +02:00
2024-01-20 11:51:46 +01:00
2017-11-02 11:10:55 +01:00
2022-11-29 16:34:15 -04:00
2022-10-03 14:03:21 -07:00
2025-02-27 04:10:52 -08:00
2022-04-13 21:32:21 +02:00
2022-11-19 00:56:15 +01:00
2024-07-25 09:50:47 +02:00
2025-02-17 09:40:03 +01:00
2023-03-02 21:54:22 -08:00
2023-02-25 13:02:20 -08:00
2022-03-22 15:57:11 -07:00
2022-10-11 12:01:24 +02:00
2022-11-08 15:57:24 -08:00
2024-11-08 16:28:26 +01:00
2024-08-03 08:54:24 +02:00
2024-02-23 09:24:58 +01: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
2023-03-31 09:21:35 -06:00
2022-11-18 13:55:06 -08:00
2017-11-02 11:10:55 +01: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-09-09 15:11:49 -07:00
2025-02-17 09:40:39 +01:00
2018-10-16 13:45:44 +02:00
2024-03-26 18:19:18 -04:00
2020-09-26 10:33:57 -07:00
2017-11-02 11:10:55 +01:00
2023-06-06 13:18:32 +02:00
2024-03-06 14:48:34 +00:00
2023-08-18 10:19:00 -07:00
2023-08-18 10:18:55 -07:00
2017-11-02 11:10:55 +01:00
2024-08-03 08:53:38 +02:00
2022-11-18 13:55:06 -08:00
2022-10-03 17:34:32 -07:00
2025-04-10 14:37:42 +02:00
2023-03-09 23:08:04 -08:00
2023-03-02 21:54:22 -08:00
2024-04-03 15:28:17 +02:00
2023-08-25 08:06:53 -07:00
2019-05-21 10:50:45 +02: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
2025-03-07 16:45:47 +01: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-10-04 16:29:38 +02:00
2024-05-17 12:02:02 +02:00
2025-01-09 13:31:55 +01:00
2022-09-23 16:46:19 +02:00
2025-04-25 10:45:29 +02:00
2022-11-01 10:04:52 -07:00
2022-06-03 10:34:34 -07:00
2024-06-12 11:11:31 +02:00
2022-07-17 17:31:41 -07:00
2022-03-17 20:17:18 -07:00
2024-05-02 16:32:46 +02:00
2024-12-14 19:59:57 +01:00
2019-05-30 11:26:32 -07:00
2023-05-16 14:08:02 -07:00
2024-12-09 10:32:53 +01:00
2025-04-25 10:45:50 +02: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
2023-07-18 13:25:37 -07:00
2021-07-08 11:48:20 -07:00
2020-08-12 10:58:00 -07:00
2024-03-26 18:19:26 -04:00
2023-08-18 17:08:42 +02:00
2022-09-07 17:04:49 +02:00
2023-06-15 13:42:18 +02: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
2024-06-12 11:12:08 +02:00
2024-01-20 11:51:46 +01:00
2023-01-25 14:07:21 -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
2023-10-18 12:12:41 -07:00
2024-05-02 16:32:41 +02:00
2022-10-11 17:42:58 -06:00
2019-05-21 10:50:45 +02:00
2022-10-11 17:42:58 -06:00
2023-08-21 13:46:24 -07:00
2023-06-05 15:28:42 -07:00
2022-12-13 15:47:48 -08:00
2023-08-16 11:47:29 +02:00
2019-06-05 17:36:37 +02:00
2022-04-29 14:38:00 -07:00
2023-06-18 02:32:54 -07:00
2025-05-02 07:51:02 +02:00
2019-10-16 14:56:21 +02:00
2017-07-21 09:38:30 +02:00
2023-06-12 11:31:51 -07:00
2024-10-04 16:30:02 +02:00
2015-09-10 13:29:01 -07:00
2023-04-08 13:45:39 -07:00
2019-10-03 12:12:23 -04:00
2022-11-21 22:02:10 +01:00
2023-07-27 13:45:51 +02:00
2023-05-30 16:42:01 -07:00
2023-05-30 16:42:01 -07:00
2023-02-21 14:45:22 -08:00
2022-10-11 17:42:58 -06:00
2024-01-01 12:42:46 +00:00
2023-01-11 16:14:21 -08:00
2024-10-04 16:30:02 +02:00
2020-08-12 10:58:00 -07:00