From patchwork Fri Jan 16 15:04:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 128242 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 4EA9D4BA2E2A for ; Fri, 16 Jan 2026 15:10:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EA9D4BA2E2A 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=ECtjaJv6 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.129.124]) by sourceware.org (Postfix) with ESMTP id 1AFAC4BA2E07 for ; Fri, 16 Jan 2026 15:09:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AFAC4BA2E07 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 1AFAC4BA2E07 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768576169; cv=none; b=wpnJ5Y3AqGFTjo7M1eXz11ARlyzU7TsM2Nj+FdmJcm/YeNm9G60wGHEnGAgLZ4bbmTPMhLGRN2p6q3SYeV6vKk8WuikB7hg4B22D7mCoRpzZDZq7pQw2b/G++kCTdmcyKjgCuOyKfJC99xLbAWVpwiVcLVu4ao36/K3P8VV3Z/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768576169; c=relaxed/simple; bh=b7TohnxKUXn92K9/MGxTCSn+LdsOUk23YGiutO+F3a0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eOH0e2WuJagZqqFNhc9Sv8FFqpByxgGJjeDCiPbIPAuRWewBn9jTs2oUGBEnkdU+nfPJbZtIWkrxXaln88/EBUnmA0jg7OwNtJl8Qx7xq41lFJrk+OB93/g+3n+JWdxoreWuB8a46oY3FuJQLuinbcWs0XBaqJxukq3/o0C/oxg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AFAC4BA2E07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768576168; 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=jy8Izf4LNdtq40Awto008MO/uh8M68XY0P9HYpeZOJM=; b=ECtjaJv6TYsYFchgPtBQTlzSvW3TuAce5U5aM59hW+t37xopIPcCBEr/yovxyRu3o03xWr sn1l7nCHrqRz9yYbMdIvI7xAexa+rjeVbJ6gnDKNZI0EN2rWY8rNL5g7Ss0IQaQsTeLT9W bFHpOafFhni6fs7Y7F0dkD+RVOuLGSY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-3qDZRxTAOv24QMafZmLCzw-1; Fri, 16 Jan 2026 10:09:27 -0500 X-MC-Unique: 3qDZRxTAOv24QMafZmLCzw-1 X-Mimecast-MFC-AGG-ID: 3qDZRxTAOv24QMafZmLCzw_1768576166 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4310062d97bso1373957f8f.0 for ; Fri, 16 Jan 2026 07:09:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768576166; x=1769180966; 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=jy8Izf4LNdtq40Awto008MO/uh8M68XY0P9HYpeZOJM=; b=BkzGtu73Yk0r0dnXDXsRvbGTCq4U9mBJ8SPfI+6okbYAR8J0RuFlHSntPUnnbiBc+z VrXMXqwtE+uWl3RfCc4ZurrReeejGXoJo/eOQCUFEMOkX8NBrp1Tk70Qcvcjxi79lGhT cb9JKB2XG+KHgSS4OZVqoNUOfFVOe6CTEpfYZNkYvuZ9RSLP3DpH+elgY83DPK1RwaKl wktEjoRaTbMcynpcBfG2v3NUPJzHCROR+rukVoU9ErD7txsztcPJt2HbtOCDmQW9bmSm xJhZkK8FlPkeXmgsGUH2KpC0fBXku2ZQk3L4Ke7dKXXd+u1gjG8DwjyHAs6M0jBGvh45 yCDg== X-Gm-Message-State: AOJu0Yxz638EHa/5wzjmtoE2kpkH8XepuHWHpcZoi9O6nFUgU7v0BEdt LUt4ZPTWX/b1CJfLXK4MgDej/vQ+vOEOIaTa5ckXPyVDEBXr6lYlkIp/Qy2Rx7ALA3hEbGHMlJ1 wltSRScg0rSKJ/S5m+u3G7YR/MS8VGiwal01xDRDvLyY5vnS0rDqoK4ugb0LAJ8lZikDXdxj/ua rxm73xwq5jnWMM2q2EP2zr3RPuIjAoRKid+P5etDXo2g== X-Gm-Gg: AY/fxX6m6n759mxpDuSosEvb8fGRg+6LjP+pUIvz2Yyx99gcuc3nzICoWrox398Achh ESiByWBB84jIT7HpLm2Zf0yG2ogAeSO7WfZvtnsOi09Nvv41rrxu1wpqD5GnrjEv2DaYOSptf9V tZ/GVKDJqTjt5Rg6PepIsFqOLd9ZK05ujkMl2fyq6jSizwg6q8zjJ4MOdhoIkUw8OPcMe+/k/VN L4evBaAoa49h4Q9TGLBoqLvm8D8ya7Pi+XjSiZa7BwhjPnWawbaojyw+aXJQlK3yDYhsjdNkTnf qFeG0KppZgLTxK9AAM5WRZTaoshjOViy3bFbT03HH5HPxqUy+lTYJiwVa1ZNjjxdZpFajLX1Esx RZ/RUg0kf2j1VynkN6f1qXp31sdmRBJVcbKdMZg== X-Received: by 2002:a05:6000:1a8a:b0:42f:bb08:d1f0 with SMTP id ffacd0b85a97d-4356a0720bamr3842227f8f.60.1768576166098; Fri, 16 Jan 2026 07:09:26 -0800 (PST) X-Received: by 2002:a05:6000:1a8a:b0:42f:bb08:d1f0 with SMTP id ffacd0b85a97d-4356a0720bamr3842181f8f.60.1768576165628; Fri, 16 Jan 2026 07:09:25 -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-4356992c6f2sm5947370f8f.19.2026.01.16.07.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jan 2026 07:09:25 -0800 (PST) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Florian Weimer , Arjun Shankar Subject: [PATCH v2] dlfcn: Add dlinfo request type RTLD_DI_ORIGIN_PATH (bug #24298) Date: Fri, 16 Jan 2026 16:04:23 +0100 Message-ID: <20260116150921.3841139-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: tHiUugjig00VHITSiRny-sEjpYMepVSibW0zkX-ekuo_1768576166 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_NONE, RCVD_IN_MSPIKE_H2, 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: Florian Weimer --- v1: https://inbox.sourceware.org/libc-alpha/20260116141039.3823661-1-arjun@redhat.com/ Changes in v2: Addressed Florian's review comments on the manual change: * Mention that the function returns 0 even when the result is NULL. * Recommend RTLD_DI_ORIGIN_PATH in the description of RTLD_DI_ORIGIN. --- dlfcn/dlfcn.h | 7 ++++++- dlfcn/dlinfo.c | 7 +++++++ dlfcn/tst-dlinfo.c | 8 ++++++++ manual/dynlink.texi | 9 ++++++++- 4 files changed, 29 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..8ba18c8d2b 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -554,13 +554,20 @@ 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}}. + @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