From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 585FF3851C1C for ; Sat, 6 Feb 2021 05:10:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 585FF3851C1C 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-448--n017CVLOGadwrGt8Gtqgw-1; Sat, 06 Feb 2021 00:10:39 -0500 X-MC-Unique: -n017CVLOGadwrGt8Gtqgw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3E65801962 for ; Sat, 6 Feb 2021 05:10:38 +0000 (UTC) Received: from greed.delorie.com (ovpn-114-77.rdu2.redhat.com [10.10.114.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A086160C47 for ; Sat, 6 Feb 2021 05:10:38 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 1165AbGZ007212 for ; Sat, 6 Feb 2021 00:10:37 -0500 Date: Sat, 06 Feb 2021 00:10:37 -0500 Message-Id: From: DJ Delorie To: libc-stable@sourceware.org Subject: [COMMITTED 2.33] nsswitch: return result when nss database is locked [BZ #27343] X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Feb 2021 05:10:45 -0000 From: Sergei Trofimovich Subject: nsswitch: return result when nss database is locked [BZ #27343] (cherry picked from commit c3479fb7939898ec22c655c383454d6e8b982a67) Before the change nss_database_check_reload_and_get() did not populate the '*result' value when it returned success in a case of chroot detection. This caused initgroups() to use garage pointer in the following test (extracted from unbound): ``` int main() { // load some NSS modules struct passwd * pw = getpwnam("root"); chdir("/tmp"); chroot("/tmp"); chdir("/"); // access nsswitch.conf in a chroot initgroups("root", 0); } ``` Reviewed-by: DJ Delorie diff --git a/nss/nss_database.c b/nss/nss_database.c index cf0306adc4..e1bef6bd75 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -398,8 +398,9 @@ nss_database_check_reload_and_get (struct nss_database_state *local, && (str.st_ino != local->root_ino || str.st_dev != local->root_dev))) { - /* Change detected; disable reloading. */ + /* Change detected; disable reloading and return current state. */ atomic_store_release (&local->data.reload_disabled, 1); + *result = local->data.services[database_index]; __libc_lock_unlock (local->lock); __nss_module_disable_loading (); return true;