From nobody Sat Nov 25 09:05:39 2023 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 4ScmCl2mzCz51tvm; Sat, 25 Nov 2023 09:05:39 +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 4ScmCl2LL6z4c5d; Sat, 25 Nov 2023 09:05:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700903139; 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=+n7aQ5oBq/IWqEGmJAMuQ6DKtmQRv7lx1QgGHtqe2DM=; b=sM4nQODAc3YSq5CLa94IN8AiyNe95FxvcHgGmEIi1g6NRxDyAOiBAcvxnXQZSw29le4vYg cPOA9eZ2dBwkT83kHei7XReuMy9m/YPtVTmFj0FNU+L74MSTU5Nqg3c1MUdW3ffPRII67M 0FWoZ/m75g5t6TjcUjllbilQ7YZt7fbQLwDuz/l2DmzR7KPncHbZjmeKnSiXy6+YVanPRi Xa5iVtU3swp2uF+7PE9a/keeTcDIsYyH9MDeDINFpNiQITo8ToKwsvNj5VtO3Rxwqx+NG3 fKhIeok7rUn6Rs3LRcid7SaO4ynwZRtIXwRkIwJcQdCqyq/n15Y0zsjmlufJOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700903139; 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=+n7aQ5oBq/IWqEGmJAMuQ6DKtmQRv7lx1QgGHtqe2DM=; b=fY7TZ6wJvt4cYJDYtGtM8yHzjBBbhZLUid0XB6t7zue6X8nbziP6Y9kMMb8l4QuQMMWeyz ZKx/R81z1/RWZTsaH9gUPbEZqfVtC8KTmROx/LtEpxmDJSDFMed63WYTru0MkMwhWM/NRP JP+WIvGHTD9olM/QwoufkhfrqwWlNZ4RBwEE90/pL5n3BI50LfWWnCffB6ZMUVTwQD2hb3 EIW+Zr+xTtNGgVnF+DcWFCOqjrok1aMzjXFutunFg+/c8geLf90ftV6gEnfGubMUmfu+sD EbR6HOs55jF37zo/s+IEWqiJCGcxTFLoaxJ6vuPqn0b4KJsFrsvQmEgVaNjUww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700903139; a=rsa-sha256; cv=none; b=kHIqtq0m0V2A2MIZqttDqEK/GSBVSxvOa18GKT3F3eqF6v5PuyoCw7U5DqtuzcGJGG5HzH 34BLZ59TF+O1J0agakRCaDkw3lB4nW0Z15TB7VjyK4nKHlaWW4kTiaV140iKkRody1Mdo5 rV17Tv7e3wBfsVeMhAPda++IXZeCl3N1suxOaln3llYVc943IFFgAhCoqNMzPxsf3Jkd8L 2JhdlgqZVZViCjLV/8fKAsJXht/GBeWj0+82e9JTW4d768GmzB7lJ56C5A1HjBzQvpyaRM TxGE011H7ndAUtPm7hYKoKeHHmVnG3gWeQX8fjPkWmtKVOyagS08xkO7nPxe2Q== 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 4ScmCl1Qnsz1L9B; Sat, 25 Nov 2023 09:05:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AP95dT7021437; Sat, 25 Nov 2023 09:05:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AP95dHE021434; Sat, 25 Nov 2023 09:05:39 GMT (envelope-from git) Date: Sat, 25 Nov 2023 09:05:39 GMT Message-Id: <202311250905.3AP95dHE021434@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 1e4798e9677f - stable/14 - compiler-rt: avoid segfaults when re-exec'ing with ASLR 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: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1e4798e9677f17a7cdc9a1873a0c6e008fc620d8 Auto-Submitted: auto-generated The branch stable/14 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=1e4798e9677f17a7cdc9a1873a0c6e008fc620d8 commit 1e4798e9677f17a7cdc9a1873a0c6e008fc620d8 Author: Dimitry Andric AuthorDate: 2023-11-22 18:23:06 +0000 Commit: Dimitry Andric CommitDate: 2023-11-25 09:05:09 +0000 compiler-rt: avoid segfaults when re-exec'ing with ASLR After 930a7c2ac67e ("compiler-rt: re-exec with ASLR disabled when necessary") and 96fe7c8ab0f6 ("compiler-rt: support ReExec() on FreeBSD"), binaries linked against the sanitizer libraries may segfault due to procctl(2) being intercepted. Instead, the non-intercepted internal_procctl() should be called. Similarly, the ReExec() function that re-executes the binary after turning off ASLR should not call elf_aux_info(3) and realpath(3), since these will also be intercepted. Instead, loop directly over the elf aux info vector to find the executable path, and avoid calling realpath(3) since it is actually unwanted for this use case. Fixes: 930a7c2ac67e, 96fe7c8ab0f6 MFC after: 3 days (cherry picked from commit 4c9a0adad18263ec8725d9bfc5f560c6ad1da8bd) --- .../compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 2 +- .../lib/sanitizer_common/sanitizer_linux_libcdep.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 3f544623c6fb..ebbd14eca72f 100644 --- a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2323,7 +2323,7 @@ void CheckASLR() { "and binaries compiled with PIE\n" "ASLR will be disabled and the program re-executed.\n"); int aslr_ctl = PROC_ASLR_FORCE_DISABLE; - CHECK_NE(procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1); + CHECK_NE(internal_procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1); ReExec(); } # elif SANITIZER_PPC64V2 diff --git a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index ff62fc4af430..58310e05b359 100644 --- a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -56,6 +56,7 @@ // that, it was never implemented. So just define it to zero. #undef MAP_NORESERVE #define MAP_NORESERVE 0 +extern const Elf_Auxinfo *__elf_aux_vector; #endif #if SANITIZER_NETBSD @@ -947,11 +948,11 @@ void ReExec() { const char *pathname = "/proc/self/exe"; #if SANITIZER_FREEBSD - char exe_path[PATH_MAX]; - if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) { - char link_path[PATH_MAX]; - if (realpath(exe_path, link_path)) - pathname = link_path; + for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) { + if (aux->a_type == AT_EXECPATH) { + pathname = static_cast(aux->a_un.a_ptr); + break; + } } #elif SANITIZER_NETBSD static const int name[] = {