From nobody Wed Jan 19 18:07:58 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 17746196BDB6; Wed, 19 Jan 2022 18:08:00 +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 4JfDC33NRnz3r1d; Wed, 19 Jan 2022 18:07:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642615679; 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=UE9nsVzrujyLHh73nRsDGLe1Idl+x8858slTIFO17bk=; b=KZteJDx2obSwHcnSTvYAoeiCtibOF6JUi8q51YHkltkuEOXGm7elOKJzpuTXvigPSmzBzo xp3FD89mV69kW+Z6c5xNepcjBcBJkCAX6sUETjoczEjefd7on/a3VDz7cHkmy9KdwGcSeM hT7dsqcdE/FaZ1xHfZ6C4sS+v2uNtlQ0lG5Fqc24Y5ruitqmPAi+OaEw7YsWcnPnYPgR5P CT4dXhaSfTaifeIO/aGyToebMDowecD4DqxF6AZ5Wa5WtiNb4oifmwq0el3qATVwLpUqst oGJJa87nNTtwk0kcpmFuJwygCPuuHcDec8G1MoESnEgw/3pdDfC/EHh9i/zN1w== 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 DCBD2195C3; Wed, 19 Jan 2022 18:07:58 +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 20JI7wXI004481; Wed, 19 Jan 2022 18:07:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20JI7wr6004480; Wed, 19 Jan 2022 18:07:58 GMT (envelope-from git) Date: Wed, 19 Jan 2022 18:07:58 GMT Message-Id: <202201191807.20JI7wr6004480@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 7cafe89f9ce3 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 7cafe89f9ce33effe6e471b185339d413da1ca46 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642615679; 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=UE9nsVzrujyLHh73nRsDGLe1Idl+x8858slTIFO17bk=; b=PKz4ekjNPGRlwdEPFk1k7S1puB3PnNXKRGZWi2O1ARIqB9svmJnFSNc25F0oGnfA58o321 WG7WSele1q1lNCBGmnvFWhg5cnryuxbw1zVI3oj5sS6gA60FuemEL1vSCzUqVv6DOeKx/2 ToqyL1FB/05yPidXugXg7TH3t2/2C6ICyi3yTIIlTPN1JmIw7t7VLKHUrZ/YLKb/6w/M+k 7/pUdfTJQFv9h0/BzewkO9wz/mZz0RMGLTbA4jP+UAddYapIvV2g2v+AebY7RjQTRojYXr LisUNojGmrT8zUOVxjYniOJFC6TOJ/OvU2XaHkIyjHEeYbhpiG5Dx5QerxAedA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642615679; a=rsa-sha256; cv=none; b=T8UTRLjOtSZBJa+bkyfKQESkC8TduNg9Sg2DAAjZu3pYVvzCO7K9u4BgbrZ2cx/OaUBWQU YPMcCcZOlGHctfuadyPbKye/62NkoZNtI8Q2OUcNwZzZ+2cvek8ZN93aCuC7ByhgJuz+Yi UnfquU4YJbi85/GX1VcRJlsH2VcHsA8ZWw73Nn3E1ooKQUdU0u/5jjr9BLBTcLSLbAeN/n wN70KNsWwq3tpEiBEn4tRJhhtQPC0jBe6Rdbd3AmzD5MjKIGEq5epzE4X+3qnhQGogfYZx vED1WcZ4JbQXNynHQvMGVs1muZU9lldn+8IYuqfLUEnViixo+Lc16oy/r62Uxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=7cafe89f9ce33effe6e471b185339d413da1ca46 commit 7cafe89f9ce33effe6e471b185339d413da1ca46 Author: Ed Maste AuthorDate: 2022-01-18 00:00:35 +0000 Commit: Ed Maste CommitDate: 2022-01-19 18:07:40 +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 --- .../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();