From nobody Mon Mar 04 01:00:46 2024 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 4Tp0k65wn6z5Ch0s; Mon, 4 Mar 2024 01:00:46 +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 4Tp0k65VKmz4lfX; Mon, 4 Mar 2024 01:00:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709514046; 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=NqKGMfbbR063a5g8m9kiTNAmyqFi74jsr0/fGHns0nc=; b=UoS7r1CJxG7VOEIVsa4OgLwAZ+BNtPh2VEXl0W6QTz9+ATUa89in6XSzo1Bpr18xnsCxkg zx35jD0dKmAH7AbpdXVQWHs7HzJO4O3NKrtMhDpLxZR8KUn7Db7KHRL7vL7oa8QcUnCZ6J jNKPMEeuLgkfmLDkVwqZHb9cCRBmb/YMdVK0Lwgw4sioDbZs9lB88a1rQA1RETLRewdVcw mHjleKAyBzyKIJPVnQYLs+NN/MCxhTTWjGO+tXzQWwSftAWzRPyumY92McZWFtr1MYZ0kQ Ariutq6872oZHYBp5QBNCIQtuZ5pjamB6+hlhTAm8fjC4jgEvpXAZEER9C60Xg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709514046; a=rsa-sha256; cv=none; b=FBZcQvytP9ybj9XuUuWZ/li7qY/PuZ868q+zGszsBXz+24dvhaEva2PRgOUiZ6B2b7hz2x +pvaLfzj0pUY+BK93eJ94vjL3xz+g37pd0mVgw3p3OoX7x8eKcJk27VTNNvUnYbx2h0bA/ /2XNIUNt7bhjOK3kiQbfEbH3cyEr846LfY226p91Q6Z136litlKMQ1wd/O7iJpeKcmYzb9 dKZWa6Cww2fR5zIwxn6iREXYk868f+i3Qry4tzn3am8Wr612ROZHbU6O4zwbfG6oHTgalx kTL0Z0AE6SQ9IG6nWakj90+SYIPuzQh/xu7fYclvoC3g267VyN8gDcwjJIv+QQ== 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=1709514046; 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=NqKGMfbbR063a5g8m9kiTNAmyqFi74jsr0/fGHns0nc=; b=SeVay1dUqMnRyhOADX72/x3R0guke8gzGV7wxEEpUyiucLqCDCAQF2bdniaZ8PZFypPupk lCFU9rLQGQxmK7zZefpkM37Oi/gm8jZ6biRRwk4/cH44lujG6wMo1+iWe8i089ipxc6/gW 4oXHHb2zDLS9Vg12kJ2b89865pTNfhSm56JwCci2ASmeUVgkvndVEvaeRHJpr47MdFP+CU Tflw6SWlE8ekqYqEuCFPdc9gwWX9/CehxMsBVXt9FepFskpG6wUA3ck64aqyI0ExGDw+Mv oWn+750AA55S+reE+BKap2E0KRKiutNDmfQfVWmtwDxQT4l4NOsKx1p6J1IObw== 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 4Tp0k655ldz11KK; Mon, 4 Mar 2024 01:00:46 +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 42410kbo004206; Mon, 4 Mar 2024 01:00:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42410kWZ004203; Mon, 4 Mar 2024 01:00:46 GMT (envelope-from git) Date: Mon, 4 Mar 2024 01:00:46 GMT Message-Id: <202403040100.42410kWZ004203@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 822042fdfca7 - main - posix_spawn(3): add POSIX_SPAWN_DISABLE_ASLR_NP 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 822042fdfca79faada89e67110b01dd9ecc05996 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=822042fdfca79faada89e67110b01dd9ecc05996 commit 822042fdfca79faada89e67110b01dd9ecc05996 Author: Konstantin Belousov AuthorDate: 2024-03-03 13:30:04 +0000 Commit: Konstantin Belousov CommitDate: 2024-03-04 01:00:38 +0000 posix_spawn(3): add POSIX_SPAWN_DISABLE_ASLR_NP similar to Apple _POSIX_SPAWN_DISABLE_ASLR Reviewed by: emaste, kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44195 --- include/spawn.h | 1 + lib/libc/gen/posix_spawn.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/spawn.h b/include/spawn.h index 9643fcda5c13..a93315930954 100644 --- a/include/spawn.h +++ b/include/spawn.h @@ -59,6 +59,7 @@ typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; #define POSIX_SPAWN_SETSCHEDULER 0x08 #define POSIX_SPAWN_SETSIGDEF 0x10 #define POSIX_SPAWN_SETSIGMASK 0x20 +#define POSIX_SPAWN_DISABLE_ASLR_NP 0x40 __BEGIN_DECLS /* diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index 41e059cf437b..4726416f1d02 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -28,6 +28,7 @@ #include "namespace.h" #include +#include #include #include @@ -91,7 +92,7 @@ static int process_spawnattr(const posix_spawnattr_t sa) { struct sigaction sigact = { .sa_flags = 0, .sa_handler = SIG_DFL }; - int i; + int aslr, i; /* * POSIX doesn't really describe in which order everything @@ -139,6 +140,13 @@ process_spawnattr(const posix_spawnattr_t sa) } } + /* Disable ASLR. */ + if ((sa->sa_flags & POSIX_SPAWN_DISABLE_ASLR_NP) != 0) { + aslr = PROC_ASLR_FORCE_DISABLE; + if (procctl(P_PID, 0, PROC_ASLR_CTL, &aslr) != 0) + return (errno); + } + return (0); } @@ -631,7 +639,8 @@ posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags) { if ((flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER | - POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK)) != 0) + POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK | + POSIX_SPAWN_DISABLE_ASLR_NP)) != 0) return (EINVAL); (*sa)->sa_flags = flags; return (0);