Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8BA083A48C5 for ; Mon, 27 Jul 2026 12:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785154779; cv=none; b=gBJH7hr65mebU9qyb2YLJvR5Dhga/oLb/HT6lwLf3BSCE0N/uGK08VtSgo/P8viNoNDCB8gEIJZeO+/Szje0ghuutkLRvOmdwcP0tdSY0IjMWmcRTPmW7+goVAVcjTk8IN/qpzjGsfYfkq2/Fq2mpP0+dEqHlHmqMS7/Zsf/84M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785154779; c=relaxed/simple; bh=4kyme8MORGzm4T6aH6w3yfDNjmBxWxoavVQN1Ukk8fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEct/Gni3fAMjoCf7x/kESPWiuqNhZjhdpP361NRoLedAbx/68O0URmvmSmJYPbtKP204KpTfT9Yh7I40tSfkaH327q+HyS93s4yYUCuydTqdtJKwHpF8Lp1Qvg36aAr4rsSvD7MHnVO9TfzH5muhscPLvNsDfbVI8iS6Tmk19M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CJIkZwcb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CJIkZwcb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A1631F000E9; Mon, 27 Jul 2026 12:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785154776; bh=56bLdtYKvKjKkf5jsOkTZ9kt2ZSs0AXjdZoaeh7nA3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CJIkZwcbzoH3YWpRPoMbei97NBfxJ59MqzK/6lMwsa43nLHI+2g2DxOSGtvamhGa/ BkIWrLY2aWI+q2Q6LLpc4w8l0TF+UaP/At1yUsOLN96yUfTyK8D0Gu3U8yJGu1hcFw n/ihkhOxhJVveDYc5TuD5Q6ETSAIqcXOrpMgIjn6xSI2cKMUg4aKW4QXl73hxZtIr0 2rTMH18tUbbIh74LbDq6Dc5qqkbyQ/P7c8eYPC80gje5K6ZVQVm1lbXFZ6cS7rQQI2 B8vNU4e8QVELFDTjPHIoEt+gt6S4KLmZ5b59XEG7bfeSHmYOOqso57cJI24WelQh0I +GwDDql41wkzQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Ibrahim Hashimov , Namjae Jeon , Steve French , Sasha Levin Subject: [PATCH 5.15.y] ksmbd: fix integer overflow in set_file_allocation_info() Date: Mon, 27 Jul 2026 08:19:34 -0400 Message-ID: <20260727121934.3777423-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026072024-headphone-posh-4ed4@gregkh> References: <2026072024-headphone-posh-4ed4@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: Ibrahim Hashimov [ Upstream commit 1c0ae3df692ea2a4ce992f786346154e75a3f0d5 ] set_file_allocation_info() converts the client-supplied FILE_ALLOCATION_INFORMATION::AllocationSize into a 512-byte block count with: alloc_blks = (le64_to_cpu(file_alloc_info->AllocationSize) + 511) >> 9; AllocationSize is a fully client-controlled __le64 field; the only validation performed by the caller (smb2_set_info_file(), case FILE_ALLOCATION_INFORMATION) is that the fixed buffer is at least sizeof(struct smb2_file_alloc_info) == 8 bytes. The value itself is never range-checked before this arithmetic. When AllocationSize is close to U64_MAX (e.g. 0xffffffffffffffff), "AllocationSize + 511" wraps around mod 2^64 to a small number (0xffffffffffffffff + 511 = 510), so alloc_blks becomes 0. Since any existing regular file has stat.blocks > 0, the function then takes the "shrink" branch and calls: ksmbd_vfs_truncate(work, fp, alloc_blks * 512); /* == 0 */ silently truncating the file to size 0, even though the client asked to grow the allocation to (what looks like) the maximum possible size. The trailing "if (size < alloc_blks * 512) i_size_write(inode, size);" restore is guarded by a comparison that is never true once alloc_blks == 0, so the truncation is not undone. This lets an authenticated SMB client that already holds an open handle with FILE_WRITE_DATA on a file silently truncate that same file to size 0 via a single crafted SET_INFO(FILE_ALLOCATION_INFORMATION) request advertising a near-U64_MAX AllocationSize, even though the request asks to grow the file's allocation rather than shrink it. This is a functional/data-loss bug, not a privilege-boundary violation: the same client could already truncate the file via FILE_END_OF_FILE_INFORMATION or a plain write. Fix it by validating AllocationSize against MAX_LFS_FILESIZE, the same upper bound the VFS itself uses to reject unrepresentable file sizes, before doing the "+511" rounding, and rejecting oversized values with -EINVAL. Bounding AllocationSize to MAX_LFS_FILESIZE - 511 guarantees the "+511" addition cannot wrap, and that the subsequent "alloc_blks * 512" values passed to vfs_fallocate() and ksmbd_vfs_truncate() stay within a representable loff_t as well. No legitimate SMB client asks for an allocation size anywhere near 2^64 bytes, so this only rejects a value that was previously silently misinterpreted as zero. Runtime-verified on a v6.19 KASAN test stand: sending SET_INFO (FILE_ALLOCATION_INFORMATION) with AllocationSize = 0xffffffffffffffff against ksmbd now returns -EINVAL and leaves the target file's size unchanged, where the unpatched kernel truncated it from 4096 to 0 bytes. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Signed-off-by: Ibrahim Hashimov Assisted-by: AuditCode-AI:2026.07 Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/ksmbd/smb2pdu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index f7eeb79be48ab5..056ebc5dfed67f 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -5814,6 +5814,7 @@ static int set_file_allocation_info(struct ksmbd_work *work, */ loff_t alloc_blks; + u64 alloc_size; struct inode *inode; struct kstat stat; int rc; @@ -5826,7 +5827,19 @@ static int set_file_allocation_info(struct ksmbd_work *work, if (rc) return rc; - alloc_blks = (le64_to_cpu(file_alloc_info->AllocationSize) + 511) >> 9; + /* + * AllocationSize is fully client-controlled (the caller only + * validates the fixed 8-byte buffer length). Reject values that + * would overflow the "round up to 512-byte blocks" conversion + * below instead of silently wrapping it to a tiny block count, + * which would truncate the file to a size the client never + * asked for. + */ + alloc_size = le64_to_cpu(file_alloc_info->AllocationSize); + if (alloc_size > MAX_LFS_FILESIZE - 511) + return -EINVAL; + + alloc_blks = (alloc_size + 511) >> 9; inode = file_inode(fp->filp); if (alloc_blks > stat.blocks) { -- 2.53.0