From patchwork Wed Jun 9 11:16:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 43781 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 161023971C3C for ; Wed, 9 Jun 2021 11:18:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 161023971C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623237499; bh=+zdVhTc446kr4gKThi/Qj6ldRjE7CbmEar1C0hQ765M=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lDY3VZ+8qokN7Me+XqBH/YAbLzJj5h8sEywMl3xeSMT+pnJ6sCflY3nwKDHcleBYY iWOstQAjs0YesWB8rhCzaYMh58U/wCQ394QCrBa6HCQaJyaTUbETpRApA6ccVc2OHp 6l51LDvJMRJTE+sNVATm4mKqJ9tBcoux8PPT9xWw= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 421B6395C826 for ; Wed, 9 Jun 2021 11:16:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 421B6395C826 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-w6s-s1AMM4a6d8QruzwYwg-1; Wed, 09 Jun 2021 07:16:16 -0400 X-MC-Unique: w6s-s1AMM4a6d8QruzwYwg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50A811850608 for ; Wed, 9 Jun 2021 11:16:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 715FF17C5F for ; Wed, 9 Jun 2021 11:16:14 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 3/4] elf: Generalize name-based DSO recognition in ldconfig In-Reply-To: References: X-From-Line: 937116e1b6e669fa0d679bf677ceefd145735e9c Mon Sep 17 00:00:00 2001 Message-Id: <937116e1b6e669fa0d679bf677ceefd145735e9c.1623237082.git.fweimer@redhat.com> Date: Wed, 09 Jun 2021 13:16:12 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- elf/Makefile | 2 +- elf/dl-is_dso.h | 33 +++++++++++++++++++++++++++++++++ elf/ldconfig.c | 5 ++--- elf/tst-dl-is_dso.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 elf/dl-is_dso.h create mode 100644 elf/tst-dl-is_dso.c diff --git a/elf/Makefile b/elf/Makefile index e9788d3d4f..5389c35536 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -223,7 +223,7 @@ 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-tls20 tst-tls21 tst-dlmopen-dlerror 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