From 30c3ef9f6feff054e6bc2734d448de34b284fa9b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 31 Jul 2023 23:40:59 +0200 Subject: [PATCH] linux: handle UNAME26 personality (#4109) --- src/unix/linux.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/unix/linux.c b/src/unix/linux.c index 65fb847f65b..eac18e86b04 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -328,6 +328,31 @@ unsigned uv__kernel_version(void) { if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch)) return 0; + /* Handle it when the process runs under the UNAME26 personality: + * + * - kernels >= 3.x identify as 2.6.40+x + * - kernels >= 4.x identify as 2.6.60+x + * + * UNAME26 is a poorly conceived hack that doesn't let us distinguish + * between 4.x kernels and 5.x/6.x kernels so we conservatively assume + * that 2.6.60+x means 4.x. + * + * Fun fact of the day: it's technically possible to observe the actual + * kernel version for a brief moment because uname() first copies out the + * real release string before overwriting it with the backcompat string. + */ + if (major == 2 && minor == 6) { + if (patch >= 60) { + major = 4; + minor = patch - 60; + patch = 0; + } else if (patch >= 40) { + major = 3; + minor = patch - 40; + patch = 0; + } + } + version = major * 65536 + minor * 256 + patch; atomic_store_explicit(&cached_version, version, memory_order_relaxed);