The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sunrpc: treat empty auth.unix.gid replies as negative entries
@ 2026-08-14 17:25 Ameer Hamza
  2026-08-14 20:02 ` Chuck Lever
  0 siblings, 1 reply; 3+ messages in thread
From: Ameer Hamza @ 2026-08-14 17:25 UTC (permalink / raw)
  To: cel, jlayton, neil, okorniev, Dai.Ngo, tom
  Cc: linux-nfs, linux-kernel, alexander.motin, caleb.stjohn,
	ameer.hamza

When rpc.mountd cannot resolve a uid (getpwuid() or getgrouplist()
failure, e.g. while winbind or sssd is briefly unreachable), it
answers the auth.unix.gid upcall with zero groups. unix_gid_parse()
installs that as a valid positive entry, and svcauth_unix_set_client()
then replaces the credential's group list with the empty one on
every request, RPCSEC_GSS included via svcauth_gss_set_client().
One failed lookup strips that uid of all supplementary groups on
every export for up to mountd's configured TTL (30 minutes by
default), long after the NSS backend has recovered.

mountd cannot send an empty list for a successful lookup, since
getgrouplist(3) always includes at least the user's primary group,
so a zero-group reply can only mean the lookup failed. Record it as
a negative entry: unix_gid_find() then returns -ENOENT and
svcauth_unix_set_client() keeps the groups the RPC credential
already carries. This is the fallback that
commit 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a
gid list when using AUTH_UNIX authentication") promised when no
answer is available, and the same state try_to_negate_entry()
already creates when no listener holds the channel open.

Fixes: 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a gid list when using AUTH_UNIX authentication")
Assisted-by: Claude:claude-fable-5
Signed-off-by: Ameer Hamza <ameer.hamza@truenas.com>
---
Reproducer (any server with rpc.mountd --manage-gids; 'alice' is a
member of group 'proj' *supplementary*, /srv/proj is root:proj 0750):

    runuser -u alice -- cat /mnt/proj/data          # ok
    # the reply mountd sends when getpwuid()/getgrouplist() fail:
    echo "$(id -u alice) $(( $(date +%s) + 600 )) 0" \
        > /proc/net/rpc/auth.unix.gid/channel
    runuser -u alice -- cat /mnt/proj/data          # EACCES until
                                                    # refresh/flush/expiry

Applies unmodified (fuzz 0) to every maintained stable tree, 5.10.y
through 7.1.y. Tested on a live 6.12-based server over NFSv3 and
v4.0-v4.2, with sec=sys and sec=krb5.

 net/sunrpc/svcauth_unix.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index aebd97e7f66c7..2f592ba54a366 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -540,6 +540,13 @@ static int unix_gid_parse(struct cache_detail *cd,
 	if (ugp) {
 		struct cache_head *ch;
 		ug.h.flags = 0;
+		/*
+		 * mountd sends at least the user's primary group on
+		 * success, so an empty list can only mean the lookup
+		 * failed. Keep the credential's own groups instead.
+		 */
+		if (gids == 0)
+			set_bit(CACHE_NEGATIVE, &ug.h.flags);
 		ug.h.expiry_time = expiry;
 		ch = sunrpc_cache_update(cd,
 					 &ug.h, &ugp->h,

base-commit: 46db3c8a1be96a354758b44b1d4fbb4b70d09a20
-- 
2.53.0


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

* Re: [PATCH] sunrpc: treat empty auth.unix.gid replies as negative entries
  2026-08-14 17:25 [PATCH] sunrpc: treat empty auth.unix.gid replies as negative entries Ameer Hamza
@ 2026-08-14 20:02 ` Chuck Lever
  2026-08-14 20:34   ` Ameer Hamza
  0 siblings, 1 reply; 3+ messages in thread
From: Chuck Lever @ 2026-08-14 20:02 UTC (permalink / raw)
  To: Ameer Hamza, Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey
  Cc: linux-nfs, linux-kernel, alexander.motin, caleb.stjohn



On Fri, Aug 14, 2026, at 1:25 PM, Ameer Hamza wrote:
> When rpc.mountd cannot resolve a uid (getpwuid() or getgrouplist()
> failure, e.g. while winbind or sssd is briefly unreachable), it
> answers the auth.unix.gid upcall with zero groups. unix_gid_parse()
> installs that as a valid positive entry, and svcauth_unix_set_client()
> then replaces the credential's group list with the empty one on
> every request, RPCSEC_GSS included via svcauth_gss_set_client().
> One failed lookup strips that uid of all supplementary groups on
> every export for up to mountd's configured TTL (30 minutes by
> default), long after the NSS backend has recovered.
>
> mountd cannot send an empty list for a successful lookup, since
> getgrouplist(3) always includes at least the user's primary group,
> so a zero-group reply can only mean the lookup failed. Record it as
> a negative entry: unix_gid_find() then returns -ENOENT and
> svcauth_unix_set_client() keeps the groups the RPC credential
> already carries. This is the fallback that
> commit 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a
> gid list when using AUTH_UNIX authentication") promised when no
> answer is available, and the same state try_to_negate_entry()
> already creates when no listener holds the channel open.
>
> Fixes: 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a gid 
> list when using AUTH_UNIX authentication")
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Ameer Hamza <ameer.hamza@truenas.com>

Looks like the same bug exists for the new mountd netlink
mechanism. Since that instance of the bug arrived in a
different commit, that fix needs to be a separate patch
with its own Fixes: tag.

Can you make this a two-patch series?


-- 
Chuck Lever

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

* Re: [PATCH] sunrpc: treat empty auth.unix.gid replies as negative entries
  2026-08-14 20:02 ` Chuck Lever
