[PATCH] dlfcn: Deprecate dlinfo request type RTLD_DI_ORIGIN (bug #24298)

Arjun Shankar arjun@redhat.com
Mon Jan 26 16:15:40 GMT 2026


Commit b52619f2e8bbae57d79c95538346198c4a9f24a6 added a new dlinfo
request type, RTLD_DI_ORIGIN_PATH, to be used instead of the buffer
overflow prone RTLD_DI_ORIGIN.  With a replacement available,
RTLD_DI_ORIGIN can now be deprecated.

This commit deprecates RTLD_DI_ORIGIN by adding a compile time warning
upon its use, and documents the deprecation in the manual.
---
This patch comes out of the discussion linked below:
https://inbox.sourceware.org/libc-alpha/CAG_osaYR1aMgxzumCT8hCUGe=EYDVrvjSReAXsMEg0eyU=mZDw@mail.gmail.com/

Apparently, GCC supports deprecating enumerators since GCC 6:
https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Enumerator-Attributes.html#Enumerator-Attributes
---
 dlfcn/dlfcn.h       | 7 +++++--
 dlfcn/dlinfo.c      | 7 +++++++
 dlfcn/tst-dlinfo.c  | 4 ++++
 manual/dynlink.texi | 6 +++---
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index a73303a17e..8588572bca 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -145,8 +145,11 @@ enum
     RTLD_DI_SERINFOSIZE = 5,
 
     /* Treat ARG as `char *', and store there the directory name used to
-       expand $ORIGIN in this shared object's dependency file names.  */
-    RTLD_DI_ORIGIN = 6,
+       expand $ORIGIN in this shared object's dependency file names.
+       Deprecated due to potential for buffer overflows.  */
+    RTLD_DI_ORIGIN
+      __attribute_deprecated_msg__ ("Use RTLD_DI_ORIGIN_PATH instead")
+      = 6,
 
     RTLD_DI_PROFILENAME = 7,	/* Unsupported, defined by Solaris.  */
     RTLD_DI_PROFILEOUT = 8,	/* Unsupported, defined by Solaris.  */
diff --git a/dlfcn/dlinfo.c b/dlfcn/dlinfo.c
index a4c6ffb5b8..a97c1a5791 100644
--- a/dlfcn/dlinfo.c
+++ b/dlfcn/dlinfo.c
@@ -63,7 +63,14 @@ dlinfo_doit (void *argsblock)
       _dl_rtld_di_serinfo (l, args->arg, true);
       break;
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
+    /* Deprecated via compile time warning due to buffer overflow risk.  */
     case RTLD_DI_ORIGIN:
+
+#pragma GCC diagnostic pop
+
       strcpy (args->arg, l->l_origin);
       break;
 
diff --git a/dlfcn/tst-dlinfo.c b/dlfcn/tst-dlinfo.c
index d0c8d8fb6d..87d584fbb0 100644
--- a/dlfcn/tst-dlinfo.c
+++ b/dlfcn/tst-dlinfo.c
@@ -52,7 +52,11 @@ do_test (void)
     }
 
   char origin[8192];		/* >= PATH_MAX, in theory */
+#pragma GCC diagnostic push
+/* Ignore deprecation to be able to test deprecated request type.  */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   TRY (RTLD_DI_ORIGIN, origin)
+#pragma GCC diagnostic push
     {
       printf ("origin: %s\n", origin);
     }
diff --git a/manual/dynlink.texi b/manual/dynlink.texi
index 1091d25a89..a41ad24407 100644
--- a/manual/dynlink.texi
+++ b/manual/dynlink.texi
@@ -568,9 +568,9 @@ 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.  Instead, @code{RTLD_DI_ORIGIN_PATH} described above should be
-used.
+This request type has been deprecated because it is prone to buffer
+overflows and should therefore not be used.  Instead,
+@code{RTLD_DI_ORIGIN_PATH} described above should be used.
 
 @item RTLD_DI_SERINFO
 @itemx RTLD_DI_SERINFOSIZE
-- 
2.52.0



More information about the Libc-alpha mailing list