[PATCH 4.4 03/40] cifs: check MaxPathNameComponentLength != 0 before using it

From: Greg Kroah-Hartman
Date: Mon Nov 06 2017 - 04:56:05 EST


4.4-stable review patch. If anyone has any objections, please let me know.

------------------

From: Ronnie Sahlberg <lsahlber@xxxxxxxxxx>

commit f74bc7c6679200a4a83156bb89cbf6c229fe8ec0 upstream.

And fix tcon leak in error path.

Signed-off-by: Ronnie Sahlberg <lsahlber@xxxxxxxxxx>
Signed-off-by: Steve French <smfrench@xxxxxxxxx>
Reviewed-by: David Disseldorp <ddiss@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
fs/cifs/dir.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -193,7 +193,8 @@ check_name(struct dentry *direntry, stru
struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
int i;

- if (unlikely(direntry->d_name.len >
+ if (unlikely(tcon->fsAttrInfo.MaxPathNameComponentLength &&
+ direntry->d_name.len >
le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength)))
return -ENAMETOOLONG;

@@ -509,7 +510,7 @@ cifs_atomic_open(struct inode *inode, st

rc = check_name(direntry, tcon);
if (rc)
- goto out_free_xid;
+ goto out;

server = tcon->ses->server;