NFS: nfs_prime_dcache must validate the filename
authorTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 20 Sep 2016 18:34:24 +0000 (14:34 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Thu, 22 Sep 2016 21:02:03 +0000 (17:02 -0400)
Before we try to stash it in the dcache, we need to at least check
that the filename passed to us by the server is non-empty and doesn't
contain any illegal '\0' or '/' characters.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/dir.c

index 177fefb26c18d344a30dfb85f75db61c7a6e44ec..eb095f77c39d0277762ee543c9fea38fdbcf98ab 100644 (file)
@@ -496,6 +496,14 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
                return;
        if (!(entry->fattr->valid & NFS_ATTR_FATTR_FSID))
                return;
+       if (filename.len == 0)
+               return;
+       /* Validate that the name doesn't contain any illegal '\0' */
+       if (strnlen(filename.name, filename.len) != filename.len)
+               return;
+       /* ...or '/' */
+       if (strnchr(filename.name, filename.len, '/'))
+               return;
        if (filename.name[0] == '.') {
                if (filename.len == 1)
                        return;