All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfsd: Return EPERM on utime/utimes/lutimes calls instead of EACCESS in some cases
@ 2018-11-30  8:04 zhengbin
  0 siblings, 0 replies; 8+ messages in thread
From: zhengbin @ 2018-11-30  8:04 UTC (permalink / raw)
  To: bfields, jlayton, linux-nfs; +Cc: zhengbin13, houtao1, zhaohongjiang

As the man(3) page for utime/utimes/lutimes, EPERM is returned
when the second parameter of utime/utimes/lutimes is not NULL,
the caller's effective UID does not match the owner of the file,
and the caller is not privileged.

However, in a NFS directory, it will return EACCESS(nfsd_setattr->
fh_verify->nfsd_permission), This patch fix this.

Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
 fs/nfsd/vfs.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index eb67098..9824e32 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -396,10 +396,23 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
 	bool		get_write_count;
 	bool		size_change = (iap->ia_valid & ATTR_SIZE);

-	if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_SIZE))
+	if (iap->ia_valid & ATTR_SIZE) {
 		accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
-	if (iap->ia_valid & ATTR_SIZE)
 		ftype = S_IFREG;
+	}
+
+	/*
+	 * If utimes(2) and friends are called with times not NULL, we should
+	 * not set NFSD_MAY_WRITE bit. Otherwise fh_verify->nfsd_permission
+	 * will return EACCESS, when the caller's effective UID does not match
+	 * the owner of the file, and the caller is not privileged. In this
+	 * situation, we should return EPERM(notify_change will return this).
+	 */
+	if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME)) {
+		accmode |= NFSD_MAY_OWNER_OVERRIDE;
+		if (!(iap->ia_valid & (ATTR_ATIME_SET | ATTR_MTIME_SET)))
+			accmode |= NFSD_MAY_WRITE;
+	}

 	/* Callers that do fh_verify should do the fh_want_write: */
 	get_write_count = !fhp->fh_dentry;
--
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH] nfsd: Return EPERM on utime/utimes/lutimes calls instead of EACCESS in some cases
@ 2018-11-30  7:51 zhengbin
  2018-12-03  8:36 ` zhengbin (A)
  0 siblings, 1 reply; 8+ messages in thread
From: zhengbin @ 2018-11-30  7:51 UTC (permalink / raw)
  To: bfields, jlayton, linux-nfs; +Cc: zhengbin13, houtao1, zhaohongjiang

As the man(3) page for utime/utimes/lutimes, EPERM is returned
when the second parameter of utime/utimes/lutimes is not NULL,
the caller's effective UID does not match the owner of the file,
and the caller is not privileged.

However, in a NFS directory, it will return EACCESS(nfsd_setattr->
fh_verify->nfsd_permission), This patch fix this.

Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
 fs/nfsd/vfs.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index eb67098..9824e32 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -396,10 +396,23 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
 	bool		get_write_count;
 	bool		size_change = (iap->ia_valid & ATTR_SIZE);

-	if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_SIZE))
+	if (iap->ia_valid & ATTR_SIZE) {
 		accmode |= NFSD_MAY_WRITE|NFSD_MAY_OWNER_OVERRIDE;
-	if (iap->ia_valid & ATTR_SIZE)
 		ftype = S_IFREG;
+	}
+
+	/*
+	 * If utimes(2) and friends are called with times not NULL, we should
+	 * not set NFSD_MAY_WRITE bit. Otherwise fh_verify->nfsd_permission
+	 * will return EACCESS, when the caller's effective UID does not match
+	 * the owner of the file, and the caller is not privileged. In this
+	 * situation, we should return EPERM(notify_change will return this).
+	 */
+	if (iap->ia_valid & (ATTR_ATIME | ATTR_MTIME)) {
+		accmode |= NFSD_MAY_OWNER_OVERRIDE;
+		if (!(iap->ia_valid & (ATTR_ATIME_SET | ATTR_MTIME_SET)))
+			accmode |= NFSD_MAY_WRITE;
+	}

 	/* Callers that do fh_verify should do the fh_want_write: */
 	get_write_count = !fhp->fh_dentry;
--
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-12-05  1:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30  8:04 [PATCH] nfsd: Return EPERM on utime/utimes/lutimes calls instead of EACCESS in some cases zhengbin
  -- strict thread matches above, loose matches on Subject: below --
2018-11-30  7:51 zhengbin
2018-12-03  8:36 ` zhengbin (A)
2018-12-04 20:13   ` J. Bruce Fields
2018-12-05  1:04     ` zhengbin (A)
2018-12-05  1:37       ` J. Bruce Fields
2018-12-05  1:43         ` zhengbin (A)
2018-12-05  1:49           ` J. Bruce Fields

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.