Skip to contentSkip to conversation

nfsd: only set NFSD_MAY_BYPASS_GSS for RPC_AUTH_UNIX in nlm_fopen()

PATCH In review Dominik Maier 3 participants 3 messages Nov 19 – Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsd: only set NFSD_MAY_BYPASS_GSS for RPC_AUTH_UNIX in nlm_fopen()

As documented in nlm_fopen(), NFSD_MAY_BYPASS_GSS is intended to let NLM clients using AUTH_SYS (RPC_AUTH_UNIX) lock files on Kerberos NFS exports, whereas NLM clients using AUTH_NULL (RPC_AUTH_NULL) are only meant to bypass authentication when NFSEXP_NOAUTHNLM (no_auth_nlm) is enabled via NFSD_MAY_NLM.

However, nlm_fopen() has historically passed NFSD_MAY_BYPASS_GSS unconditionally, and check_security_flavor() accepts both RPC_AUTH_UNIX and RPC_AUTH_NULL whenever may_bypass_gss is true on an export with a pseudoflavor >= RPC_AUTH_DES. Since commit bb4f07f2409c ("nfsd: Fix NFSD_MAY_BYPASS_GSS and NFSD_MAY_BYPASS_GSS_ON_ROOT") restricted may_bypass_gss to exports with pseudoflavor >= RPC_AUTH_DES, default auth_nlm rejects RPC_AUTH_NULL NLM requests on sec=sys exports with nfserr_wrongsec while still accepting RPC_AUTH_NULL NLM requests on sec=krb5* exports even when no_auth_nlm is not set.

Only set NFSD_MAY_BYPASS_GSS in nlm_fopen() when rq_cred.cr_flavor is RPC_AUTH_UNIX so auth_nlm and no_auth_nlm behave consistently across sec=sys and GSS exports, requiring no_auth_nlm or an explicit sec=none export flavor for RPC_AUTH_NULL NLM requests.

This issue was discovered by an AI-assisted code review tool (ARTIST), validated in QEMU against an unmodified v7.4-rc3 kernel without kernel modifications or error injection, build-tested with KCFLAGS=-Werror, and checked with checkpatch.pl --strict.

---
 fs/nfsd/lockd.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/nfsd/lockd.c +5 -3
