From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id 8E6A5393BC0C; Mon, 28 Jun 2021 06:34:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E6A5393BC0C Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] elf: Generalize name-based DSO recognition in ldconfig X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/master X-Git-Oldrev: b89d5de2508215ef3131db7bed76ac50b3f4c205 X-Git-Newrev: 6bf789d69e6be48419094ca98f064e00297a27d5 Message-Id: <20210628063424.8E6A5393BC0C@sourceware.org> Date: Mon, 28 Jun 2021 06:34:24 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2021 06:34:24 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6bf789d69e6be48419094ca98f064e00297a27d5 commit 6bf789d69e6be48419094ca98f064e00297a27d5 Author: Florian Weimer Date: Mon Jun 28 08:33:57 2021 +0200 elf: Generalize name-based DSO recognition in ldconfig This introduces and the _dl_is_dso function. A test ensures that the official names of libc.so, ld.so, and their versioned names are recognized. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell Diff: --- elf/Makefile | 3 ++- elf/dl-is_dso.h | 33 +++++++++++++++++++++++++++++++++ elf/ldconfig.c | 5 ++--- elf/tst-dl-is_dso.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 38d08e03b8..62f7e8a225 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -223,7 +223,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-single_threaded tst-single_threaded-pthread \ tst-tls-ie tst-tls-ie-dlmopen argv0test \ tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ - tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dlmopen-gethostbyname + tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dlmopen-gethostbyname \ + tst-dl-is_dso # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ diff --git a/elf/dl-is_dso.h b/elf/dl-is_dso.h new file mode 100644 index 0000000000..94e00966a1 --- /dev/null +++ b/elf/dl-is_dso.h @@ -0,0 +1,33 @@ +/* Heuristic for recognizing DSO file names. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* Returns true if the file name looks like a DSO name. */ +static bool +_dl_is_dso (const char *name) +{ + /* Recognize lib*.so*, ld-*.so*, ld.so.*, ld64.so.*. ld-*.so* + matches both platform dynamic linker names like ld-linux.so.2, + and versioned dynamic loader names like ld-2.12.so. */ + return (((strncmp (name, "lib", 3) == 0 || strncmp (name, "ld-", 3) == 0) + && strstr (name, ".so") != NULL) + || strncmp (name, "ld.so.", 6) == 0 + || strncmp (name, "ld64.so.", 8) == 0); +} diff --git a/elf/ldconfig.c b/elf/ldconfig.c index 96bf7700b2..1037e8d0cf 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -842,9 +843,7 @@ search_dir (const struct dir_entry *entry) subdirectory (if not already processing a glibc-hwcaps subdirectory)? The dynamic linker is also considered as shared library. */ - if (((strncmp (direntry->d_name, "lib", 3) != 0 - && strncmp (direntry->d_name, "ld-", 3) != 0) - || strstr (direntry->d_name, ".so") == NULL) + if (!_dl_is_dso (direntry->d_name) && (direntry->d_type == DT_REG || (entry->hwcaps == NULL && !is_hwcap_platform (direntry->d_name)))) diff --git a/elf/tst-dl-is_dso.c b/elf/tst-dl-is_dso.c new file mode 100644 index 0000000000..48d2cc9fbe --- /dev/null +++ b/elf/tst-dl-is_dso.c @@ -0,0 +1,35 @@ +/* Test heuristic for recognizing DSO file names. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +static int +do_test (void) +{ + /* Official ABI names. */ + TEST_VERIFY (_dl_is_dso (LIBC_SO)); + TEST_VERIFY (_dl_is_dso (LD_SO)); + /* Version-based names. The version number does not matter. */ + TEST_VERIFY (_dl_is_dso ("libc-2.12.so")); + TEST_VERIFY (_dl_is_dso ("ld-2.12.so")); + return 0; +} + +#include