Skip to content

Commit 88a92c9

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: fix crash in smb2_compound_op()/smb2_set_next_command()
RHBZ: 1722704 In low memory situations the various SMB2_*_init() functions can fail to allocate a request PDU and thus leave the request iovector as NULL. If we don't check the return code for failure we end up calling smb2_set_next_command() with a NULL iovector causing a crash when it tries to dereference it. CC: Stable <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ce465bf commit 88a92c9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

fs/cifs/smb2inode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
120120
SMB2_O_INFO_FILE, 0,
121121
sizeof(struct smb2_file_all_info) +
122122
PATH_MAX * 2, 0, NULL);
123+
if (rc)
124+
goto finished;
123125
smb2_set_next_command(tcon, &rqst[num_rqst]);
124126
smb2_set_related(&rqst[num_rqst++]);
125127
trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid,
@@ -147,6 +149,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
147149
COMPOUND_FID, current->tgid,
148150
FILE_DISPOSITION_INFORMATION,
149151
SMB2_O_INFO_FILE, 0, data, size);
152+
if (rc)
153+
goto finished;
150154
smb2_set_next_command(tcon, &rqst[num_rqst]);
151155
smb2_set_related(&rqst[num_rqst++]);
152156
trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path);
@@ -163,6 +167,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
163167
COMPOUND_FID, current->tgid,
164168
FILE_END_OF_FILE_INFORMATION,
165169
SMB2_O_INFO_FILE, 0, data, size);
170+
if (rc)
171+
goto finished;
166172
smb2_set_next_command(tcon, &rqst[num_rqst]);
167173
smb2_set_related(&rqst[num_rqst++]);
168174
trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path);
@@ -180,6 +186,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
180186
COMPOUND_FID, current->tgid,
181187
FILE_BASIC_INFORMATION,
182188
SMB2_O_INFO_FILE, 0, data, size);
189+
if (rc)
190+
goto finished;
183191
smb2_set_next_command(tcon, &rqst[num_rqst]);
184192
smb2_set_related(&rqst[num_rqst++]);
185193
trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid,
@@ -206,6 +214,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
206214
COMPOUND_FID, current->tgid,
207215
FILE_RENAME_INFORMATION,
208216
SMB2_O_INFO_FILE, 0, data, size);
217+
if (rc)
218+
goto finished;
209219
smb2_set_next_command(tcon, &rqst[num_rqst]);
210220
smb2_set_related(&rqst[num_rqst++]);
211221
trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path);
@@ -231,6 +241,8 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
231241
COMPOUND_FID, current->tgid,
232242
FILE_LINK_INFORMATION,
233243
SMB2_O_INFO_FILE, 0, data, size);
244+
if (rc)
245+
goto finished;
234246
smb2_set_next_command(tcon, &rqst[num_rqst]);
235247
smb2_set_related(&rqst[num_rqst++]);
236248
trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path);

fs/cifs/smb2ops.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,10 @@ smb2_set_related(struct smb_rqst *rqst)
20272027
struct smb2_sync_hdr *shdr;
20282028

20292029
shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2030+
if (shdr == NULL) {
2031+
cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2032+
return;
2033+
}
20302034
shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
20312035
}
20322036

@@ -2041,6 +2045,12 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
20412045
unsigned long len = smb_rqst_len(server, rqst);
20422046
int i, num_padding;
20432047

2048+
shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2049+
if (shdr == NULL) {
2050+
cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2051+
return;
2052+
}
2053+
20442054
/* SMB headers in a compound are 8 byte aligned. */
20452055

20462056
/* No padding needed */
@@ -2080,7 +2090,6 @@ smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
20802090
}
20812091

20822092
finished:
2083-
shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
20842093
shdr->NextCommand = cpu_to_le32(len);
20852094
}
20862095

0 commit comments

Comments
 (0)