From nobody Tue Dec 05 18:22:03 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 4Sl8573RM4z53HqN; Tue, 5 Dec 2023 18:22: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 4Sl8572wlHz3XT4; Tue, 5 Dec 2023 18:22:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701800523; 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=ebgot7seZQKahHfOGha6AIcc8304Da2PKgbWJ+dhCPo=; b=VorqWLXFG8H3esC7FVcA9vHUPwzfn9D4vTyGxdsPiyIBKJnqBG3jK5Az+k1n1C8BE+Z8n9 38f7WaNBdXfSHpH7yHfLS5LVljmZYROqAUmI3QglwA/UGQ485mxcTBtlbc95raaTfceEUX XmXvGpkxDcLPyPfhvljU7zduz62BtvBBloa/GOaGQI+qu3JoWe5gZUfDI0jmP51YoT97vD g9penrp0Q/vAZkh77IDIF902jUNqyy+VfzUIi0mocYpOHMaNr+A5TgvMtWjNzYUgWLCHHa kb/wJXOPJYZTzD9v14/5Y9TmjLe3BgKxl4v4wtSNU8GDuNMgVv76xLvg1Fd9ag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701800523; a=rsa-sha256; cv=none; b=EwzKjRJzeil7Eu+HvZn7YGAagChEnR66e/7oXbpMMgdTKojha63LKum7IZWxnJMovxWPdd O7RQPB/fj4ccJvJjXRtyPV6hHBIfN9jwq2XabbMMKlcfzA9JedY6/5KbMz9oGapS4dWlwY FUtLpMpUFYqaV2i+7nh2ZOlt81OpCjMDdBIM2+bdqMXjKOnuWwLhSo4kH1RqjQr6nRFbAW CEVJvLVh/j7jVI3FmIb6CnZWDLtCxpT0NEsjKPPdP2Cj0TjU+gsoiLcbStrRJb69NREXeU wAsDYg3F1T6nVCTCiCP3/9LYAqPoERPG80XxlpST7FZDIzTSRgaib+SmNGFF6Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701800523; 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=ebgot7seZQKahHfOGha6AIcc8304Da2PKgbWJ+dhCPo=; b=KNrpwX/eBOE7b8yoXYxptrFOuJeowTf39EKm8kZZs9T7w8eBSslCzVxOdzGsXtraAVmfQN D7T1sMuGC6ILZIu3QKRVy7EbfXc+T5+qm3cZfUsnhzqixlu+KTkM6wGLtk5hjnuAXsfpLd AzKAmrMt69VMrMFtbWTltjCPGfWjYe75N7w9ZNfNZ7niejp9EWCpPsHcAgKnIZheC6+S+o sf9uyhGpUsrUF+sSWzrf1VO91iFtg3DhwQEMrl3MayFCggLHxeTWwzkmyU//1dFsLYBY42 ZCXderm56a485EwdMzqeYZQkWCvYVXDhIKVA2dPmA22iZpnewdkRDyX9Q9wu+Q== 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 4Sl85720nWz5Y7; Tue, 5 Dec 2023 18:22:03 +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 3B5IM3al003803; Tue, 5 Dec 2023 18:22:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B5IM32m003800; Tue, 5 Dec 2023 18:22:03 GMT (envelope-from git) Date: Tue, 5 Dec 2023 18:22:03 GMT Message-Id: <202312051822.3B5IM32m003800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 6d94fc2b0db9 - releng/13.2 - 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 6d94fc2b0db9c2f0b0d5b116513d745122bc37c4 Auto-Submitted: auto-generated The branch releng/13.2 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=6d94fc2b0db9c2f0b0d5b116513d745122bc37c4 commit 6d94fc2b0db9c2f0b0d5b116513d745122bc37c4 Author: Dimitry Andric AuthorDate: 2023-11-22 18:23:06 +0000 Commit: Ed Maste CommitDate: 2023-12-05 18:20:00 +0000 compiler-rt: avoid segfaults when re-exec'ing with ASLR 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 (cherry picked from commit 4c9a0adad18263ec8725d9bfc5f560c6ad1da8bd) (cherry picked from commit 7c25a53a2cb975e516cfea78898bfb850db88524) Note: This is a partial cherry-pick, as only the ReExec change from the original applies to FreeBSD 13.2. Security: EN-23:15.sanitizer Approved by: so --- .../lib/sanitizer_common/sanitizer_linux_libcdep.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 15a6a4998bd0..6e2c51ea3e8d 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 @@ -55,6 +55,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 @@ -905,11 +906,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[] = {