From patchwork Fri Jan 16 14:10:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 128239 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id CA0924BA2E26 for ; Fri, 16 Jan 2026 14:11:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA0924BA2E26 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HAR2uBDb X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6E6AB4BA2E06 for ; Fri, 16 Jan 2026 14:10:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E6AB4BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E6AB4BA2E06 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768572655; cv=none; b=mtNfHprqtXlmAi0iCFKcWZn7wyaIwwDKWHrfCPLyDqBZ6Kdsey/NlzXqAPjT6gRZkiYnH4rY8mtG0XmBWaLKprD+WtFRyeXe9iz8CR8xULp1XIzjiNprWss9dskWIXvV8Xh5oglJiNN5b/DNh0rjxUjFDPj/DgNmf7Yysriuz1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768572655; c=relaxed/simple; bh=+Y2D4h6UObUh4KTagWhPELUQ8RhKGVhFq0ouiCLkoSk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZqgB+S5AYDIfiaIBJE1lRxeALuqeQg18KYWYNsSwKBmkvpmuwyrCly11tiX+8weL6s7DboNN9mrqFGrsasiwOaXRPPt2sp9C5pucaO3GwLeq3iwbPitnm7s6AOE/1sPXeLF0+KuPhzKWxZH/PchAaxlHEW2EUxR5z1u22L1FuqQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E6AB4BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768572655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XXpLk6CcIgZsC5r6FT3CcjxRlgQe5vmSuuFgI40z7pY=; b=HAR2uBDbH9SZrEbmzrrrGg3zHqi9jrzoTjihWv1HS3h1tu3GN5SHo1l5Y7DHh24+y8wlw5 GN77LayxvS2UrRVowEkvoGNRQhuCmZS6PuU9ZU8+aOGs6Z7loHhvzyyK/KcYOkBCxfbBzl wuo91ZrFwIz/m1RMTEn3tKDFxW6Sk40= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-190-TJa72bUYNhWZcCADxny6ng-1; Fri, 16 Jan 2026 09:10:53 -0500 X-MC-Unique: TJa72bUYNhWZcCADxny6ng-1 X-Mimecast-MFC-AGG-ID: TJa72bUYNhWZcCADxny6ng_1768572652 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-430f57cd2caso1800206f8f.0 for ; Fri, 16 Jan 2026 06:10:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768572651; x=1769177451; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XXpLk6CcIgZsC5r6FT3CcjxRlgQe5vmSuuFgI40z7pY=; b=cNem5kPmgdk7lbldCO7tRhTU8Y7hkfS2pAjcH9EqpEQjRGrfVkZFX85B8Dlo5/zHQC h9kf75ilIJBEAO4dKOWMKhgSkKv3vPvu7Q1X1QuaQzmzYPZcFi0zeSTgUff+X2SX/n9L a61pSuotZfqJ518lrUVwjsJUIRnhY8ByEGt4Q95hYHFMnETY7O7YG4Lhlnzx4nElUT+7 g4wekkIfg1poN3ZvequLZfPG7ooquxXAOT9xFb0btHHUIn/9Kmi4WXmngg6B4tEuHwOE kFFwgaKlEaVLxXlNYaheTe4JQ8gTvphPu2YSDUwzpMUkLekr5713R+yJbQOJQeX8zCfy /Fow== X-Gm-Message-State: AOJu0Ywq/2ab4P3CBp4y28noM8ehhZKEb9g7QsPmfN1jkGrgiTWKKuzJ VPqO51jeRWUItPzXMHiHKxD1BKBWnqwVIUGaMzl70J2bO4syMTcSs7mcrUoyK5EAYOKtYFjtINU eR/UUPQ00ZBFk2FHhw0zvLPdR4bBjk5xtbjkHjPOEi3PxUpaV4qdSO5I5/vmNBmXAkQ8McNgcCp 29H/rdmQ/XZEkk/MVkaPPEVuqFvDuMlTICtp8wbpDdXg== X-Gm-Gg: AY/fxX730k77HufCPmkKX+yKOmlpLHn2nb8WR7+ws4LJYgy7Zthf4unc3+wIP4lni8w cZauHYgDY7lDHpB2FbZFOcbZqmaSQCkf9dgOUmBCJ1e2jaS6TgT61hHFNwOWj8jSWlF4+koj3vw Rx39owswoqlmzCLjfNij+YTMRZH9dpsmBE6voStQxhzIK3uovjy0IvmXc2PVs8tOZjIWwzv2gZZ ZXrIZ1Q0DBjQxPyhIvZDebPvt+fRnX8YchlYWbvINV3KAemNYZaR+LCkwtDRVCFfComPaZhFhpD 2bqg2MV9MGUdCl3PbmxTS6mUAQKNg40Z0kW9V7M8HCptaCP6lyaCKKcpvE+21FsTHMp/9L8CDls 3mycdLbxBji7LNzAlUTeLa9dCUuXx3UKvoZD89g== X-Received: by 2002:a05:6000:178d:b0:430:f68f:ee7d with SMTP id ffacd0b85a97d-4356a082e1amr3779391f8f.47.1768572651352; Fri, 16 Jan 2026 06:10:51 -0800 (PST) X-Received: by 2002:a05:6000:178d:b0:430:f68f:ee7d with SMTP id ffacd0b85a97d-4356a082e1amr3779347f8f.47.1768572650893; Fri, 16 Jan 2026 06:10:50 -0800 (PST) Received: from x1ctwelve (ip-94-112-226-240.bb.vodafone.cz. [94.112.226.240]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43569921da2sm5504501f8f.1.2026.01.16.06.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 06:10:50 -0800 (PST) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Arjun Shankar Subject: [PATCH] dlfcn: Add dlinfo request type RTLD_DI_ORIGIN_PATH (bug #24298) Date: Fri, 16 Jan 2026 15:10:39 +0100 Message-ID: <20260116141039.3823661-1-arjun@redhat.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Dh38z1rSNQytcNim7yHf89-BJtQocwvoDPaZUhxJAHQ_1768572652 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The existing dlinfo request type RTLD_DI_ORIGIN used for querying the value of the '$ORIGIN' dynamic string token is prone to buffer overflows. This commit adds a new request type named RTLD_DI_ORIGIN_PATH that returns a pointer to the dynamic string token (i.e. the 'l_origin' field in the link map) instead, and documents it in the dlinfo manual. A test for the new request type is also added to tst-dlinfo. --- dlfcn/dlfcn.h | 7 ++++++- dlfcn/dlinfo.c | 7 +++++++ dlfcn/tst-dlinfo.c | 8 ++++++++ manual/dynlink.texi | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index a1ee0765bd..a73303a17e 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -167,7 +167,12 @@ enum the number of program headers in the array. */ RTLD_DI_PHDR = 11, - RTLD_DI_MAX = 11 + /* Treat ARG as `const char **' and at that location, store the address + of the directory name used to expand $ORIGIN in this shared object's + dependency file names. */ + RTLD_DI_ORIGIN_PATH = 12, + + RTLD_DI_MAX = 12 }; diff --git a/dlfcn/dlinfo.c b/dlfcn/dlinfo.c index 6a1a7345b5..a4c6ffb5b8 100644 --- a/dlfcn/dlinfo.c +++ b/dlfcn/dlinfo.c @@ -67,6 +67,13 @@ dlinfo_doit (void *argsblock) strcpy (args->arg, l->l_origin); break; + case RTLD_DI_ORIGIN_PATH: + if (l->l_origin != (char *) -1) + *(const char **) args->arg = l->l_origin; + else + *(const char **) args->arg = NULL; + break; + case RTLD_DI_TLS_MODID: *(size_t *) args->arg = 0; *(size_t *) args->arg = l->l_tls_modid; diff --git a/dlfcn/tst-dlinfo.c b/dlfcn/tst-dlinfo.c index 014cb1b6ff..d0c8d8fb6d 100644 --- a/dlfcn/tst-dlinfo.c +++ b/dlfcn/tst-dlinfo.c @@ -20,6 +20,7 @@ #include #include #include +#include #define TEST_FUNCTION do_test () @@ -56,6 +57,13 @@ do_test (void) printf ("origin: %s\n", origin); } + const char *origin_path; + TRY (RTLD_DI_ORIGIN_PATH, &origin_path) + { + TEST_COMPARE_STRING (origin, origin_path); + printf ("origin_path: %s\n", origin_path); + } + Dl_serinfo counts; TRY (RTLD_DI_SERINFOSIZE, &counts) { diff --git a/manual/dynlink.texi b/manual/dynlink.texi index a388d7eeeb..7acd1c260f 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -554,6 +554,12 @@ The namespace identifier of @var{handle} is written to @code{*@var{arg}}. The @var{arg} argument must be the address of an object of type @code{Lmid_t}. +@item RTLD_DI_ORIGIN_PATH +The @code{$ORIGIN} dynamic string token pointer for @var{handle} is written +to @code{*@var{arg}}. The @var{arg} argument must be the address of a +@code{const char *}. If the @code{$ORIGIN} could not be determined, a null +pointer is written. + @item RTLD_DI_ORIGIN The value of the @code{$ORIGIN} dynamic string token for @var{handle} is written to the character array starting at @var{arg} as a