5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yifan Zhang [ Upstream commit e49296d51ccbf2ad0ed0484db1382f1d7217bd6e ] smb2_set_ea() verifies that the byte reserved for the declared EA-name terminator lies inside the request, but it does not verify that the byte is zero. With SMB debug logging enabled, the name is passed to %s and the diagnostic reads beyond the request allocation. KASAN reports: BUG: KASAN: slab-out-of-bounds in string Read of size 1 string vsnprintf _printk smb2_set_ea smb2_set_info Reject an EA entry whose declared terminator byte is nonzero. Return -EBADMSG for the malformed buffer, and map that error to STATUS_EA_LIST_INCONSISTENT for both SET_INFO and CREATE. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Suggested-by: Namjae Jeon Signed-off-by: Yifan Zhang Signed-off-by: Namjae Jeon Signed-off-by: Sasha Levin --- fs/ksmbd/smb2pdu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index e992775476981..bb4695b61ec39 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -2425,6 +2425,11 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, if (!eabuf->EaNameLength) goto next; + if (eabuf->name[eabuf->EaNameLength]) { + rc = -EBADMSG; + break; + } + ksmbd_debug(SMB, "name : <%s>, name_len : %u, value_len : %u, next : %u\n", eabuf->name, eabuf->EaNameLength, @@ -3574,6 +3579,8 @@ int smb2_open(struct ksmbd_work *work) if (rc) { if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EOPNOTSUPP) rsp->hdr.Status = STATUS_NOT_SUPPORTED; else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) @@ -6293,6 +6300,8 @@ int smb2_set_info(struct ksmbd_work *work) rsp->hdr.Status = STATUS_ACCESS_DENIED; else if (rc == -EINVAL) rsp->hdr.Status = STATUS_INVALID_PARAMETER; + else if (rc == -EBADMSG) + rsp->hdr.Status = STATUS_EA_LIST_INCONSISTENT; else if (rc == -EMSGSIZE) rsp->hdr.Status = STATUS_INFO_LENGTH_MISMATCH; else if (rc == -ESHARE) -- 2.53.0