index f24e45d..2683939 100644
@@ -41,8 +41,8 @@ static int nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f,
 	fh.fh_export = NULL;
 
 	/*
-	 * Allow BYPASS_GSS as some client implementations use AUTH_SYS
-	 * for NLM even when GSS is used for NFS.
+	 * Allow BYPASS_GSS for AUTH_SYS as some client implementations use
+	 * AUTH_SYS for NLM even when GSS is used for NFS.
 	 * Allow OWNER_OVERRIDE as permission might have been changed
 	 * after the file was opened.
 	 * Pass MAY_NLM so that authentication can be completely bypassed
@@ -50,7 +50,9 @@ static int nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f,
 	 * for NLM requests.
 	 */
 	access = (flags == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
-	access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_BYPASS_GSS;
+	access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE;
+	if (rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
+		access |= NFSD_MAY_BYPASS_GSS;
 	nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
 	fh_put(&fh);
 
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Dominik Maier

As documented in nlm_fopen(), NFSD_MAY_BYPASS_GSS is intended to let NLM clients using AUTH_SYS (RPC_AUTH_UNIX) lock files on Kerberos NFS exports, whereas NLM clients using AUTH_NULL (RPC_AUTH_NULL) are only meant to bypass authentication when NFSEXP_NOAUTHNLM (no_auth_nlm) is enabled via NFSD_MAY_NLM.

However, nlm_fopen() has historically passed NFSD_MAY_BYPASS_GSS unconditionally, and check_security_flavor() accepts both RPC_AUTH_UNIX and RPC_AUTH_NULL whenever may_bypass_gss is true on an export with a pseudoflavor >= RPC_AUTH_DES. Since commit bb4f07f2409c ("nfsd: Fix NFSD_MAY_BYPASS_GSS and NFSD_MAY_BYPASS_GSS_ON_ROOT") restricted may_bypass_gss to exports with pseudoflavor >= RPC_AUTH_DES, default auth_nlm rejects RPC_AUTH_NULL NLM requests on sec=sys exports with nfserr_wrongsec while still accepting RPC_AUTH_NULL NLM requests on sec=krb5* exports even when no_auth_nlm is not set.

Only set NFSD_MAY_BYPASS_GSS in nlm_fopen() when rq_cred.cr_flavor is RPC_AUTH_UNIX so auth_nlm and no_auth_nlm behave consistently across sec=sys and GSS exports, requiring no_auth_nlm or an explicit sec=none export flavor for RPC_AUTH_NULL NLM requests.

Quoted 5 lines

This issue was discovered by an AI-assisted code review tool (ARTIST), validated in QEMU against an unmodified v7.4-rc3 kernel without kernel modifications or error injection, build-tested with KCFLAGS=-Werror, and checked with checkpatch.pl --strict.

Sashiko suggests:

Fixes 4cc9b9f2bf4d ("nfsd: refine and rename NFSD_MAY_LOCK")
Quoted 21 lines
---
 fs/nfsd/lockd.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/nfsd/lockd.c +2 -2
index f24e45d..2683939 100644
@@ -41,8 +41,8 @@ static int nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f,
 	fh.fh_export = NULL;
 
 	/*
-	 * Allow BYPASS_GSS as some client implementations use AUTH_SYS
-	 * for NLM even when GSS is used for NFS.
+	 * Allow BYPASS_GSS for AUTH_SYS as some client implementations use
+	 * AUTH_SYS for NLM even when GSS is used for NFS.
 	 * Allow OWNER_OVERRIDE as permission might have been changed
 	 * after the file was opened.
 	 * Pass MAY_NLM so that authentication can be completely bypassed

fs/nfsd/lockd.c static int nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, · line 58

Quoted 10 lines
fs/nfsd/lockd.c +3 -1
@@ -50,7 +50,9 @@ static int nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f,
 	 * for NLM requests.
 	 */
 	access = (flags == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
-	access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_BYPASS_GSS;
+	access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE;
+	if (rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
+		access |= NFSD_MAY_BYPASS_GSS;
 	nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
 	fh_put(&fh);
 
maintainer
#2 lore raw
In reply to Dominik Maier
Quoted 16 lines · Dominik Maier

As documented in nlm_fopen(), NFSD_MAY_BYPASS_GSS is intended to let NLM clients using AUTH_SYS (RPC_AUTH_UNIX) lock files on Kerberos NFS exports, whereas NLM clients using AUTH_NULL (RPC_AUTH_NULL) are only meant to bypass authentication when NFSEXP_NOAUTHNLM (no_auth_nlm) is enabled via NFSD_MAY_NLM.

However, nlm_fopen() has historically passed NFSD_MAY_BYPASS_GSS unconditionally, and check_security_flavor() accepts both RPC_AUTH_UNIX and RPC_AUTH_NULL whenever may_bypass_gss is true on an export with a pseudoflavor >= RPC_AUTH_DES. Since commit bb4f07f2409c ("nfsd: Fix NFSD_MAY_BYPASS_GSS and NFSD_MAY_BYPASS_GSS_ON_ROOT") restricted may_bypass_gss to exports with pseudoflavor >= RPC_AUTH_DES, default auth_nlm rejects RPC_AUTH_NULL NLM requests on sec=sys exports with nfserr_wrongsec while still accepting RPC_AUTH_NULL NLM requests on sec=krb5* exports even when no_auth_nlm is not set.

Quoted 1 line

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: only set NFSD_MAY_BYPASS_GSS for RPC_AUTH_UNIX in nlm_fopen()

      commit: 824294e1f20b5dbd8420e77ddb3da230150f96c1

--
Chuck Lever <[email protected]>