From a4ee0edc4a0b3f880463021c7ae1bdcf7112f3d6 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 18 Oct 2022 18:11:26 -0400 Subject: [PATCH] libc: Make elf_aux_info() return an error if AT_USRSTACK* is undefined Otherwise we do not fall back to sysctls if the auxv entries are not defined by the kernel. Arguably this is not a bug since we do not support newer libc running on an older kernel, but we can be a bit more gentle for the benefit of Valgrind or any other software which synthesizes the auxv for virtualization purposes. Reported by: Paul Floyd MFC after: 1 week Reviewed by: brooks, kib Differential Revision: https://reviews.freebsd.org/D37036 --- lib/libc/gen/auxv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/auxv.c b/lib/libc/gen/auxv.c index af59a2dda90a..2f043f8814cf 100644 --- a/lib/libc/gen/auxv.c +++ b/lib/libc/gen/auxv.c @@ -381,15 +381,21 @@ _elf_aux_info(int aux, void *buf, int buflen) break; case AT_USRSTACKBASE: if (buflen == sizeof(u_long)) { - *(u_long *)buf = usrstackbase; - res = 0; + if (usrstackbase != 0) { + *(u_long *)buf = usrstackbase; + res = 0; + } else + res = ENOENT; } else res = EINVAL; break; case AT_USRSTACKLIM: if (buflen == sizeof(u_long)) { - *(u_long *)buf = usrstacklim; - res = 0; + if (usrstacklim != 0) { + *(u_long *)buf = usrstacklim; + res = 0; + } else + res = ENOENT; } else res = EINVAL; break;