Skip to content

Commit 567320c

Browse files
Paulo Alcantarasmfrench
authored andcommitted
smb: client: fix potential OOB in smb2_dump_detail()
Validate SMB message with ->check_message() before calling ->calc_smb_size(). This fixes CVE-2023-6610. Reported-by: [email protected] Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218219 Cc; [email protected] Signed-off-by: Paulo Alcantara <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent b50492b commit 567320c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

fs/smb/client/smb2misc.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)
173173
}
174174

175175
mid = le64_to_cpu(shdr->MessageId);
176+
if (check_smb2_hdr(shdr, mid))
177+
return 1;
178+
179+
if (shdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) {
180+
cifs_dbg(VFS, "Invalid structure size %u\n",
181+
le16_to_cpu(shdr->StructureSize));
182+
return 1;
183+
}
184+
185+
command = le16_to_cpu(shdr->Command);
186+
if (command >= NUMBER_OF_SMB2_COMMANDS) {
187+
cifs_dbg(VFS, "Invalid SMB2 command %d\n", command);
188+
return 1;
189+
}
190+
176191
if (len < pdu_size) {
177192
if ((len >= hdr_size)
178193
&& (shdr->Status != 0)) {
@@ -193,21 +208,6 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)
193208
return 1;
194209
}
195210

196-
if (check_smb2_hdr(shdr, mid))
197-
return 1;
198-
199-
if (shdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) {
200-
cifs_dbg(VFS, "Invalid structure size %u\n",
201-
le16_to_cpu(shdr->StructureSize));
202-
return 1;
203-
}
204-
205-
command = le16_to_cpu(shdr->Command);
206-
if (command >= NUMBER_OF_SMB2_COMMANDS) {
207-
cifs_dbg(VFS, "Invalid SMB2 command %d\n", command);
208-
return 1;
209-
}
210-
211211
if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) {
212212
if (command != SMB2_OPLOCK_BREAK_HE && (shdr->Status == 0 ||
213213
pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2_LE)) {

fs/smb/client/smb2ops.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
403403
cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
404404
shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
405405
shdr->Id.SyncId.ProcessId);
406-
cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
407-
server->ops->calc_smb_size(buf));
406+
if (!server->ops->check_message(buf, server->total_read, server)) {
407+
cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
408+
server->ops->calc_smb_size(buf));
409+
}
408410
#endif
409411
}
410412

0 commit comments

Comments
 (0)