From nobody Mon May 06 04:42:45 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 4VXpgB0wLdz5JB2j; Mon, 06 May 2024 04:42: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 4VXpgB0L2rz4X7Z; Mon, 6 May 2024 04:42:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714970566; 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=qnt5pfxASXXbS2ZX3tpYoTL8kpsNgkEmzYCfjJ1GL/E=; b=mTQ5Un/K7daVQHDZTeUXiJuPFi8Tik5Js4WssDNiSGMXFNQz2l2S+yU7kd1Ppd7h1WYmIn onmEMQSOUIteeqSlA1L5062BUB1tVhIRdhqC+QmSrzMbBrvBFKB2daQ6jRG7JSFIrBywUw kM/MtawrJNgw/MztGIHJVtmW6ilozMS3f21qhlrqcEAuj2wWBB4RhmYUO6VSuBYNpACLeD Fho8JzHTgQL783Gzux/WvgckIc0pNeVn9ALm2BsyhZqGfriLU0xykq0OaM29APUWAJJOKo 2fYihQg90Aqmpof+zy+fs9f6m3DdY6vB57cIMlZON6zCzNb+cLZltUqJFCrGNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714970566; a=rsa-sha256; cv=none; b=ljJDAd8Y/WiZe/1r+ixMxUjhVPCl+Wv5ut4V7z5AiSkiyK9g24Zz7+t2DeSI9cwSbk7FBA 58wkOamrRLx2DCNnxQRiaJBCsfAV01ToKyrdNiIkQ2EHUoF5KDERBhYb+42XSeXuZj4OeH 8Mq5q7mswLbeBcrH6vKdpcgugGusPDtZ/DpXKmfH5XDA14oBVi9gEQalwaBBINkG622xeW WV3D2b4L4qgjy9l1Gw2fOmZYquG5IAckPm2eFRw5+ca3x2yD8O7/Nj1Q/zFxN6mGGjIIp1 ndMLQAgBlyGBaIn7B/uTpJLl0Ozk1bQxyIJtwFwl563sWvToaYXL9DkfrZLtNA== 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=1714970566; 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=qnt5pfxASXXbS2ZX3tpYoTL8kpsNgkEmzYCfjJ1GL/E=; b=iFGusZcEJOFCcBOHQZP7xonOWSGeevQYD4wdNSNAyfN/P6OhAdQXVcAaV17sn8PKdAa9co IavW1Okrm2xRIoSEbvYdLzOdDtUCfRAlnP6V+CyAPS9geBddymJGlsjwF3cgvfcORuBpSn 3temqNsHVIPTg6KLZrkGQyOmttjxYV7Eoxxxgrq9rFlmXbIdSaeIdLG2EWvhsamT6LDOjT OUEo4phVs4sthYGvd3IfEbSUl3hXqTN2gxyaFnK3tZKuD/UHwgL/MQ0Dhoz4DzoshS8ufZ 91Zovj8bboWqmq5erIN+pgWrzXQOnA9EzHo/fbe7aXH3FAZ7o8L6pXPC/hE03g== 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 4VXpg973vFzjKb; Mon, 6 May 2024 04:42:45 +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 4464gjnw049911; Mon, 6 May 2024 04:42:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4464gjVA049908; Mon, 6 May 2024 04:42:45 GMT (envelope-from git) Date: Mon, 6 May 2024 04:42:45 GMT Message-Id: <202405060442.4464gjVA049908@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: d63c680d39f5 - stable/14 - rtld: add direct-exec option -o 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/14 X-Git-Reftype: branch X-Git-Commit: d63c680d39f57ab36961a5b873f9962dc327d17e Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d63c680d39f57ab36961a5b873f9962dc327d17e commit d63c680d39f57ab36961a5b873f9962dc327d17e Author: Konstantin Belousov AuthorDate: 2024-04-28 03:19:39 +0000 Commit: Konstantin Belousov CommitDate: 2024-05-06 04:42:19 +0000 rtld: add direct-exec option -o (cherry picked from commit d1cd0cc32b53c09e72e33116b94a5b0b9781a183) --- libexec/rtld-elf/rtld.1 | 20 +++++++++++++++++++- libexec/rtld-elf/rtld.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1 index a152dd444bd7..0f1e8f68b10a 100644 --- a/libexec/rtld-elf/rtld.1 +++ b/libexec/rtld-elf/rtld.1 @@ -26,7 +26,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 29, 2023 +.Dd April 28, 2024 .Dt RTLD 1 .Os .Sh NAME @@ -352,6 +352,7 @@ The syntax of the direct invocation is .Op Fl b Ar exe .Op Fl d .Op Fl f Ar fd +.Op Fl o Ar OPT=NAME .Op Fl p .Op Fl u .Op Fl v @@ -387,6 +388,23 @@ If this option is specified, is only used to provide the .Va argv[0] value to the program. +.It Fl o Ar OPT=VALUE +Set the +.Ar OPT +configuration variable to the value +.Ar VALUE . +The possible variable names are listed above as +.Ev LD_ +prefixed environment variables, but here are referenced without the +.Ev LD_ +prefix. +A configuration variable set this way does not leak into +the activated image's environment. +.Pp +The option can be repeated as many times as needed to set +all configuration parameters. +The parameters set using this option have priority over +the same parameters assigned via environment. .It Fl p If the .Pa image_path diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index d5e702652058..0492b8f9d9f3 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -6155,6 +6155,35 @@ parse_args(char* argv[], int argc, bool *use_pathp, int *fdp, *fdp = fd; seen_f = true; break; + } else if (opt == 'o') { + struct ld_env_var_desc *l; + char *n, *v; + u_int ll; + + if (j != arglen - 1) { + _rtld_error("Invalid options: %s", arg); + rtld_die(); + } + i++; + n = argv[i]; + v = strchr(n, '='); + if (v == NULL) { + _rtld_error("No '=' in -o parameter"); + rtld_die(); + } + for (ll = 0; ll < nitems(ld_env_vars); ll++) { + l = &ld_env_vars[ll]; + if (v - n == (ptrdiff_t)strlen(l->n) && + strncmp(n, l->n, v - n) == 0) { + l->val = v + 1; + break; + } + } + if (ll == nitems(ld_env_vars)) { + _rtld_error("Unknown LD_ option %s", + n); + rtld_die(); + } } else if (opt == 'p') { *use_pathp = true; } else if (opt == 'u') { @@ -6238,6 +6267,7 @@ print_usage(const char *argv0) " -b Execute instead of , arg0 is \n" " -d Ignore lack of exec permissions for the binary\n" " -f Execute instead of searching for \n" + " -o = Set LD_ to , without polluting env\n" " -p Search in PATH for named binary\n" " -u Ignore LD_ environment variables\n" " -v Display identification information\n"