public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] nsswitch: actually return the result when nss database is being locked
@ 2021-02-05  7:32 slyich
  2021-02-05 18:45 ` DJ Delorie
  0 siblings, 1 reply; 2+ messages in thread
From: slyich @ 2021-02-05  7:32 UTC (permalink / raw)
  To: libc-alpha, Carlos O'Donell, DJ Delorie; +Cc: Sergei Trofimovich

From: Sergei Trofimovich <slyfox@gentoo.org>

https://sourceware.org/bugzilla/show_bug.cgi?id=27343

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);
}
```
---
 nss/nss_database.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nsswitch: actually return the result when nss database is being locked
  2021-02-05  7:32 [PATCH] nsswitch: actually return the result when nss database is being locked slyich
@ 2021-02-05 18:45 ` DJ Delorie
  0 siblings, 0 replies; 2+ messages in thread
From: DJ Delorie @ 2021-02-05 18:45 UTC (permalink / raw)
  To: slyich; +Cc: libc-alpha, carlos, slyfox


slyich@gmail.com writes:
> -      /* 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];

LGTM although I tweaked the patch subject for length.  Committed.
Thanks!

Reviewed-by: DJ Delorie <dj@redhat.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-05 18:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05  7:32 [PATCH] nsswitch: actually return the result when nss database is being locked slyich
2021-02-05 18:45 ` DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).