From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385550; b=JxKsEOawTCV4h1qIAPUz3AcnbRPQ2xrbfW4MobcwpDa3Sh43zObwgB3hq/xN5NfREMeC chHIHvJIwxwkGayQ/XsfokHdNp0iqYuS3Dqz3ZrTZoilwI3JNfI8nXNSIjj9bbGcbBJ5g gDHQOz6YSoRD0nUY0lMqj9pBX9w/X2JMEkP5WZVteYWTOEOFZXKwfQhWakRXoAfOlrgCi TapOqjNET7HlsmxRhiyy5et+6iis0rW6SMcD8SOE6jO69RLotlaTZcSC2meqPKJR3duzS XMa67CtzBGhi6LRzq9XSwCblXmDgWfvNT9jPz8YrHvr8cXeMe1hb/DGriJiTy7DUDDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385550; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=a8Yf1J+GVIaf0nK5/uNSXNIZKLMVEOI7pq4M+CuW1fU=; b=hwDTBE/iYbIqNhsKZrw45owVzS3S59qUsqnZcF6k4DjPqRlnxB9aGlOOW/t0UGAPPeGm qVgybvqc7oJLREZxjHaYTAszsO28Dn2uvt6CaTihm8Y6+QXujQ5I55K48Fq4zV8uuZYsM IhGyMG6mc8+EnRAeB/rODLUbV19EObymUzNZQPvFtxSg6XJrB4Qin6XSNSg57T88/whOX fr9IW0Xrm3xH/6VX5gMXd3IYVtnsSmzTvq0G+7Fvam097g1JMw8Y+ayhIQ76rawT/2NgP vAqW1tDV96e62zPrcuHnWBaFbyyGv44jleYHT3OWvYea8q0tGlM3zwx//4NcKd5q4DA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="Bh4i/WNr"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18C43606A322; Fri, 4 Dec 2026 11:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Bh4i/WNr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D4A11F000CE; Fri, 4 Dec 2026 11:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385549; bh=a8Yf1J+GVIaf0nK5/uNSXNIZKLMVEOI7pq4M+CuW1fU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Bh4i/WNrDpFzwo5/3YTqj4uW85lYK3oIVEjiCw/O2SRiv9DniZLJQKzLvJujGMJ9T EoGkXfpKriTy/CgOKOy4pILLPAWNqTNHGgbHv1e0cuFmoJQk57v40Z1sxWia7Tm4+3 LQcA5GOb0yviQAhACZUB9+vwbZS/1g55b3AT5oYo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fredric Cover , Namjae Jeon , Paulo Alcantara Subject: [PATCH 6.6 0597/1167] smb: client: fix out-of-bounds read in dfs_parse_target_referral() Date: Fri, 4 Dec 2026 19:00:24 +0900 Message-ID: <20261204100717.604798819@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fredric Cover commit 86aacc2f3f6ba18e1d87feee24f37c94b3ce863a upstream. dfs_parse_target_referral() decides whether a prefix path remains after the consumed part of full_path with: if (strlen(full_path) - ref->path_consumed) strlen() returns size_t, so if path_consumed is larger than the length of full_path, the subtraction wraps around to a huge non-zero value. The branch is then taken, prepath is set to a pointer past the terminating NUL of full_path, and *prepath reads out of bounds. path_consumed can exceed strlen(full_path) when the mount charset is not utf8. The referral code derives path_consumed from the canonical path, which is in the DFS cache charset (utf8), but it is applied here to full_path, which is in the mount charset. Each non-ASCII character in the consumed part of the path that is longer in utf8 than in the mount charset makes the count too large by the difference. This was reproduced with iocharset=iso8859-1 against a Samba DFS root containing a link named "café", mounting with the single Latin-1 byte 0xe9 in the path. On an unmodified tree such a mount fails earlier with -ENOENT because the path is converted to utf8 twice in setup_dfs_ref(); with that fixed ("smb: client: fix double conversion of DFS path in setup_dfs_ref()"), the mount reaches this code. full_path was 29 bytes while path_consumed was 30: BUG: KASAN: slab-out-of-bounds in dfs_parse_target_referral+0x26a/0x270 Read of size 1 at addr ffff88810db89d5f by task mount/1743 ... The buggy address is located 0 bytes to the right of allocated 31-byte region [ffff88810db89d40, ffff88810db89d5f) Compare path_consumed against the string length instead of subtracting, so that no prefix path is used when the consumed count covers the whole string. With the bounds check in place the same mount succeeds and no KASAN report is produced. This only prevents the out-of-bounds access. path_consumed is still in the wrong units, so a non-ASCII link followed by a path component can still produce a wrong prefix path. That needs a separate fix. Signed-off-by: Fredric Cover Cc: stable@vger.kernel.org Reviewed-by: Namjae Jeon Signed-off-by: Paulo Alcantara Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/dfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/smb/client/dfs.c +++ b/fs/smb/client/dfs.c @@ -31,7 +31,7 @@ int dfs_parse_target_referral(const char if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0)) return -EINVAL; - if (strlen(full_path) - ref->path_consumed) { + if ((size_t)ref->path_consumed < strlen(full_path)) { prepath = full_path + ref->path_consumed; /* skip initial delimiter */ if (*prepath == '/' || *prepath == '\\')