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 1B62A3161BF; Tue, 21 Jul 2026 17:11:28 +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=1784653889; cv=none; b=k7PmBaLRm9V/Ch+daY//l1GZKbMFaf6JIthzGoHOm/SHlQBWFOh+Ysc2J3u5fmuFkDLiHyP7gNnAZ/XG+fbm2fvtzThHAnNx0+cpIw6n6TyYSt0CHx7dEjnR3CV6wdj2A4ITuf/+xstzc7G2OBOjVQRYdyDlIe5+nZkpVB8djCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784653889; c=relaxed/simple; bh=XTfboICzTK2GntrRW6jb6SD6MYXg8mZvRpfp7gvxJww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R+hXXumaMbdxRnb869YEz4lrs5ycv+ukweTcDaSHcQKZKAj7nggcnM7jd8N1VuObuKHWyosCTYOy5Y+IsZhz38MikbsBQJYNDqjJPyakj/kZfhzIOJGQh83V4SX1yYoWgE7EXRgMpCfQiIECw2VL+DevQdIIUufoT2+Yk8YOiGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nuiONLzy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="nuiONLzy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81E5D1F000E9; Tue, 21 Jul 2026 17:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784653888; bh=oy92NFh+4RH08973OGGdRJAyPNkJKCIum5VcK7HBKls=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nuiONLzymX35RtWEIP/R8uRHp2oIXSx47XpAJAAkO/gV3g/Fg5YWOKvnS3ixY/uV0 27Qs88hH1qOZhNQ7+KueIbCcUhUz2ej5huYFMMI2ry6E0uJdJIqViYQdk6X5970hoU UeEnb7H4jQlo2KNYjLJIGEIT9aZu1wSfANOMOLas= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Steve French , Sasha Levin Subject: [PATCH 7.1 1497/2077] cifs: validate DFS referral string offsets Date: Tue, 21 Jul 2026 17:19:30 +0200 Message-ID: <20260721152628.097814223@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit 027a84ac6b50c12ef767c15abfc58aa865820e9e ] parse_dfs_referrals() validates that the response header and referral array fit in the received buffer, but each referral also contains string offsets supplied by the server. Those offsets are used to compute the DfsPath and NetworkAddress string pointers without checking whether they still point inside the response buffer. A malformed referral can therefore make the computed pointer exceed the end of the buffer. The resulting negative max_len is then passed to cifs_strndup_from_utf16(), and the non-Unicode path forwards it to kstrndup() as a size_t, allowing strnlen() to read out of bounds. Validate each string offset before deriving the string pointer. Fixes: 4ecce920e13a ("CIFS: move DFS response parsing out of SMB1 code") Signed-off-by: Guangshuo Li Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/client/misc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 0c54b9b79a2ce5..ee1728eec8aa0a 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -752,6 +752,10 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size, node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); /* copy DfsPath */ + if (le16_to_cpu(ref->DfsPathOffset) > data_end - (char *)ref) { + rc = -EINVAL; + goto parse_DFS_referrals_exit; + } temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); max_len = data_end - temp; node->path_name = cifs_strndup_from_utf16(temp, max_len, @@ -762,6 +766,10 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size, } /* copy link target UNC */ + if (le16_to_cpu(ref->NetworkAddressOffset) > data_end - (char *)ref) { + rc = -EINVAL; + goto parse_DFS_referrals_exit; + } temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); max_len = data_end - temp; node->node_name = cifs_strndup_from_utf16(temp, max_len, -- 2.53.0