From nobody Mon Jan 17 21:13:02 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2C9411976861; Mon, 17 Jan 2022 21:13:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jd4PW0nn8z3Fbj; Mon, 17 Jan 2022 21:13:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642453983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CnQCVPws6eiLxZBqvMT8IB8K2SU4EWR5fQaUyD2H8MI=; b=PqzA39fvAYckIppyZtfewfXKi2rsOVZcFMNY7VAlu/NzzZwh6wG98DDn9k/tUsk5b9ljIN 0DRoIuJGRHzOQEz9txC6JRCxcF+Xx2JC0vbz/Bkn/N/b56GqOIQvmAefWIxHNcQp3hrNUJ BdeapLU3O/XXDXA/tq5mSciepmXYB7Dedrmz0/5w8mfu6+xgH10gJxLqRyfKttyFB60xgY kSn9o7OcT71xATBwPpNJm+DfaUTtuvjdz4qIJ8GwoevfhBcM2+NdKGILR027UbLHO7iy0v TV3xP5bTXL2c5zdupNN5W8jwAcJk+KZW1Yoh9qhyeWrCll9UX6P8DsgzUZMKqA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EFE9114ED6; Mon, 17 Jan 2022 21:13:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20HLD2fw006829; Mon, 17 Jan 2022 21:13:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20HLD29r006828; Mon, 17 Jan 2022 21:13:02 GMT (envelope-from git) Date: Mon, 17 Jan 2022 21:13:02 GMT Message-Id: <202201172113.20HLD29r006828@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f75b1ff6e569 - main - Revert "libthr: Use kern.stacktop for thread stack calculation." List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f75b1ff6e5698ac092aa33d66ea73a56f381ed99 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642453983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CnQCVPws6eiLxZBqvMT8IB8K2SU4EWR5fQaUyD2H8MI=; b=I/TXzg04TSvgzWoQefB/xTpPx+aQyJqqStaLOzWM8gkP02NPGoedKcn7MSiAnk+fHmQguf hUvpMiJvTt7i7cABLHdQEHF27sUvUpK8bsMfBR38/0rp6h7+m1XpE1nEITkyw8SRsCjVFo oJj9fcYUiXjLEgN9nvah8vZh3zsfTZbhPXgaSC8O4Ybmc7xNg2IpZaxGcb0tP0kvrhr3Yi 9+KgfMH9gHBzR8YuQpO0QgzUh4UpVc96bBKenLOYypoZCAszP/03KbO3OE0joE7/RRqBoP nE92Vl4CfrTk9iC20h0dJ/OdFYjMRORx+AG239jbUBM43Fta2vDOCCYzk0Bz5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642453983; a=rsa-sha256; cv=none; b=h2hx22vKNUEc4LZ+Kf7Wb5vvuO5pjN0xc/PKX2P5q/72kaQh4Gs/zgSEdl9LCn8UF3am3p aFZBGnlNe+i6W7v+VgfYc5AgjcQfgMoNIBNvbqL4zAkP4i3NxqiLQGUhpQoze1r5grmxa7 O13u3tLZLeras0gNb6LRp3SGR2QaTlcKCa+A+DDhOQFWm9H20VRSgUf4gYwjkVdh7ffc81 gl6/9MGykXW7PEkVw2vdf7zkTEPpsGVAdH9Q7MeUfS2O59TDStzW/IAdbeRLDShkJ7qBVH 1YiAl81/xOQcMBr38tC5lzTkJ4K3rtq8iy195+3OlM3T192UtC0MLjStI9odGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f75b1ff6e5698ac092aa33d66ea73a56f381ed99 commit f75b1ff6e5698ac092aa33d66ea73a56f381ed99 Author: Mark Johnston AuthorDate: 2022-01-17 16:41:49 +0000 Commit: Mark Johnston CommitDate: 2022-01-17 16:41:49 +0000 Revert "libthr: Use kern.stacktop for thread stack calculation." The current ASLR stack gap feature will be removed, and with that the need for this change, and the kern.stactop sysctl, is gone. Moreover, the approach taken in this revision does not provide compatibility for old copies of libthr.so, and the revision should have also updated __libc_map_stacks_exec(). This reverts commit 78df56ccfcb40013a3e6904bd6d39836220c3550. Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33704 --- lib/libthr/thread/thr_init.c | 19 ++++++++----------- lib/libthr/thread/thr_private.h | 2 +- lib/libthr/thread/thr_stack.c | 22 ++++++++++------------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index f2a66c406e85..82bde10a153e 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -61,7 +61,7 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" #include "thr_private.h" -char *_stacktop; +char *_usrstack; struct pthread *_thr_initial; int _libthr_debug; int _thread_event_mask; @@ -388,7 +388,7 @@ init_main_thread(struct pthread *thread) * resource limits, so this stack needs an explicitly mapped * red zone to protect the thread stack that is just beyond. */ - if (mmap(_stacktop - _thr_stack_initial - + if (mmap(_usrstack - _thr_stack_initial - _thr_guard_default, _thr_guard_default, 0, MAP_ANON, -1, 0) == MAP_FAILED) PANIC("Cannot allocate red zone for initial thread"); @@ -402,7 +402,7 @@ init_main_thread(struct pthread *thread) * actually free() it; it just puts it in the free * stack queue for later reuse. */ - thread->attr.stackaddr_attr = _stacktop - _thr_stack_initial; + thread->attr.stackaddr_attr = _usrstack - _thr_stack_initial; thread->attr.stacksize_attr = _thr_stack_initial; thread->attr.guardsize_attr = _thr_guard_default; thread->attr.flags |= THR_STACK_USER; @@ -427,7 +427,7 @@ init_main_thread(struct pthread *thread) thread->attr.prio = sched_param.sched_priority; #ifdef _PTHREAD_FORCED_UNWIND - thread->unwind_stackend = _stacktop; + thread->unwind_stackend = _usrstack; #endif /* Others cleared to zero by thr_alloc() */ @@ -464,13 +464,10 @@ init_private(void) __thr_malloc_init(); /* Find the stack top */ mib[0] = CTL_KERN; - mib[1] = KERN_STACKTOP; - len = sizeof (_stacktop); - if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1) { - mib[1] = KERN_USRSTACK; - if (sysctl(mib, 2, &_stacktop, &len, NULL, 0) == -1) - PANIC("Cannot get kern.usrstack from sysctl"); - } + mib[1] = KERN_USRSTACK; + len = sizeof (_usrstack); + if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1) + PANIC("Cannot get kern.usrstack from sysctl"); env_bigstack = getenv("LIBPTHREAD_BIGSTACK_MAIN"); env_splitstack = getenv("LIBPTHREAD_SPLITSTACK_MAIN"); if (env_bigstack != NULL || env_splitstack == NULL) { diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index d6fb74bb4372..a5bbc5997d30 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -724,7 +724,7 @@ extern int __isthreaded; * Global variables for the pthread kernel. */ -extern char *_stacktop __hidden; +extern char *_usrstack __hidden; /* For debugger */ extern int _libthr_debug; diff --git a/lib/libthr/thread/thr_stack.c b/lib/libthr/thread/thr_stack.c index fe50bc76db5f..b08bafdd9417 100644 --- a/lib/libthr/thread/thr_stack.c +++ b/lib/libthr/thread/thr_stack.c @@ -149,20 +149,18 @@ singlethread_map_stacks_exec(void) { int mib[2]; struct rlimit rlim; - u_long stacktop; + u_long usrstack; size_t len; mib[0] = CTL_KERN; - mib[1] = KERN_STACKTOP; - len = sizeof(stacktop); - if (sysctl(mib, nitems(mib), &stacktop, &len, NULL, 0) == -1) { - mib[1] = KERN_USRSTACK; - if (sysctl(mib, nitems(mib), &stacktop, &len, NULL, 0) == -1) - return; - } + mib[1] = KERN_USRSTACK; + len = sizeof(usrstack); + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &usrstack, &len, NULL, 0) + == -1) + return; if (getrlimit(RLIMIT_STACK, &rlim) == -1) return; - mprotect((void *)(uintptr_t)(stacktop - rlim.rlim_cur), + mprotect((void *)(uintptr_t)(usrstack - rlim.rlim_cur), rlim.rlim_cur, _rtld_get_stack_prot()); } @@ -215,7 +213,7 @@ _thr_stack_alloc(struct pthread_attr *attr) /* * Use the garbage collector lock for synchronization of the - * spare stack lists and allocations from stacktop. + * spare stack lists and allocations from usrstack. */ THREAD_LIST_WRLOCK(curthread); /* @@ -251,11 +249,11 @@ _thr_stack_alloc(struct pthread_attr *attr) } else { /* - * Allocate a stack from or below stacktop, depending + * Allocate a stack from or below usrstack, depending * on the LIBPTHREAD_BIGSTACK_MAIN env variable. */ if (last_stack == NULL) - last_stack = _stacktop - _thr_stack_initial - + last_stack = _usrstack - _thr_stack_initial - _thr_guard_default; /* Allocate a new stack. */