From patchwork Fri Jan 16 20:18:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 128329 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 4D39E4BA23CD for ; Fri, 16 Jan 2026 20:21:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D39E4BA23CD 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=Cmd+lSHQ 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 0C1704BA2E1C for ; Fri, 16 Jan 2026 20:20:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C1704BA2E1C 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 0C1704BA2E1C 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=1768594832; cv=none; b=MM7DFIPSWUI4Rgq2nGogJtj0rWyQx56VFjmXURLMUOoywEWjheSzjzgUkxPrSkayvFzDux/InEwAci/kzbDGarOlXNKX2Y1sPV66z0OZA8mdb8q08GUCFUQ51U6lF6pa5L5U1YUlw5rusLCYSyGQcMhxrkSLW4mFAXa7TDUcSAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768594832; c=relaxed/simple; bh=4LCiKnaZjnkYK0gADq2EazsEuiXUI7GlxXS+IAAdnQw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PF9+Ip9UZchCGk2fFxCwMGATVjW45J85EC5KbavgyUYLyn0VtyU2+Pb1pIiV/ddYXNS0ptuIyfFkfF/nWulNFpsJycVHwhAV6HHMbzqTpmUlL+OANB5TZtWiwUtPwhwsaPQgzXzBcdss+trFODWaWXrRtfgOLALt3hVOO1JIgPU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C1704BA2E1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768594831; 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=uDGdMeVBqXSBsHPQTF1Bxij9U0KL0TpHeFYOeknXu0o=; b=Cmd+lSHQjaElFjCYcfMFnD6Pzja3Lzp7taXdKGhE2w4FCTMhUfpNMtp3j9/fHUNH2sNYP+ BUjLfaXPcVal6wjWu7/FEqip0U46FhMiQM/wBX38dMrzjwJL+qw5R41Woviwo1LcHs+9uH JJEmoT283MmlLkg4nDPNBVqncpb5f6M= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-5Z_pAIxoPwGB_rx15yD7Bw-1; Fri, 16 Jan 2026 15:20:29 -0500 X-MC-Unique: 5Z_pAIxoPwGB_rx15yD7Bw-1 X-Mimecast-MFC-AGG-ID: 5Z_pAIxoPwGB_rx15yD7Bw_1768594829 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-47ee3dd7fc8so20302245e9.3 for ; Fri, 16 Jan 2026 12:20:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768594828; x=1769199628; 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=uDGdMeVBqXSBsHPQTF1Bxij9U0KL0TpHeFYOeknXu0o=; b=X9DmiyBKLWHdKF3WqO1RAQ76WK/F0F5zJDglhrIJKzEkkN3cspHp9N8dG9K2heP9ih 2AFshs6IczxBcWXYA2x2PfTzuXQ4V5gA2mFyG/NjvdyQkiS/8yHAwA3VO4Atwc1Gv5CN 8rnGrCJ58vVssbsH4PMIPWxwjr1V7Zd1AtxPlvfshTvx1pRo+kmW3Rxu+JC5R3FqANdb lYOvE9kP98CG0liGm0i9q12Rhb3owf6DEikknWwJ4AqpY8GDANx7cWUs+qJchT45LNoR ZCXSA76bX6XQDBOPp1lYk6Nq3950p6IjOQhkOdyPpCyl4ZyqugJ3PUAX4xTa0OQnOQX+ al0A== X-Gm-Message-State: AOJu0YywUDGPXOFwZE7eX9HxatuUsvkdKZPpIgHurCwsiqhsUTq0ILKT +bEPdP8GYhI0QNTHLgaaazp1BfSkFBXhg2hx8C19QrsBxkkAlSBPR0lHfr/O676uSXg0vbU9v5R 389X92nSq3e2i3N7VJyc9TmzPX4jsAtWsq6+gFeHNTxU9WQzcXOPnbIXfJlKG5dO3IkCP3lGS4f CGnJSLurvrXrQ9IcFdukG0uKr8HAVrakRhxysTSoU8Aw== X-Gm-Gg: AY/fxX5PgnmcoLMu1l7YgyOpyCvv3gDrp68Ka/j6K1YNNepyZ8oNK6m0vwaRyDEVcFT vVVFjoP9Y2crJqcl+qgdCYu6dIs/K65FvLfd2RAo1frrFwHjmmGW+KqfPShu7XaCKPP5jVc3dV7 cw9I+Hzs/kzYjWfkgjXFQDzkrzhzue8yqDi/bzOUbuI5YZMvyMp7rceRnldy81eWukRNhdRC2og J5wqFLYWXXLNZO93rrKa8JN2sR3cUf1MgeZzZ9aUfdObQCQee/I3SCd2MA7d399sSu9TshlOShF evhOQt0G3Q3FCVt2FFBPJkPM28GlCIEGgACP4kAYM5KQwHY9Mb2WMz8OYvLDre0ZNKcBJ4QvfuM QInx5MroG1PcHU4z4Dkvfc7cmc9EZSCV5wcKn4Q== X-Received: by 2002:a05:600c:674f:b0:477:9b35:3e49 with SMTP id 5b1f17b1804b1-4801eaba084mr38109235e9.3.1768594828237; Fri, 16 Jan 2026 12:20:28 -0800 (PST) X-Received: by 2002:a05:600c:674f:b0:477:9b35:3e49 with SMTP id 5b1f17b1804b1-4801eaba084mr38109065e9.3.1768594827782; Fri, 16 Jan 2026 12:20:27 -0800 (PST) Received: from x1ctwelve (ip-94-112-226-240.bb.vodafone.cz. [94.112.226.240]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47f4289b7aasm117163795e9.2.2026.01.16.12.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 12:20:27 -0800 (PST) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Florian Weimer , Carlos O'Donell , Arjun Shankar Subject: [PATCH v3] dlfcn: Add dlinfo request type RTLD_DI_ORIGIN_PATH (bug #24298) Date: Fri, 16 Jan 2026 21:18:42 +0100 Message-ID: <20260116202016.3863129-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: oCJmE0u7CmyKoEdTkQjcuL3uymfWxeJBzMHHkJOwh70_1768594829 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, URIBL_BLOCKED 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. The dlinfo manual is updated with the new request type, and the description of RTLD_DI_ORIGIN is updated to recommend RTLD_DI_ORIGIN_PATH instead. A test for the new request type is also added to tst-dlinfo. Reviewed-by: Carlos O'Donell --- v2: https://inbox.sourceware.org/libc-alpha/20260116150921.3841139-1-arjun@redhat.com/ Changes in v3: Address Carlos' review comments on the manual change: * Specify the lifetime of the result's validity --- dlfcn/dlfcn.h | 7 ++++++- dlfcn/dlinfo.c | 7 +++++++ dlfcn/tst-dlinfo.c | 8 ++++++++ manual/dynlink.texi | 12 +++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) 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..477370b81a 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -554,13 +554,23 @@ 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, the +function still returns 0 but writes a null pointer to @code{*@var{arg}}. +The returned string is only valid as long as the corresponding handle is +valid. Accessing it after @code{dlclose} has been called for the +corresponding object is not safe. + @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 null-terminated string. This request type should not be used because it is prone to buffer -overflows. +overflows. Instead, @code{RTLD_DI_ORIGIN_PATH} described above should be +used. @item RTLD_DI_SERINFO @itemx RTLD_DI_SERINFOSIZE