From nobody Sat Nov 25 09:05:54 2023 X-Original-To: dev-commits-src-branches@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 4ScmD252snz51v12; Sat, 25 Nov 2023 09:05:54 +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 4ScmD24cS7z4cR9; Sat, 25 Nov 2023 09:05:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700903154; 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=azIy6uxyQLJM2QeY3w/OfBcvQD0e+ac2V0lDHNXhVfg=; b=wRfDQqKem9WT/x4jHJZ0SRfXX6uQByVxo52RZG2euHigD6EqAMg4uRPTr+N8WFlQ4uzsMi UpS+rZeGKewngYBhh/4Hfbu+qEJPt23L1IjeInfTET5IgY/tyy5KlZb2I/bVEDZJwK/Pxw +guik8jvzM4kWgskDgnosrIJfaYlAofyuX/KH94pK9zhVRdnezzPnmdoCXKkF+7902kVbO OZCR9f8cPKkrLxXxDn4PJs3C3soDOxvKqc98OMMLoeTc5KZNBQ3nx58AqfVkuU5JC21p5B 63cpPfn7cvBE61Yvc6r9hfFexYuAsQkgXpD7ZgawTFrgJXYXhnHzK75lKYc2YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700903154; 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=azIy6uxyQLJM2QeY3w/OfBcvQD0e+ac2V0lDHNXhVfg=; b=BrGAM01jjxVkW1a0ExACZX1dyCpZ9B+N1S0yk9H5IsPPHGqltbHU7P4AaNQZ0f7hwNfxLf pTaLDwe4xxGnLsFNHCOr0rADFWU4WihPlhhDKZlesZJ1JhGuGkCt4BET/tFYN7/weWdSpx guotrxZaliyM5vOHU6AZ6xERCFY6RLSvNVLdTOZ9ry4+owpWNgMuOHHf73ks5PI5UNSt/K QNPF2jkcrUH9sAvXhlo4RDJY07OwoTiXuvYrsPeQ61/vNF5CjyPHoq7YdWCk4cLsGvN7uX JwKLlrdFo1MKqv7xUwCH0yRyAfDtaszWXyNKon4aREsgJd536v1Did+/wJzX+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700903154; a=rsa-sha256; cv=none; b=tFgiQuda9DRhqWujzhBf8RS6t568H12Emf6M6cdPZOM8lnmt0K0WvBLKGvw2T7kGaYug7B QolTsKYPoyGCdNJnLsIuWo7SY2VYQfJNEVDAwdpWjGM9nNwkf4Rt4odzyucukUT2Ezca2x HeN98fef2TJkJMQzZcuSSs9W3e3GaU9H8ck39qAU+7WXN5S72LmWEkd46Oyvf64YZ5Fhvz FCHfmEngwJZ2xF2tYXc7je0gQhWQYwzxtuYkIvsdT6idESbleFv/yIGq6tP+bDSmn83Rcl d4xzdwu8SryhNWnn+l7LqzrbAJEyhzv7kFVaOIJvV7nFI8PQLLmsHcg5S41nUw== 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 4ScmD23YQdz1LhS; Sat, 25 Nov 2023 09:05:54 +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 3AP95suK021598; Sat, 25 Nov 2023 09:05:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AP95s23021595; Sat, 25 Nov 2023 09:05:54 GMT (envelope-from git) Date: Sat, 25 Nov 2023 09:05:54 GMT Message-Id: <202311250905.3AP95s23021595@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: 7c25a53a2cb9 - stable/13 - compiler-rt: avoid segfaults when re-exec'ing with ASLR List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13 X-Git-Reftype: branch X-Git-Commit: 7c25a53a2cb975e516cfea78898bfb850db88524 Auto-Submitted: auto-generated The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=7c25a53a2cb975e516cfea78898bfb850db88524 commit 7c25a53a2cb975e516cfea78898bfb850db88524 Author: Dimitry Andric AuthorDate: 2023-11-22 18:23:06 +0000 Commit: Dimitry Andric CommitDate: 2023-11-25 09:05:14 +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[] = {