Date: Tue, 18 Oct 2022 11:36:07 -0400 From: Mark Johnston <markj@freebsd.org> To: Paul Floyd <paulf2718@gmail.com> Cc: freebsd-hackers <freebsd-hackers@freebsd.org> Subject: Re: AMD64 14.0-CURRENT memory layout changes Message-ID: <Y07H5/q0YoPnH3Y2@nuc> In-Reply-To: <259246b0-9592-3aa8-2a1a-52609ac5357c@gmail.com> References: <bcfa260b-7a94-1414-a5ae-c281e96c76ec@gmail.com> <Y0wiCAlHIHe9rFQ7@nuc> <578a011d-0c3f-3f91-48ca-17999a6515a9@gmail.com> <259246b0-9592-3aa8-2a1a-52609ac5357c@gmail.com>
index | next in thread | previous in thread | raw e-mail
On Tue, Oct 18, 2022 at 02:13:46PM +0200, Paul Floyd wrote:
>
> >
> > How is 14.0 working out what address to use for the stack?
> > (The above is with ASLR all off)
>
>
> Answering my own question:
>
> it's in auxv (from __thr_get_main_stack_base)
>
>
> /usr/include/sys/elf_common.h:#define AT_USRSTACKBASE 35 /* Top
> of user stack */
>
> I haven't yet added this (or AT_USRSTACKLIM) to the client auxv that
> Valgrind synthesizes.
>
>
> I'm still not certain that will fix it - I would have expected
> __thr_get_main_stack_base to fallback to using sysctl.
I think this is a compatibility bug in elf_aux_info(). The values of
AT_USRSTACKBASE and AT_USRSTACKLIM can never legitimately be zero, I
think, so we can use that to test.
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;
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Y07H5/q0YoPnH3Y2>
