summaryrefslogtreecommitdiffstats
path: root/sys/fs
diff options
context:
space:
mode:
authorrmacklem <rmacklem@FreeBSD.org>2015-06-04 12:35:00 +0000
committerrmacklem <rmacklem@FreeBSD.org>2015-06-04 12:35:00 +0000
commit7e70fa5ddf08770c1c0fd7766648ce038f7ddfb4 (patch)
tree4d344f274249fa16518cd300054c2a50f37feeab /sys/fs
parentb8022a78066933b27588597a788d2ca57544a094 (diff)
downloadFreeBSD-src-7e70fa5ddf08770c1c0fd7766648ce038f7ddfb4.zip
FreeBSD-src-7e70fa5ddf08770c1c0fd7766648ce038f7ddfb4.tar.gz
MFC: r283273
The NFS client wasn't handling getdirentries(2) requests for sizes that are not an exact multiple of DIRBLKSIZ correctly. Fortunately readdir(3) always uses an exact multiple of DIRBLKSIZ, so few applications were affected. This patch fixes this problem by reducing the size of the directory read to an exact multiple of DIRBLKSIZ.
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/nfsclient/nfs_clvnops.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index 731d6a2..1013164 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -2211,7 +2211,7 @@ nfs_readdir(struct vop_readdir_args *ap)
struct vnode *vp = ap->a_vp;
struct nfsnode *np = VTONFS(vp);
struct uio *uio = ap->a_uio;
- ssize_t tresid;
+ ssize_t tresid, left;
int error = 0;
struct vattr vattr;
@@ -2240,6 +2240,17 @@ nfs_readdir(struct vop_readdir_args *ap)
}
/*
+ * NFS always guarantees that directory entries don't straddle
+ * DIRBLKSIZ boundaries. As such, we need to limit the size
+ * to an exact multiple of DIRBLKSIZ, to avoid copying a partial
+ * directory entry.
+ */
+ left = uio->uio_resid % DIRBLKSIZ;
+ if (left == uio->uio_resid)
+ return (EINVAL);
+ uio->uio_resid -= left;
+
+ /*
* Call ncl_bioread() to do the real work.
*/
tresid = uio->uio_resid;
@@ -2250,6 +2261,9 @@ nfs_readdir(struct vop_readdir_args *ap)
if (ap->a_eofflag != NULL)
*ap->a_eofflag = 1;
}
+
+ /* Add the partial DIRBLKSIZ (left) back in. */
+ uio->uio_resid += left;
return (error);
}
OpenPOWER on IntegriCloud