From nobody Mon Mar 11 00:30:32 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 4TtHk11mkGz5DDcX; Mon, 11 Mar 2024 00:30:33 +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 4TtHk06xvcz4ttH; Mon, 11 Mar 2024 00:30:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710117033; 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=lhQDq065743AEf4+af9GkQDsm/fcBZX8i0uYMjQrFnw=; b=u3ilPiIjplTotE5n4dzJ4UnhYCIDZKjDnmFWjRAd8kMFqVC5gLxaZEGPC6cXALo9HQMlXm RQmg/jmqdy8hTxPSL0ak9y12SNxWjO2bSRstzQYktebOqO6389MkRk+sBb9CtNVJ4e8t0Q F+HRUbR43BVhaxEarC26WcLpWkCWDnng4oAtQVzozL5/QK8XTLioIfHh5EWjF6YHclE7Dl 8XNaBI4mF/uCU2C7lWxEH0TY8XMWLGGBcieC+TKD/8v8gcORqXJWfkEGJgzqwCECgP3J7S qTGOxT9YtyJZt1OmQmnXDf7aAo6WXb41gyPMyGu+BKG6NQo42vQUMv3scz4XwQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710117033; a=rsa-sha256; cv=none; b=X3YU8SIDlnDAv6Td+/qKiM/p+khB9+BRJHZYykAIYAlPHwHQsj6E+5otWaSGFSvqUMeBV3 HQMnUurKU0QSJrVldb+Vabf3BXgs3tmFUicYlX1IVGkOj3e0Si92GPnklUIRq1nqIPqZnk mb2heVjeUg91kbQCX9i8UXhOqTjNZYqJmbBKT4ecNGdU3kdVlwL9a8b5Nt0a3mXq/cOHC0 oB5HRHqqLq0TT6BTanA9MZUnHEXVzn66SP4zviAVNr0DH0DU/3sMPQ4gamcvlWNUtB6LH3 FR/XS02mDmRr0unYDF7SWGHFYBL0kCfX3RGJO1KDObWFHfqb7ursu7HldZOW2A== 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=1710117033; 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=lhQDq065743AEf4+af9GkQDsm/fcBZX8i0uYMjQrFnw=; b=b9Z+5GyhiBYJIWmmyrwL2Q5jkWmOXhk5zwlPuKzMDP3aCDBacuY8uL9HaVaiQJFU7/O2Qj AUX+Wogm2TXULeyuBFR+lUEDk+LBzPjchH05kLZsJTx6yLfjv1e0sB4OQZFXHOvdIPyy9F 3ybB/2eU0GthJlC9iTPp+0OYqahGgE76nOB+QG593lH2U7LR6DX2Q8T/udnmXBwpKFYlQO KPpZoE5GDBVUo7bizEaERt+14ABHEMlOYj2ZFf3lUA38YDZNgwNpft+9N/4GJDJUxmZ38K TNk+ZMZV5JYSCptO6IHlK9E7F5uqRk7qDIMjm04IjO7i0itT1nwqw3qoigtGxQ== 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 4TtHk06LbVz16h1; Mon, 11 Mar 2024 00:30:32 +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 42B0UWK5003028; Mon, 11 Mar 2024 00:30:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42B0UWJ7003025; Mon, 11 Mar 2024 00:30:32 GMT (envelope-from git) Date: Mon, 11 Mar 2024 00:30:32 GMT Message-Id: <202403110030.42B0UWJ7003025@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: fc287f28dfc9 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: fc287f28dfc99bfe47d7a6071f52ddecd9983472 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=fc287f28dfc99bfe47d7a6071f52ddecd9983472 commit fc287f28dfc99bfe47d7a6071f52ddecd9983472 Author: Konstantin Belousov AuthorDate: 2024-03-03 13:30:04 +0000 Commit: Konstantin Belousov CommitDate: 2024-03-11 00:29:51 +0000 posix_spawn(3): add POSIX_SPAWN_DISABLE_ASLR_NP (cherry picked from commit 822042fdfca79faada89e67110b01dd9ecc05996) --- 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 49a63bb40501..eda654a2f7e6 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -29,6 +29,7 @@ #include #include "namespace.h" #include +#include #include #include @@ -92,7 +93,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 @@ -140,6 +141,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); } @@ -632,7 +640,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);