Skip to contentSkip to conversation

cifs: fix out-of-bound memory access when calling smb3_notify() at mount point

PATCH In review Eugene Korenevsky 2 participants 2 messages Apr 16, 2021 – Apr 17, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix out-of-bound memory access when calling smb3_notify() at mount point

If smb3_notify() is called at mount point of CIFS, build_path_from_dentry() returns the pointer to kmalloc-ed memory with terminating zero (this is empty FileName to be passed to SMB2 CREATE request). This pointer is assigned to the path variable.
Then path + 1 (to skip first backslash symbol) is passed to cifs_convert_path_to_utf16(). This is incorrect for empty path and causes out-of-bound memory access.

Get rid of this "increase by one". cifs_convert_path_to_utf16() already contains the check for leading backslash in the path.

---
 fs/cifs/smb2ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2ops.c +1 -1
index caa5432a5ed1..b13a8e3e1e24 100644
@@ -2264,7 +2264,7 @@ smb3_notify(const unsigned int xid, struct file *pfile,
 		goto notify_exit;
 	}
 
-	utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
+	utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
 	if (utf16_path == NULL) {
 		rc = -ENOMEM;
 		goto notify_exit;
Signature · 1 line
2.20.1
#1 lore raw

Added:
CC: <[email protected]> # v5.6+
and merged into cifs-2.6.git for-next

Quoted 34 lines · Eugene Korenevsky

If smb3_notify() is called at mount point of CIFS, build_path_from_dentry() returns the pointer to kmalloc-ed memory with terminating zero (this is empty FileName to be passed to SMB2 CREATE request). This pointer is assigned to the path variable.
Then path + 1 (to skip first backslash symbol) is passed to cifs_convert_path_to_utf16(). This is incorrect for empty path and causes out-of-bound memory access.

Get rid of this "increase by one". cifs_convert_path_to_utf16() already contains the check for leading backslash in the path.

---
 fs/cifs/smb2ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2ops.c +1 -2
index caa5432a5ed1..b13a8e3e1e24 100644
@@ -2264,7 +2264,7 @@ smb3_notify(const unsigned int xid, struct file *pfile,
                goto notify_exit;
        }
 
-       utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
+       utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
        if (utf16_path == NULL) {
                rc = -ENOMEM;
                goto notify_exit;
--

2.20.1

Signature · 3 lines
Thanks,

Steve