From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00E92393DD8 for ; Mon, 30 Mar 2026 18:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774895902; cv=none; b=hpIGnxZAc+qLMgtKDsBiKw2EK3vPnKimt7fkDi7sX6jZ3LnwFuDxrIyouv7Yno6po5Yag7B0X/oomY/P0MQfZI3bFHeJa60esjF0MLTkOcVDDGBR5VS7cx7XMTFiXzxItmZ5UgDll9pblTnRdKl5tQ8JlmajQhPQ1GWl/xnsal4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774895902; c=relaxed/simple; bh=M80uT1gxQXQVGkZ9zW6yu7rw0HwwMGrBrWsP3/+DcrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EYsoI/OXgwnlqiqz2G48P1nvqCkaQFEFmOP/cAZh5nklSdwuVCQOBcyURp4ClQgLj8SLUE8hut95TvDsz5I2iBoP9VniSvZuLME2CEgmGvmu2e+rPEUVVfI9NiV2z+3ADAC5YfMrtGYZlPGyhMgiovIv5hhjPsO6sbjDI/DS8wo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BIoP7H0C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BIoP7H0C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC270C4CEF7; Mon, 30 Mar 2026 18:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774895901; bh=M80uT1gxQXQVGkZ9zW6yu7rw0HwwMGrBrWsP3/+DcrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BIoP7H0CJ+UQGwhZKzGB6u2zqkcd/K3s1gZiYWnoycNpvTV/dqbavKdyR2bgHygMM B1Bu6ove+croKC9NeePH07d7StZapIpSkjWhmLw69YElJ3+Ko1ooKnXb7rZVSlwJUk iIGsq+QWEhj9GAKDhJSe+cI9DnV++9WctBzRCqvfOs9Uyomyr57+l4n2j9dAONmZxo Xqek76MaWCVdJRCP8pcELqqgC1HvN0fAUBMnEiX5k8UzyEzBFiDP2FSTP3k2HXa5lU HRTtO0au5RfP57QGYF8AuhCZja07j5GgOO7uS+cHfFe/Dnwc/mTEqsctEGv2d8TO+g 3Xw3Lxlg6sfSw== From: Sasha Levin To: stable@vger.kernel.org Cc: Namjae Jeon , Asim Viladi Oglu Manizada , Steve French , Sasha Levin Subject: [PATCH 6.1.y] ksmbd: fix potencial OOB in get_file_all_info() for compound requests Date: Mon, 30 Mar 2026 14:38:19 -0400 Message-ID: <20260330183819.950934-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026032931-kilobyte-catchy-1ad2@gregkh> References: <2026032931-kilobyte-catchy-1ad2@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Namjae Jeon [ Upstream commit beef2634f81f1c086208191f7228bce1d366493d ] When a compound request consists of QUERY_DIRECTORY + QUERY_INFO (FILE_ALL_INFORMATION) and the first command consumes nearly the entire max_trans_size, get_file_all_info() would blindly call smbConvertToUTF16() with PATH_MAX, causing out-of-bounds write beyond the response buffer. In get_file_all_info(), there was a missing validation check for the client-provided OutputBufferLength before copying the filename into FileName field of the smb2_file_all_info structure. If the filename length exceeds the available buffer space, it could lead to potential buffer overflows or memory corruption during smbConvertToUTF16 conversion. This calculating the actual free buffer size using smb2_calc_max_out_buf_len() and returning -EINVAL if the buffer is insufficient and updating smbConvertToUTF16 to use the actual filename length (clamped by PATH_MAX) to ensure a safe copy operation. Cc: stable@vger.kernel.org Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound") Reported-by: Asim Viladi Oglu Manizada Signed-off-by: Namjae Jeon Signed-off-by: Steve French [ adapted variable declarations ] Signed-off-by: Sasha Levin --- fs/smb/server/smb2pdu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 65b55e824aa8b..868b797d90d44 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -4598,6 +4598,8 @@ static int get_file_all_info(struct ksmbd_work *work, int conv_len; char *filename; u64 time; + int buf_free_len, filename_len; + struct smb2_query_info_req *req = ksmbd_req_buf_next(work); if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) { ksmbd_debug(SMB, "no right to read the attributes : 0x%x\n", @@ -4609,6 +4611,16 @@ static int get_file_all_info(struct ksmbd_work *work, if (IS_ERR(filename)) return PTR_ERR(filename); + filename_len = strlen(filename); + buf_free_len = smb2_calc_max_out_buf_len(work, + offsetof(struct smb2_query_info_rsp, Buffer) + + offsetof(struct smb2_file_all_info, FileName), + le32_to_cpu(req->OutputBufferLength)); + if (buf_free_len < (filename_len + 1) * 2) { + kfree(filename); + return -EINVAL; + } + inode = file_inode(fp->filp); generic_fillattr(file_mnt_user_ns(fp->filp), inode, &stat); @@ -4640,7 +4652,8 @@ static int get_file_all_info(struct ksmbd_work *work, file_info->Mode = fp->coption; file_info->AlignmentRequirement = 0; conv_len = smbConvertToUTF16((__le16 *)file_info->FileName, filename, - PATH_MAX, conn->local_nls, 0); + min(filename_len, PATH_MAX), + conn->local_nls, 0); conv_len *= 2; file_info->FileNameLength = cpu_to_le32(conv_len); rsp->OutputBufferLength = -- 2.53.0