SMB2_set_info_init() copies the variable-length set-info data into the SMB2 request object without checking that it fits. The object is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes and the data starts at sizeof(struct smb2_set_info_req), leaving 16492 bytes with the default CIFSMaxBufSize. A malicious server can return a nearly maximum-size security descriptor; id_mode_to_cifs_acl() retains its ACEs and adds up to five new ones, producing a rewritten ACL around 16.8 KB. A chmod() or chown() on a cifsacl mount then makes the memcpy() write up to 336 bytes past the cifs_request object, and the overrun is also read back and sent to the server. The worst case is much larger: if the server returns a security descriptor whose owner and group SIDs map to 15 subauths, the rewritten ACL keeps the original ACEs and replaces both SIDs. With 817 ACEs the resulting SET_INFO data is 62256 bytes; KASAN reports a slab-out-of-bounds write of 45764 bytes past the 16588-byte cifs_request object on v7.4-rc2 (where the earlier undersized-allocation issue is already fixed): BUG: KASAN: slab-out-of-bounds in SMB2_set_info_init+0x47c/0x6d0 [cifs] Write of size 62256 at addr ffff88800ee28060 by task python3/86 The buggy address is located 96 bytes inside of allocated 16588-byte region Reject data that cannot fit before the copy. This covers SMB2_set_acl(), SMB2_set_ea() and the other SMB2_SET_INFO callers. The vulnerable copy predates the ACE-retention rework, but the rework makes the overflow reachable with an ordinary chmod on a cifsacl mount. Fixes: 35143eb5c2e3 ("CIFS: Add SMB2 support for rename operation") Cc: stable@vger.kernel.org Signed-off-by: Abdifatah Suruur --- fs/smb/client/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index f85595136ef8a..beb3abf9724dd 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5894,6 +5894,17 @@ SMB2_set_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, req->AdditionalInformation = cpu_to_le32(additional_info); req->BufferOffset = cpu_to_le16(sizeof(struct smb2_set_info_req)); + + /* + * The request object is CIFSMaxBufSize + MAX_SMB2_HDR_SIZE bytes + * and Buffer starts at sizeof(struct smb2_set_info_req). + */ + if (*size > CIFSMaxBufSize + MAX_SMB2_HDR_SIZE - + sizeof(struct smb2_set_info_req)) { + cifs_buf_release(req); + return -EINVAL; + } + req->BufferLength = cpu_to_le32(*size); memcpy(req->Buffer, *data, *size);