From: VeroFess <coderzeng@gmail.com>
To: linux-nfs@vger.kernel.org
Cc: cel@kernel.org, jlayton@kernel.org
Subject: [PATCH 2/3] NFSD: Apply the entered export's credentials after LOOKUP and RESTOREFH
Date: Tue, 3 Nov 2026 09:32:36 +0800 [thread overview]
Message-ID: <20261103013237.1174538-3-coderzeng@gmail.com> (raw)
In-Reply-To: <20261103013237.1174538-1-coderzeng@gmail.com>
LOOKUP verifies its parent filehandle before selecting a child export.
After the crossing, the task can still use credentials mapped by the
parent export. RESTOREFH likewise restores a saved filehandle without
restoring its export's credentials. The requester must already hold an
OPEN stateid for the file: with a cached stateid, READ can retain root
access after the export enables root_squash, or fail even though
all_squash would allow access through its anonymous UID or GID.
Verify the composed filehandle when LOOKUP selects another export.
After RESTOREFH, install the saved export's credentials and propagate
an error from nfsd_setuser(). Keep the existing deferred flavor
decision for RESTOREFH.
The credential mismatch is old; it dates back at least to Linux
2.6.12. Maintained LTS branches with these filehandle paths also need
the correction.
Signed-off-by: VeroFess <coderzeng@gmail.com>
---
On nfsd-testing with all three fixes, crossed and restored READ used the
child export's root_squash or all_squash mapping, including anonymous
UID 2000 and GID 2001. In a separate fault-injection build of the same
NFSD code, RESTOREFH returned NFS4ERR_DELAY before GETATTR. This patch
also built alone with W=1.
fs/nfsd/nfs4proc.c | 4 +++-
fs/nfsd/vfs.c | 5 +++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 43c2aa9..218cedb 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -49,6 +49,7 @@
#include "xdr4.h"
#include "nfs4ctl.h"
#include "vfs.h"
+#include "auth.h"
#include "current_stateid.h"
#include "netns.h"
#include "acl.h"
@@ -859,7 +860,8 @@ nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
}
- return nfs_ok;
+ return nfserrno(nfsd_setuser(&rqstp->rq_cred,
+ cstate->current_fh.fh_export));
}
static __be32
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 2775911..0547029 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -351,6 +351,7 @@ __nfsd_lookup(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name,
{
struct svc_export *exp;
struct dentry *dentry;
+ bool crossed;
__be32 err;
err = fh_verify(rqstp, fhp, S_IFDIR, access);
@@ -363,9 +364,13 @@ __nfsd_lookup(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name,
* Note: we compose the file handle now, but as the
* dentry may be negative, it may need to be updated.
*/
+ crossed = exp != fhp->fh_export;
err = fh_compose(resfh, exp, dentry, fhp);
if (!err && d_really_is_negative(dentry))
err = nfserr_noent;
+ if (!err && crossed)
+ err = fh_verify(rqstp, resfh, 0,
+ access & NFSD_MAY_BYPASS_FLAVOR);
dput(dentry);
exp_put(exp);
--
2.43.0
next prev parent reply other threads:[~2026-11-03 1:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 1:32 [PATCH 0/3] NFSD: Apply all export checks when a compound changes exports VeroFess
2026-11-03 1:32 ` [PATCH 1/3] NFSD: Check the secure-port policy when entering an export VeroFess
2026-11-03 1:32 ` VeroFess [this message]
2026-11-03 1:32 ` [PATCH 3/3] NFSD: Verify COPY and CLONE source and destination filehandles VeroFess
2026-11-03 14:06 ` [PATCH 0/3] NFSD: Apply all export checks when a compound changes exports Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103013237.1174538-3-coderzeng@gmail.com \
--to=coderzeng@gmail.com \
--cc=cel@kernel.org \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox