git: 2d20de9ffe4d - stable/14 - nfsuserd.c: Fix handling where pw_name/gr_name differ from lookup name

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Mon, 21 Sep 2026 01:50:17 UTC
The branch stable/14 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=2d20de9ffe4d59c523592b2558a998043b4b9ccb

commit 2d20de9ffe4d59c523592b2558a998043b4b9ccb
Author:     Emanuel Helms <emanuel@nrv.cc>
AuthorDate: 2026-09-07 19:50:58 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2026-09-21 01:48:27 +0000

    nfsuserd.c: Fix handling where pw_name/gr_name differ from lookup name
    
    When an NSS backend returns a canonical pw_name or gr_name that differs from
    the lookup name supplied by the NFSv4 upcall, nfsuserd stores the successful
    mapping in the kernel cache under the canonical name instead of the requested
    name.
    
    This causes the retry lookup performed by nfsv4_strtouid() or
    nfsv4_strtogid() to miss the newly inserted cache entry, resulting in the
    default UID/GID being returned although the NSS lookup itself succeeded.
    
    PR:     296753
    
    (cherry picked from commit 1771ab245c2341033f0cee3bd098c76888cf3515)
---
 usr.sbin/nfsuserd/nfsuserd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/nfsuserd/nfsuserd.c b/usr.sbin/nfsuserd/nfsuserd.c
index e5fd6fb18c81..e4c3480f8e7e 100644
--- a/usr.sbin/nfsuserd/nfsuserd.c
+++ b/usr.sbin/nfsuserd/nfsuserd.c
@@ -704,7 +704,8 @@ nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp)
 		if (pwd != NULL) {
 			nid.nid_usertimeout = defusertimeout;
 			nid.nid_uid = pwd->pw_uid;
-			nid.nid_name = pwd->pw_name;
+			/* NSS may canonicalize the name used for the lookup. */
+			nid.nid_name = info.name;
 		} else {
 			nid.nid_usertimeout = 5;
 			nid.nid_uid = defaultuid;
@@ -737,7 +738,8 @@ nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp)
 		if (grp != NULL) {
 			nid.nid_usertimeout = defusertimeout;
 			nid.nid_gid = grp->gr_gid;
-			nid.nid_name = grp->gr_name;
+			/* NSS may canonicalize the name used for the lookup. */
+			nid.nid_name = info.name;
 		} else {
 			nid.nid_usertimeout = 5;
 			nid.nid_gid = defaultgid;