From nobody Wed Feb 02 01:17:44 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 C456919B0FC8; Wed, 2 Feb 2022 01:17:44 +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 4JpP6w539Hz3M2g; Wed, 2 Feb 2022 01:17:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643764664; 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=OqYmTx4xOUMsQRdqHg/K8inaEiU/dLdlr4EKBSrmJo4=; b=UC76d2jB6rUf7ed4tpAAImQpK2LBjnxDaixkbtmPLuIzesdCR/iHEAdW0eblyp2vhr0zzd FRRwDDBt6lVjfDdGWYDl1XmlVB9G/LHHeR0N3hU19QqUOd/OGDKAmZaen9M1vPV/3+ZAcy ycXPlaVaCiCMSkpOGYqXC54fbyFMtywT/DNv7Wv5uAUxx8VMiV3qKK4e85kXCs4NBeTkvo wkLwQlySdieOmo1If5Hw6u9X21rnTf7Ltilwh9MUU2yoX4Fp5qBlt7vFEcpSIwqJEbPL7K UAW1HHyOlhRVbSENLUk8PcD6GPLGsVWASdLSXDTdyKn6GxLXAL6Qn65RPGBbHg== 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 80E3F1B4C3; Wed, 2 Feb 2022 01:17:44 +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 2121HieV042808; Wed, 2 Feb 2022 01:17:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2121HicX042807; Wed, 2 Feb 2022 01:17:44 GMT (envelope-from git) Date: Wed, 2 Feb 2022 01:17:44 GMT Message-Id: <202202020117.2121HicX042807@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: bf1a58efa081 - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: bf1a58efa081ff4fe5ef0a679c56667f9c46235b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643764664; 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=OqYmTx4xOUMsQRdqHg/K8inaEiU/dLdlr4EKBSrmJo4=; b=FqD+55QT373Q6BPrz7SdyrM3lK5UZGkFng3io/epOd5cOD9kTmSJPMfDYvvONRGOWmah3s vofKsGokLvvyrYIqChsw/f3keMi8OzZeNM1IKtNalsMrnCAeof4LvUvguHe5wRd/lT8ZjB lQ74E2bJbm0AHbHu/QllkeN7CHZ6ZKaI23EK661j3Ubmw/u0khi14ewLagP3ckIZ+X9hBc EvkCJDYTepxhC5gCX1tUhqaVKQyp9TSp69a60gxjDcdw5wSk7Kh6SQapN5IdSueNpq6wJ3 LCct0h5/KQkVGsaGSctF+nj3DPZ7oldcjs3d71FD4569uXPbOFzjhNcbpQYGvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643764664; a=rsa-sha256; cv=none; b=n/X3SDDrrGjPj7uMHMHbotWo4YQQn59T7SJG1f7Q6kNWW3q8hGaFzfc4ESvLm0Hy2NfMEl 3DXe3iXHCaYvlkZywfSZAD57t4iX79e7bJfXMWpEUb3EQ3SehiFAtYNtDVjPVPzCnqXTM7 tdQZduK/Uex7p/c9bLeasKlVZekWmyt9y/zk/avavHrxGhzEJDX58u3Hsig0uUE93h9NLi zWy92t8HanSCk6c7LUH0eXeyNDR+IlVMJvwuvqM59AT846EkMnWic34yqftdO8Kj4zuwc4 Yxev1ZZ/lMQtPvisgnpA54zLvPKAxiiSGZvt/0DFy04TX+2DTLDMHth5d1xE7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=bf1a58efa081ff4fe5ef0a679c56667f9c46235b commit bf1a58efa081ff4fe5ef0a679c56667f9c46235b Author: Ed Maste AuthorDate: 2022-01-18 00:00:35 +0000 Commit: Ed Maste CommitDate: 2022-02-02 01:14:13 +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();