From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_HI,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 138B11F8C6 for ; Tue, 6 Jul 2021 10:23:12 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48D2E383540B for ; Tue, 6 Jul 2021 10:23:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48D2E383540B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625566991; bh=Rmrca0lxi/4P5RnvldEGLhnwMErkRZzlVxGZvq2G/r0=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=m+eArvDaKxAqXn6V9uIKND7QzZphk8keqU1XA9rx8f5V13GQwQ2wnSajg8gKZENmz UQ7Og8ZsgCIEg++Ege73KiQhLzKj757E0afjZ+wcGbT8a/RHCnYSknNKK90OdmcWOK E/WttQ2MaljATuAzINdLo1ULtiR7QZ7sAH0uspnE= Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 00C1B382C417 for ; Tue, 6 Jul 2021 10:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00C1B382C417 Received: by mail-yb1-xb49.google.com with SMTP id 132-20020a25158a0000b029055791ebe1e6so26929186ybv.20 for ; Tue, 06 Jul 2021 03:22:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Rmrca0lxi/4P5RnvldEGLhnwMErkRZzlVxGZvq2G/r0=; b=QMSFOfKqQqm2iFCfOyLfFzfexqLRwvM+vIcICLJwX2g/1n83H5haRdJ5xomTI66W5D BIjGiratq+LJkrcqVig5cdAJJ9cLsqSqquOn2qtwZCZ/c8G8b8zZ7V58bCQAYAeqQzwX EIJJ+PhetuW0jaDKhk8irUiWdlX+BXu1ZX/yYxM7wwTzNMy8lytUwVmteLN/d34Zqfif r3PmzWoY4i0V/zuS+mFHPB/c9HS/aoxPks/e1gbxmdQPq43KNMP2nXYOiAqUyyTGd+Ym 52UTer/ezJDU2GegE9wm0wFWo7VFIvCM+CdT7QIofWKmMH5pJU46ClRnEEL3q1GHtJ72 k5hA== X-Gm-Message-State: AOAM530yLIl0Idzbkt6vvZQohXMdcVyD5ZWyjaWHNGb8lZh5n3WyN7C8 mwUCZ1h/0P8d+pdgk75csg/UAsMDCjAkc5CDffg0OibKNuM8PYs4JhLBS9Xvn9LAa0NU23aUmbE jvFSRNSg6MZusLfjy0nDPizf6iiSuMbSSMknWAXILWgTRvgBsvLPp8+N6qQXU9A0DxYR/JmM= X-Google-Smtp-Source: ABdhPJx/ekasN4TNrUS2fpTQvBje0cQG7PEInqJxI267GyQFzC2wLqh/z5PwukEtIoTFgZ7YIlgY98VMmJFQ7g== X-Received: from sidereal.syd.corp.google.com ([2401:fa00:9:14:5de5:2842:4686:770d]) (user=sidereal job=sendgmr) by 2002:a25:ff11:: with SMTP id c17mr22906510ybe.9.1625566955444; Tue, 06 Jul 2021 03:22:35 -0700 (PDT) Date: Tue, 6 Jul 2021 20:21:31 +1000 In-Reply-To: <20210706102132.2170854-1-sidereal@google.com> Message-Id: <20210706102132.2170854-2-sidereal@google.com> Mime-Version: 1.0 References: <20210706102132.2170854-1-sidereal@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v4 1/2] rtld: Add --no-default-paths option To: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" 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: , From: Fergus Dall via Libc-alpha Reply-To: Fergus Dall Cc: fweimer@redhat.com, chromeos-toolchain@google.com, clumptini@google.com, Fergus Dall , joseph@codesourcery.com Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" This option causes the default library search path to be skipped, using only the paths in DT_RPATH, LD_LIBRARY_PATH, and DT_RUNPATH. This option implies --inhibit-cache, as there is no point in searching a cache of system libraries when we are not using the system libraries at all. This is necessary to preserve negative search results when isolating applications from the system libraries. This can be important when an application uses dlopen at run time to load optional libraries. When a shared library is required by the application, it can be isolated by putting appropriate versions of the libraries in directories specified in LD_LIBRARY_PATH, because the library search will always terminate before potentially loading any system libraries. On the other hand, if the application should be run without an optional library, the search will proceed past the LD_LIBRARY_PATH directories into the default system libraries, potentially causing an incorrect library to be linked. --- NEWS | 4 ++++ elf/dl-load.c | 6 ++++-- elf/dl-support.c | 2 ++ elf/dl-usage.c | 2 ++ elf/rtld.c | 10 ++++++++++ sysdeps/generic/ldsodefs.h | 3 +++ 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 8e72946c3f..790034d837 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,10 @@ Major new features: to call async-signal-safe functions (such as raise or execve). This function is currently a GNU extension. +* The dynamic linker has gained the --no-default-paths option, which + causes it to ignore libraries in the default (compiled in) system + paths even if all higher precedence locations have been searched. + Deprecated and removed features, and other changes affecting compatibility: * The function pthread_mutex_consistent_np has been deprecated; programs diff --git a/elf/dl-load.c b/elf/dl-load.c index a08df001af..0a14cbb87c 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2258,7 +2258,8 @@ _dl_map_object (struct link_map *loader, const char *name, if (fd == -1 && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB))) - && __rtld_search_dirs.dirs != (void *) -1) + && __rtld_search_dirs.dirs != (void *) -1 + && __glibc_likely (GLRO(dl_search_default_paths))) fd = open_path (name, namelen, mode, &__rtld_search_dirs, &realname, &fb, l, LA_SER_DEFAULT, &found_other_class); @@ -2438,7 +2439,8 @@ _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting) a way to indicate that in the results for Dl_serinfo. */ /* Finally, try the default path. */ - if (!(loader->l_flags_1 & DF_1_NODEFLIB)) + if (!(loader->l_flags_1 & DF_1_NODEFLIB) + && __glibc_likely (GLRO(dl_search_default_paths))) add_path (&p, &__rtld_search_dirs, XXX_default); if (counting) diff --git a/elf/dl-support.c b/elf/dl-support.c index dfc9ab760e..def75550aa 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -144,6 +144,8 @@ size_t _dl_minsigstacksize = CONSTANT_MINSIGSTKSZ; int _dl_inhibit_cache; +int _dl_search_default_paths; + unsigned int _dl_osversion; /* All known directories in sorted order. */ diff --git a/elf/dl-usage.c b/elf/dl-usage.c index 5ad3a72559..b5ae44932a 100644 --- a/elf/dl-usage.c +++ b/elf/dl-usage.c @@ -247,6 +247,8 @@ setting environment variables (which would be inherited by subprocesses).\n\ --inhibit-cache Do not use " LD_SO_CACHE "\n\ --library-path PATH use given PATH instead of content of the environment\n\ variable LD_LIBRARY_PATH\n\ + --no-default-paths do not use the default library search path\n\ + (this option implies --inhibit-cache)\n\ --glibc-hwcaps-prepend LIST\n\ search glibc-hwcaps subdirectories in LIST\n\ --glibc-hwcaps-mask LIST\n\ diff --git a/elf/rtld.c b/elf/rtld.c index fbbd60b446..8eb76b8998 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -360,6 +360,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro = ._dl_fpu_control = _FPU_DEFAULT, ._dl_pagesize = EXEC_PAGESIZE, ._dl_inhibit_cache = 0, + ._dl_search_default_paths = 1, /* Function pointers. */ ._dl_debug_printf = _dl_debug_printf, @@ -1204,6 +1205,15 @@ dl_main (const ElfW(Phdr) *phdr, _dl_argc -= 2; _dl_argv += 2; } + else if (! strcmp (_dl_argv[1], "--no-default-paths")) + { + GLRO(dl_search_default_paths) = 0; + GLRO(dl_inhibit_cache) = 1; + + ++_dl_skip_args; + --_dl_argc; + ++_dl_argv; + } else if (! strcmp (_dl_argv[1], "--inhibit-rpath") && _dl_argc > 2) { diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 176394de4d..d7c9b9e477 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -551,6 +551,9 @@ struct rtld_global_ro /* Do we read from ld.so.cache? */ EXTERN int _dl_inhibit_cache; + /* Do we search the default system paths? */ + EXTERN int _dl_search_default_paths; + /* Copy of the content of `_dl_main_searchlist' at startup time. */ EXTERN struct r_scope_elem _dl_initial_searchlist; -- 2.32.0.93.g670b81a890-goog