From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2130) id 4E2A238418B1; Tue, 14 Jun 2022 02:58:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E2A238418B1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: DJ Delorie To: glibc-cvs@sourceware.org Subject: [glibc/release/2.34/master] nss: handle stat failure in check_reload_and_get (BZ #28752) X-Act-Checkin: glibc X-Git-Author: Sam James X-Git-Refname: refs/heads/release/2.34/master X-Git-Oldrev: 368c5c3e001a37571b61ab342f2b654c3d23643d X-Git-Newrev: 94ab2088c37d8e4285354af120b7ed6b887b9e53 Message-Id: <20220614025858.4E2A238418B1@sourceware.org> Date: Tue, 14 Jun 2022 02:58:58 +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: Tue, 14 Jun 2022 02:58:58 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=94ab2088c37d8e4285354af120b7ed6b887b9e53 commit 94ab2088c37d8e4285354af120b7ed6b887b9e53 Author: Sam James Date: Sun Jun 5 04:57:10 2022 +0100 nss: handle stat failure in check_reload_and_get (BZ #28752) Skip the chroot test if the database isn't loaded correctly (because the chroot test uses some existing DB state). The __stat64_time64 -> fstatat call can fail if running under an (aggressive) seccomp filter, like Firefox seems to use. This manifested in a crash when using glib built with FAM support with such a Firefox build. Suggested-by: DJ Delorie Signed-off-by: Sam James Reviewed-by: DJ Delorie (cherry picked from commit ace9e3edbca62d978b1e8f392d8a5d78500272d9) Diff: --- nss/nss_database.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/nss/nss_database.c b/nss/nss_database.c index 54561f0328..e807e9d84c 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -420,23 +420,32 @@ nss_database_check_reload_and_get (struct nss_database_state *local, return true; } - /* Before we reload, verify that "/" hasn't changed. We assume that - errors here are very unlikely, but the chance that we're entering - a container is also very unlikely, so we err on the side of both - very unlikely things not happening at the same time. */ - if (__stat64_time64 ("/", &str) != 0 - || (local->root_ino != 0 - && (str.st_ino != local->root_ino - || str.st_dev != local->root_dev))) + int stat_rv = __stat64_time64 ("/", &str); + + if (local->data.services[database_index] != NULL) { - /* 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); - return true; + /* Before we reload, verify that "/" hasn't changed. We assume that + errors here are very unlikely, but the chance that we're entering + a container is also very unlikely, so we err on the side of both + very unlikely things not happening at the same time. */ + if (stat_rv != 0 + || (local->root_ino != 0 + && (str.st_ino != local->root_ino + || str.st_dev != local->root_dev))) + { + /* 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); + return true; + } + } + if (stat_rv == 0) + { + local->root_ino = str.st_ino; + local->root_dev = str.st_dev; } - local->root_ino = str.st_ino; - local->root_dev = str.st_dev; + __libc_lock_unlock (local->lock); /* Avoid overwriting the global configuration until we have loaded