diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 6937e7c19ee3..1c4b50fba74a 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -520,6 +520,13 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, oplock = pTcon->ses->server->oplocks ? REQ_OPLOCK : 0; + /* Don't allow path components longer than the server max. */ + if (unlikely(direntry->d_name.len > + pTcon->fsAttrInfo.MaxPathNameComponentLength)) { + rc = -ENAMETOOLONG; + goto lookup_out; + } + /* * Don't allow the separator character in a path component. * The VFS will not allow "/", but "\" is allowed by posix.