@ 2026-08-14 20:34   ` Ameer Hamza
  0 siblings, 0 replies; 3+ messages in thread
From: Ameer Hamza @ 2026-08-14 20:34 UTC (permalink / raw)
  To: Chuck Lever
  Cc: Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	linux-nfs, linux-kernel, alexander.motin, caleb.stjohn

On Fri, Aug 14, 2026 at 04:02:23PM -0400, Chuck Lever wrote:
> 
> 
> On Fri, Aug 14, 2026, at 1:25 PM, Ameer Hamza wrote:
> > When rpc.mountd cannot resolve a uid (getpwuid() or getgrouplist()
> > failure, e.g. while winbind or sssd is briefly unreachable), it
> > answers the auth.unix.gid upcall with zero groups. unix_gid_parse()
> > installs that as a valid positive entry, and svcauth_unix_set_client()
> > then replaces the credential's group list with the empty one on
> > every request, RPCSEC_GSS included via svcauth_gss_set_client().
> > One failed lookup strips that uid of all supplementary groups on
> > every export for up to mountd's configured TTL (30 minutes by
> > default), long after the NSS backend has recovered.
> >
> > mountd cannot send an empty list for a successful lookup, since
> > getgrouplist(3) always includes at least the user's primary group,
> > so a zero-group reply can only mean the lookup failed. Record it as
> > a negative entry: unix_gid_find() then returns -ENOENT and
> > svcauth_unix_set_client() keeps the groups the RPC credential
> > already carries. This is the fallback that
> > commit 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a
> > gid list when using AUTH_UNIX authentication") promised when no
> > answer is available, and the same state try_to_negate_entry()
> > already creates when no listener holds the channel open.
> >
> > Fixes: 3fc605a2aa38 ("[PATCH] knfsd: allow the server to provide a gid 
> > list when using AUTH_UNIX authentication")
> > Assisted-by: Claude:claude-fable-5
> > Signed-off-by: Ameer Hamza <ameer.hamza@truenas.com>
> 
> Looks like the same bug exists for the new mountd netlink
> mechanism. Since that instance of the bug arrived in a
> different commit, that fix needs to be a separate patch
> with its own Fixes: tag.
> 
> Can you make this a two-patch series?
> 
> 
> -- 
> Chuck Lever

Sure, will send v2 with the netlink fix as a separate patch. Thanks for taking a look.

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

end of thread, other threads:[~2026-08-14 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 17:25 [PATCH] sunrpc: treat empty auth.unix.gid replies as negative entries Ameer Hamza
2026-08-14 20:02 ` Chuck Lever
2026-08-14 20:34   ` Ameer Hamza

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox