Skip to content

Commit c1596ff

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: change validate_buf to validate_iov
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
1 parent 05432e2 commit c1596ff

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

fs/cifs/smb2pdu.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,13 +2206,13 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
22062206
}
22072207

22082208
static int
2209-
validate_buf(unsigned int offset, unsigned int buffer_length,
2210-
struct smb2_hdr *hdr, unsigned int min_buf_size)
2211-
2209+
validate_iov(struct TCP_Server_Info *server,
2210+
unsigned int offset, unsigned int buffer_length,
2211+
struct kvec *iov, unsigned int min_buf_size)
22122212
{
2213-
unsigned int smb_len = be32_to_cpu(hdr->smb2_buf_length);
2214-
char *end_of_smb = smb_len + 4 /* RFC1001 length field */ + (char *)hdr;
2215-
char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
2213+
unsigned int smb_len = iov->iov_len;
2214+
char *end_of_smb = smb_len + server->vals->header_preamble_size + (char *)iov->iov_base;
2215+
char *begin_of_buf = server->vals->header_preamble_size + offset + (char *)iov->iov_base;
22162216
char *end_of_buf = begin_of_buf + buffer_length;
22172217

22182218

@@ -2242,18 +2242,18 @@ validate_buf(unsigned int offset, unsigned int buffer_length,
22422242
* Caller must free buffer.
22432243
*/
22442244
static int
2245-
validate_and_copy_buf(unsigned int offset, unsigned int buffer_length,
2246-
struct smb2_hdr *hdr, unsigned int minbufsize,
2245+
validate_and_copy_iov(struct TCP_Server_Info *server,
2246+
unsigned int offset, unsigned int buffer_length,
2247+
struct kvec *iov, unsigned int minbufsize,
22472248
char *data)
2248-
22492249
{
2250-
char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
2250+
char *begin_of_buf = server->vals->header_preamble_size + offset + (char *)(iov->iov_base);
22512251
int rc;
22522252

22532253
if (!data)
22542254
return -EINVAL;
22552255

2256-
rc = validate_buf(offset, buffer_length, hdr, minbufsize);
2256+
rc = validate_iov(server, offset, buffer_length, iov, minbufsize);
22572257
if (rc)
22582258
return rc;
22592259

@@ -2331,9 +2331,10 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
23312331
}
23322332
}
23332333

2334-
rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset),
2334+
rc = validate_and_copy_iov(ses->server,
2335+
le16_to_cpu(rsp->OutputBufferOffset),
23352336
le32_to_cpu(rsp->OutputBufferLength),
2336-
&rsp->hdr, min_len, *data);
2337+
&rsp_iov, min_len, *data);
23372338

23382339
qinf_exit:
23392340
free_rsp_buf(resp_buftype, rsp);
@@ -3254,8 +3255,9 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
32543255
goto qdir_exit;
32553256
}
32563257

3257-
rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
3258-
le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
3258+
rc = validate_iov(server,
3259+
le16_to_cpu(rsp->OutputBufferOffset),
3260+
le32_to_cpu(rsp->OutputBufferLength), &rsp_iov,
32593261
info_buf_size);
32603262
if (rc)
32613263
goto qdir_exit;
@@ -3627,8 +3629,9 @@ SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
36273629

36283630
info = (struct smb2_fs_full_size_info *)(server->vals->header_preamble_size +
36293631
le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr);
3630-
rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
3631-
le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
3632+
rc = validate_iov(server,
3633+
le16_to_cpu(rsp->OutputBufferOffset),
3634+
le32_to_cpu(rsp->OutputBufferLength), &rsp_iov,
36323635
sizeof(struct smb2_fs_full_size_info));
36333636
if (!rc)
36343637
copy_fs_info_to_kstatfs(info, fsdata);
@@ -3684,7 +3687,7 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
36843687

36853688
rsp_len = le32_to_cpu(rsp->OutputBufferLength);
36863689
offset = le16_to_cpu(rsp->OutputBufferOffset);
3687-
rc = validate_buf(offset, rsp_len, &rsp->hdr, min_len);
3690+
rc = validate_iov(server, offset, rsp_len, &rsp_iov, min_len);
36883691
if (rc)
36893692
goto qfsattr_exit;
36903693

0 commit comments

Comments
 (0)