From nobody Wed Feb 02 01:13:56 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 642AE19AF57E; Wed, 2 Feb 2022 01:13:56 +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 4JpP2X2Jx9z3Kwp; Wed, 2 Feb 2022 01:13:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643764436; 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=7/fveQMGDV3RjTpyqFt3Xc30HflTuWr+Pu+yfLYuQxk=; b=AnQ900gEaGamCmrltxrFr/2hqqMRUZOPlqPkj40KRjQPe7RbQRON0uPdTemyGTw+UYyJ6S oFDiR2cGdnDQCBtEF5LKz+M3VbZ0qrhQQUBxNNCZ2jWAaORE3JZgFflhv7YeG/RwUSYUrO G0OZwGVSi5Yi/KtxKe6Dbxmtm1ljBhJmO5mf2m1Et5vHb+rjxYmh6CNRX4FIDoB4HfFZiQ CmPzjAD/lF12BGh+7WkcPrrT0i30nK+aBxrG+8Aq8jcQt9ITRN7gfSBujN8L3H32qxUqUV 1mw48NR+24nUR0vRsbG1+ryxEbjipVIVqoZWCyg+Ani/GFlS9z/nEzrCRnHtsQ== 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 252F81ADDE; Wed, 2 Feb 2022 01:13:56 +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 2121Du4i042495; Wed, 2 Feb 2022 01:13:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2121DuTP042494; Wed, 2 Feb 2022 01:13:56 GMT (envelope-from git) Date: Wed, 2 Feb 2022 01:13:56 GMT Message-Id: <202202020113.2121DuTP042494@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: fd1501dcf0e8 - stable/13 - sanitizers: Improve FreeBSD ASLR detection 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fd1501dcf0e88cb2c273a3de7710ef0fbd3fca43 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643764436; 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=7/fveQMGDV3RjTpyqFt3Xc30HflTuWr+Pu+yfLYuQxk=; b=OWbMvZymORzRJuHmlkUFZWcMuEX1eOLdtwg1pZYFNaT9UfN3mSH4LOfHteTvQ+BEdhJd8N juw3k6a4JAr6CN7XgegYL+z9yV3mlM7MlDZHr5cJAJsYxAErXOO69eW7tmfBhoXrNBE79D 0PImYASnoaWJciEUFjzDPeI1d+VLbpZ82LzOQKBfD1Q8cRpYUJDpj9lSWiFUoRVdjpFStU X5XLKk355skK9atAfLw7+RqapsPgBpl12GMLbwAnYP/auMQ37Ws+TxxZCiSMdByGTTKtnj Ey2k7Ty/DCj8UOphc+AQva1LAqf69r62g18O0bK1S322gRaf1fIV2I64CJdRWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643764436; a=rsa-sha256; cv=none; b=DqRrktHvL3tzpjxL+ZqLurUIz2vPexjXXr2t43ggsAjrk0K73/vObKUNzAg4Gtll0/GGsB 4RCRyHZLZA79zjj5M2i0yI4KKHUGgHYMIyUzA0heG4c1ASyH/Bm3i960vVlCcmSSRtjVPw 5CmKDCNcJ/K3taQWfCE4NMOeFY/T+C5SCO1b8HN/V40P8a63d9J2RkpZ9EA0+NukbKDu2g LAylQdyAi57g18UE9oCxDMEkZsMhjR+4Ce8u9F9LkSsxvq32rZAS/wrWIhYAYKTYpVIc3i ypz5Pau26RYe1k4G5MEogeKptqgGm1Lnw5DmBpMSUPQD/UPX05/peYZoTx4orw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=fd1501dcf0e88cb2c273a3de7710ef0fbd3fca43 commit fd1501dcf0e88cb2c273a3de7710ef0fbd3fca43 Author: Ed Maste AuthorDate: 2022-01-18 00:00:35 +0000 Commit: Ed Maste CommitDate: 2022-02-02 01:13:30 +0000 sanitizers: Improve FreeBSD ASLR detection The kern.elf64.aslr.pie_enable and kern.elf32.aslr.pie_enable sysctls control the default setting for PIE binary address randomization, but it is possible to enable or disable ASLR on a per-process basis. Use procctl(2) to query whether ASLR is enabled. (Note that with ASLR enabled but sysctl kern.elf64.aslr.pie_enable=0 a PIE binary will in effect have randomization disabled, and be functional with msan. This is not intended as as a user-facing control though. The user can use proccontrol(1) to disable aslr for the process.) Approved by: dim Obtained from: LLVM 64de0064f315f57044294879d9ff4eacb454d45b MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33933 (cherry picked from commit 7cafe89f9ce33effe6e471b185339d413da1ca46) --- .../lib/sanitizer_common/sanitizer_linux.cpp | 25 +++++----------------- 1 file changed, 5 insertions(+), 20 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 9b7d87eb85e1..09b3f31831df 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 @@ -80,6 +80,7 @@ #if SANITIZER_FREEBSD #include +#include #include #include extern "C" { @@ -2187,30 +2188,14 @@ void CheckASLR() { ReExec(); } #elif SANITIZER_FREEBSD - int aslr_pie; - uptr len = sizeof(aslr_pie); -#if SANITIZER_WORDSIZE == 64 - if (UNLIKELY(internal_sysctlbyname("kern.elf64.aslr.pie_enable", - &aslr_pie, &len, NULL, 0) == -1)) { + int aslr_status; + if (UNLIKELY(procctl(P_PID, 0, PROC_ASLR_STATUS, &aslr_status) == -1)) { // We're making things less 'dramatic' here since - // the OID is not necessarily guaranteed to be here + // the cmd is not necessarily guaranteed to be here // just yet regarding FreeBSD release return; } - - if (aslr_pie > 0) { - Printf("This sanitizer is not compatible with enabled ASLR " - "and binaries compiled with PIE\n"); - Die(); - } -#endif - // there might be 32 bits compat for 64 bits - if (UNLIKELY(internal_sysctlbyname("kern.elf32.aslr.pie_enable", - &aslr_pie, &len, NULL, 0) == -1)) { - return; - } - - if (aslr_pie > 0) { + if ((aslr_status & PROC_ASLR_ACTIVE) != 0) { Printf("This sanitizer is not compatible with enabled ASLR " "and binaries compiled with PIE\n"); Die();