| 1 | From 341f676066ab807d433f0f0b6c8356d2ad0e1cc9 Mon Sep 17 00:00:00 2001
|
| 2 | From: David Holmes <[email protected]>
|
| 3 | Date: Tue, 8 Jun 2021 04:53:02 +0000
|
| 4 | Subject: [PATCH] 8267908: linux: thread_native_entry can scribble on stack
|
| 5 | frame
|
| 6 |
|
| 7 | Reviewed-by: ysuenaga
|
| 8 | ---
|
| 9 | src/hotspot/os/linux/os_linux.cpp | 3 ++-
|
| 10 | 1 file changed, 2 insertions(+), 1 deletion(-)
|
| 11 |
|
| 12 | |
| 13 | |
| 14 | @@ -787,7 +787,8 @@ static void *thread_native_entry(Thread *thread) {
|
| 15 | // and we did not see any degradation in performance without `alloca()`.
|
| 16 | static int counter = 0;
|
| 17 | int pid = os::current_process_id();
|
| 18 | - void *stackmem = alloca(((pid ^ counter++) & 7) * 128);
|
| 19 | + int random = ((pid ^ counter++) & 7) * 128;
|
| 20 | + void *stackmem = alloca(random != 0 ? random : 1); // ensure we allocate > 0
|
| 21 | // Ensure the alloca result is used in a way that prevents the compiler from eliding it.
|
| 22 | *(char *)stackmem = 1;
|
| 23 | #endif
|