From owner-freebsd-hackers@freebsd.org Tue Mar 30 09:35:06 2021 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 31AC05C0A4F for ; Tue, 30 Mar 2021 09:35:06 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4F8knP6JtMz4V2h for ; Tue, 30 Mar 2021 09:35:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id D6A285C0AC4; Tue, 30 Mar 2021 09:35:05 +0000 (UTC) Delivered-To: hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D54C85C0E1F for ; Tue, 30 Mar 2021 09:35:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4F8knP3llcz4V4w; Tue, 30 Mar 2021 09:35:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 12U9YtXP007755 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 30 Mar 2021 12:34:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 12U9YtXP007755 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 12U9YtJ6007754; Tue, 30 Mar 2021 12:34:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 30 Mar 2021 12:34:55 +0300 From: Konstantin Belousov To: Alan Somers Cc: "freebsd-hackers@freebsd.org" Subject: Re: How does the stack's guard page work on amd64? Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4F8knP3llcz4V4w X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Technical discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Mar 2021 09:35:06 -0000 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"