From e93b6a7b01953a2036ed3713539f04b45b5396e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 16 May 2025 20:52:32 +0200 Subject: [PATCH] Fix `MaybeReenterWithoutASLR()` in docker In some docker configurations the `personality()` function may return inconsistent results. Double check if the persona has been updated before reentering, otherwise we risk infinite loop. Fixes https://github.com/google/benchmark/issues/1984. --- src/benchmark.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/benchmark.cc b/src/benchmark.cc index 9a98f889db..8672c8a94f 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -845,6 +845,13 @@ void MaybeReenterWithoutASLR(int /*argc*/, char** argv) { // Have we failed to change the personality? That may happen. if (prev_personality == -1) return; + // Make sure the parsona has been updated with the no-ASLR flag, + // otherwise we will try to reenter infinitely. + // This seems impossible, but can happen in some docker configurations. + const auto new_personality = personality(0xffffffff); + if ((internal::get_as_unsigned(new_personality) & ADDR_NO_RANDOMIZE) == 0) + return; + execv(argv[0], argv); // The exec() functions return only if an error has occurred, // in which case we want to just continue as-is.