Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 2021 12:34:55 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Alan Somers <asomers@freebsd.org>
Cc:        "freebsd-hackers@freebsd.org" <hackers@freebsd.org>
Subject:   Re: How does the stack's guard page work on amd64?
Message-ID:  <YGLwv%2BKkmhxeeJUp@kib.kiev.ua>
In-Reply-To: <CAOtMX2i5d0c9E=W=S6aKp1j5JczaaTqKDX8kW=2NqF=i35dWog@mail.gmail.com>
References:  <CAOtMX2i5d0c9E=W=S6aKp1j5JczaaTqKDX8kW=2NqF=i35dWog@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 29, 2021 at 11:06:36PM -0600, Alan Somers wrote:
> Rust tries to detect stack overflow and handles it differently than other
> segfaults, but it's currently broken on FreeBSD/amd64.  I've got a patch
> that fixes the problem, but I would like someone to confirm my reasoning.
> 
> It seems like FreeBSD's main thread stacks include a guard page at the
> bottom.  However, when Rust tries to create its own guard page (by
> re-mmap()ping and mprotect()ing it), it seems like FreeBSD's guard page
> automatically moves up into the un-remapped region.  At least, that's how
> it behaves, based on the addresses that segfault.  Is that correct?
Show the facts. For instance, procstat -v (and a note which
mapping was established by runtime for the 'guard') would tell the whole
story.

My guess would be that procctl(PROC_STACKGAP_CTL, &PROC_STACKGAP_DISABLE)
would be enough.  Cannot tell without specific data.

> 
> For other threads, Rust doesn't try to remap the guard page, it just relies
> on the guard page created by libthr in _thr_stack_alloc.
> 
> Finally, what changed in between FreeBSD 10.3 and 11.4?  Rust's stack
> overflow detection worked in 10.3.
> 
> -Alan
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YGLwv%2BKkmhxeeJUp>