Skip to contentSkip to conversation

NFSD: Fix permission check for read access to executable-only files

PATCH In review Scott Mayhew 4 participants 4 messages Dec 11, 2025 – Dec 12, 2025

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

PATCH 1/1 NFSD: Fix permission check for read access to executable-only files

Commit abc02e5602f7 added NFSD_MAY_OWNER_OVERRIDE to the access flags passed from nfsd4_layoutget() to fh_verify(). This causes LAYOUTGET to fail for executable-only files, and causes xfstests generic/126 to fail on pNFS SCSI.

To allow read access to executable-only files, what we really want is:
1. The "permissions" portion of the access flags (the lower 6 bits) must be exactly NFSD_MAY_READ
2. The "hints" portion of the access flags (the upper 26 bits) can contain any combination of NFSD_MAY_OWNER_OVERRIDE and NFSD_MAY_READ_IF_EXEC

Fixes abc02e5602f7 ("NFSD: Support write delegations in LAYOUTGET")
---
 fs/nfsd/vfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +2 -2
index 964cf922ad83..168d3ccc8155 100644
@@ -2865,8 +2865,8 @@ nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
 
 	/* Allow read access to binaries even when mode 111 */
 	if (err == -EACCES && S_ISREG(inode->i_mode) &&
-	     (acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE) ||
-	      acc == (NFSD_MAY_READ | NFSD_MAY_READ_IF_EXEC)))
+	     (((acc & NFSD_MAY_MASK) == NFSD_MAY_READ) &&
+	      (acc & (NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_READ_IF_EXEC))))
 		err = inode_permission(&nop_mnt_idmap, inode, MAY_EXEC);
 
 	return err? nfserrno(err) : 0;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Scott Mayhew

Commit abc02e5602f7 added NFSD_MAY_OWNER_OVERRIDE to the access flags passed from nfsd4_layoutget() to fh_verify(). This causes LAYOUTGET to fail for executable-only files, and causes xfstests generic/126 to fail on pNFS SCSI.

To allow read access to executable-only files, what we really want is:
1. The "permissions" portion of the access flags (the lower 6 bits) must be exactly NFSD_MAY_READ
2. The "hints" portion of the access flags (the upper 26 bits) can contain any combination of NFSD_MAY_OWNER_OVERRIDE and NFSD_MAY_READ_IF_EXEC

Fixes abc02e5602f7 ("NFSD: Support write delegations in LAYOUTGET")
---
 fs/nfsd/vfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +0 -0
index 964cf922ad83..168d3ccc8155 100644

fs/nfsd/vfs.c nfsd_permission(struct svc_cred *cred, struct svc_export *exp, · line 2870

Quoted 8 lines
fs/nfsd/vfs.c +2 -2
@@ -2865,8 +2865,8 @@ nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
 
 	/* Allow read access to binaries even when mode 111 */
 	if (err == -EACCES && S_ISREG(inode->i_mode) &&
-	     (acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE) ||
-	      acc == (NFSD_MAY_READ | NFSD_MAY_READ_IF_EXEC)))
+	     (((acc & NFSD_MAY_MASK) == NFSD_MAY_READ) &&
+	      (acc & (NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_READ_IF_EXEC))))
 		err = inode_permission(&nop_mnt_idmap, inode, MAY_EXEC);

The new code is cleaner and more correct - thanks.

NeilBrown

Quoted 6 lines
fs/nfsd/vfs.c +0 -0
 	return err? nfserrno(err) : 0;
Signature · 1 line
2.51.0
maintainer Reviewed-by
#2 lore raw
Quoted 35 lines · NeilBrown
Quoted 23 lines · Scott Mayhew

Commit abc02e5602f7 added NFSD_MAY_OWNER_OVERRIDE to the access flags passed from nfsd4_layoutget() to fh_verify(). This causes LAYOUTGET to fail for executable-only files, and causes xfstests generic/126 to fail on pNFS SCSI.

To allow read access to executable-only files, what we really want is:
1. The "permissions" portion of the access flags (the lower 6 bits) must be exactly NFSD_MAY_READ
2. The "hints" portion of the access flags (the upper 26 bits) can contain any combination of NFSD_MAY_OWNER_OVERRIDE and NFSD_MAY_READ_IF_EXEC

Fixes abc02e5602f7 ("NFSD: Support write delegations in LAYOUTGET")
---
 fs/nfsd/vfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +0 -0
index 964cf922ad83..168d3ccc8155 100644

fs/nfsd/vfs.c nfsd_permission(struct svc_cred *cred, struct svc_export *exp, · line 2870

Quoted 8 lines
fs/nfsd/vfs.c +2 -2
@@ -2865,8 +2865,8 @@ nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
 
 	/* Allow read access to binaries even when mode 111 */
 	if (err == -EACCES && S_ISREG(inode->i_mode) &&
-	     (acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE) ||
-	      acc == (NFSD_MAY_READ | NFSD_MAY_READ_IF_EXEC)))
+	     (((acc & NFSD_MAY_MASK) == NFSD_MAY_READ) &&
+	      (acc & (NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_READ_IF_EXEC))))
 		err = inode_permission(&nop_mnt_idmap, inode, MAY_EXEC);
Quoted 3 lines

The new code is cleaner and more correct - thanks.

NeilBrown

Agreed.

maintainer
#3 lore raw
In reply to Scott Mayhew

From: Chuck Lever <[email protected]>

Quoted 5 lines · Scott Mayhew

Commit abc02e5602f7 added NFSD_MAY_OWNER_OVERRIDE to the access flags passed from nfsd4_layoutget() to fh_verify(). This causes LAYOUTGET to fail for executable-only files, and causes xfstests generic/126 to fail on pNFS SCSI.

Quoted 8 lines

To allow read access to executable-only files, what we really want is:
1. The "permissions" portion of the access flags (the lower 6 bits) must be exactly NFSD_MAY_READ
2. The "hints" portion of the access flags (the upper 26 bits) can contain any combination of NFSD_MAY_OWNER_OVERRIDE and NFSD_MAY_READ_IF_EXEC

[...]

Applied to nfsd-testing, thanks!

[1/1] NFSD: Fix permission check for read access to executable-only files

      commit: 2341758268d9bdc099c48fde624fee6d3754bb84

--
Chuck Lever