Skip to content

Commit 0ec757d

Browse files
J. Bruce FieldsLinus Torvalds
authored andcommitted
knfsd: nfsd4: make readonly access depend on pseudoflavor
Allow readonly access to vary depending on the pseudoflavor, using the flag passed with each pseudoflavor in the export downcall. The rest of the flags are ignored for now, though some day we might also allow id squashing to vary based on the flavor. Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 32c1eb0 commit 0ec757d

5 files changed

Lines changed: 24 additions & 10 deletions

File tree

‎fs/nfsd/nfsfh.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
255255
goto out;
256256

257257
/* Finally, check access permissions. */
258-
error = nfsd_permission(exp, dentry, access);
258+
error = nfsd_permission(rqstp, exp, dentry, access);
259259

260260
if (error) {
261261
dprintk("fh_verify: %s/%s permission failure, "

‎fs/nfsd/nfsproc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
278278
* echo thing > device-special-file-or-pipe
279279
* by doing a CREATE with type==0
280280
*/
281-
nfserr = nfsd_permission(newfhp->fh_export,
281+
nfserr = nfsd_permission(rqstp,
282+
newfhp->fh_export,
282283
newfhp->fh_dentry,
283284
MAY_WRITE|MAY_LOCAL_ACCESS);
284285
if (nfserr && nfserr != nfserr_rofs)

‎fs/nfsd/vfs.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
328328
/* The size case is special. It changes the file as well as the attributes. */
329329
if (iap->ia_valid & ATTR_SIZE) {
330330
if (iap->ia_size < inode->i_size) {
331-
err = nfsd_permission(fhp->fh_export, dentry, MAY_TRUNC|MAY_OWNER_OVERRIDE);
331+
err = nfsd_permission(rqstp, fhp->fh_export, dentry, MAY_TRUNC|MAY_OWNER_OVERRIDE);
332332
if (err)
333333
goto out;
334334
}
@@ -616,7 +616,7 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor
616616

617617
sresult |= map->access;
618618

619-
err2 = nfsd_permission(export, dentry, map->how);
619+
err2 = nfsd_permission(rqstp, export, dentry, map->how);
620620
switch (err2) {
621621
case nfs_ok:
622622
result |= map->access;
@@ -1043,7 +1043,7 @@ nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
10431043
__be32 err;
10441044

10451045
if (file) {
1046-
err = nfsd_permission(fhp->fh_export, fhp->fh_dentry,
1046+
err = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
10471047
MAY_READ|MAY_OWNER_OVERRIDE);
10481048
if (err)
10491049
goto out;
@@ -1072,7 +1072,7 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
10721072
__be32 err = 0;
10731073

10741074
if (file) {
1075-
err = nfsd_permission(fhp->fh_export, fhp->fh_dentry,
1075+
err = nfsd_permission(rqstp, fhp->fh_export, fhp->fh_dentry,
10761076
MAY_WRITE|MAY_OWNER_OVERRIDE);
10771077
if (err)
10781078
goto out;
@@ -1801,7 +1801,8 @@ nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat)
18011801
* Check for a user's access permissions to this inode.
18021802
*/
18031803
__be32
1804-
nfsd_permission(struct svc_export *exp, struct dentry *dentry, int acc)
1804+
nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
1805+
struct dentry *dentry, int acc)
18051806
{
18061807
struct inode *inode = dentry->d_inode;
18071808
int err;
@@ -1832,7 +1833,7 @@ nfsd_permission(struct svc_export *exp, struct dentry *dentry, int acc)
18321833
*/
18331834
if (!(acc & MAY_LOCAL_ACCESS))
18341835
if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
1835-
if (EX_RDONLY(exp) || IS_RDONLY(inode))
1836+
if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode))
18361837
return nfserr_rofs;
18371838
if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
18381839
return nfserr_perm;

‎include/linux/nfsd/export.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,21 @@ struct svc_expkey {
112112

113113
#define EX_SECURE(exp) (!((exp)->ex_flags & NFSEXP_INSECURE_PORT))
114114
#define EX_ISSYNC(exp) (!((exp)->ex_flags & NFSEXP_ASYNC))
115-
#define EX_RDONLY(exp) ((exp)->ex_flags & NFSEXP_READONLY)
116115
#define EX_NOHIDE(exp) ((exp)->ex_flags & NFSEXP_NOHIDE)
117116
#define EX_WGATHER(exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES)
118117

118+
static inline int EX_RDONLY(struct svc_export *exp, struct svc_rqst *rqstp)
119+
{
120+
struct exp_flavor_info *f;
121+
struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
122+
123+
for (f = exp->ex_flavors; f < end; f++) {
124+
if (f->pseudoflavor == rqstp->rq_flavor)
125+
return f->flags & NFSEXP_READONLY;
126+
}
127+
return exp->ex_flags & NFSEXP_READONLY;
128+
}
129+
119130
__be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
120131

121132
/*

‎include/linux/nfsd/nfsd.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
119119
struct kstatfs *);
120120

121121
int nfsd_notify_change(struct inode *, struct iattr *);
122-
__be32 nfsd_permission(struct svc_export *, struct dentry *, int);
122+
__be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
123+
struct dentry *, int);
123124
int nfsd_sync_dir(struct dentry *dp);
124125

125126
#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)

0 commit comments

Comments
 (0)