Skip to contentSkip to conversation

smb: client: fix potential NULL deref in parse_dfs_referrals()

PATCH In review Paulo Alcantara 2 participants 2 messages Dec 6, 2023

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

PATCH 1/1 smb: client: fix potential NULL deref in parse_dfs_referrals()

If server returned no data for FSCTL_DFS_GET_REFERRALS, @dfs_rsp will remain NULL and then parse_dfs_referrals() will dereference it.

Fix this by returning -EIO when no output data is returned.

Besides, we can't fix it in SMB2_ioctl() as some FSCTLs are allowed to return no data as per MS-SMB2 2.2.32.

Fixes 9d49640a21bf ("CIFS: implement get_dfs_refer for SMB2+")
---
 fs/smb/client/smb2ops.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2ops.c +2 -0
index 45931115f475..fcfb6566b899 100644
@@ -2836,6 +2836,8 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
 		usleep_range(512, 2048);
 	} while (++retry_count < 5);
 
+	if (!rc && !dfs_rsp)
+		rc = -EIO;
 	if (rc) {
 		if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
 			cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
Signature · 1 line
2.43.0
#1 lore raw

updated cifs-2.6.git for-next (and added Cc: stable) with this patch

Quoted 32 lines · Paulo Alcantara

If server returned no data for FSCTL_DFS_GET_REFERRALS, @dfs_rsp will remain NULL and then parse_dfs_referrals() will dereference it.

Fix this by returning -EIO when no output data is returned.

Besides, we can't fix it in SMB2_ioctl() as some FSCTLs are allowed to return no data as per MS-SMB2 2.2.32.

Fixes 9d49640a21bf ("CIFS: implement get_dfs_refer for SMB2+")
---
 fs/smb/client/smb2ops.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2ops.c +2 -1
index 45931115f475..fcfb6566b899 100644
@@ -2836,6 +2836,8 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
                usleep_range(512, 2048);
        } while (++retry_count < 5);
 
+       if (!rc && !dfs_rsp)
+               rc = -EIO;
        if (rc) {
                if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
                        cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
--

2.43.0

Signature · 3 lines
Thanks,

Steve