Skip to content

Commit dffb44b

Browse files
Zisen Yegregkh
authored andcommitted
smb/client: fix out-of-bounds read in smb2_compound_op()
commit 8d09328 upstream. If a server sends a truncated response but a large OutputBufferLength, and terminates the EA list early, check_wsl_eas() returns success without validating that the entire OutputBufferLength fits within iov_len. Then smb2_compound_op() does: memcpy(idata->wsl.eas, data[0], size[0]); Where size[0] is OutputBufferLength. If iov_len is smaller than size[0], memcpy can read beyond the end of the rsp_iov allocation and leak adjacent kernel heap memory. Link: https://lore.kernel.org/linux-cifs/d998240c-aca9-420d-9dbd-f5ba24af19e0@chenxiaosong.com/ Fixes: ea41367 ("smb: client: introduce SMB2_OP_QUERY_WSL_EA") Cc: stable@vger.kernel.org Signed-off-by: Zisen Ye <zisenye@stu.xidian.edu.cn> Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e5c9384 commit dffb44b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

fs/smb/client/smb2inode.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int check_wsl_eas(struct kvec *rsp_iov)
108108
u32 outlen, next;
109109
u16 vlen;
110110
u8 nlen;
111-
u8 *end;
111+
u8 *ea_end, *iov_end;
112112

113113
outlen = le32_to_cpu(rsp->OutputBufferLength);
114114
if (outlen < SMB2_WSL_MIN_QUERY_EA_RESP_SIZE ||
@@ -117,15 +117,19 @@ static int check_wsl_eas(struct kvec *rsp_iov)
117117

118118
ea = (void *)((u8 *)rsp_iov->iov_base +
119119
le16_to_cpu(rsp->OutputBufferOffset));
120-
end = (u8 *)rsp_iov->iov_base + rsp_iov->iov_len;
120+
ea_end = (u8 *)ea + outlen;
121+
iov_end = (u8 *)rsp_iov->iov_base + rsp_iov->iov_len;
122+
if (ea_end > iov_end)
123+
return -EINVAL;
124+
121125
for (;;) {
122-
if ((u8 *)ea > end - sizeof(*ea))
126+
if ((u8 *)ea > ea_end - sizeof(*ea))
123127
return -EINVAL;
124128

125129
nlen = ea->ea_name_length;
126130
vlen = le16_to_cpu(ea->ea_value_length);
127131
if (nlen != SMB2_WSL_XATTR_NAME_LEN ||
128-
(u8 *)ea->ea_data + nlen + 1 + vlen > end)
132+
(u8 *)ea->ea_data + nlen + 1 + vlen > ea_end)
129133
return -EINVAL;
130134

131135
switch (vlen) {

0 commit comments

Comments
 (0)