From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796499789; b=zcW85ReSOVqNd+7FD9z7k0mGixOdh/iqt1B7hRdpTbk/ca447X427T/MTBXqgaSwTNDo 50bHTBiSW7fd3H9Uw68FptYTPLnFSp1Brei67RmZpmSBnPOOqojevtERHgpy1BDkRmhkE p10hCrlqkcczGjK9ArppQO7MJbRMnTenCafldpUUQgkdh6a/vdNOwT4B3l1GWp+9IqYJK 3ovGEEUa3NqaQJJRTtz/PGiUHNwmVQBKvJFukvLZT5F6DWWo3UdNMNplQch4EA7o/d5RF KlYVDcm51h1TamOGPgp/L1uqDUEFmvQl3TW4aTsXjolSUyJE4UcEub/oPUZXkp7xzvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499789; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=1SLCZk75xTd2c0/o7JdOqIXiJGJkvqiOaGJLQGDpBn4=; b=O92rZeRzjNJMvHgAO+T75NVCBoVFSqPSCB8pfOYXNhcF6hTT/NDNvB2el82yVsbUt1kl Z9wWM49RuBlQAqMR2JumyHZMqALQ4sQgXYFB/D/46GIzssNqRPhwYH3e1F2LSjqKhYt5X /zK9CRD50Df649ss5P967Qw9mSgrTmPtB/ou/hFcx2NqqDNNPrJ035vf50hoTPQ0T94X8 Zp2LXg0FbosqU7G+FgGBEAg/dXxGVzTP56k0nfjEHk6/eSyg2bBGVlChGEcgy3iPjAwgL gutsAPZ9n8ycrqJ7ZHBmrCt9UOdLQNQATeaY6u5zviriViXCsSpfCk6vwDImt6yAYRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b="fWsN2wV/"; arc=none smtp.remote-ip=74.125.82.47 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1C53606A31F for ; Sat, 5 Dec 2026 19:43:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1C53606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=fWsN2wV/ Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-15ea896ddc8so2744981c88.0 for ; Sat, 05 Dec 2026 11:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796499788; x=1797104588; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=1SLCZk75xTd2c0/o7JdOqIXiJGJkvqiOaGJLQGDpBn4=; b=fWsN2wV/uKYSTbdpWoU8Zm0TjPT0jFcEaG+3LZu8eKhSjQ7tHKhyG/N4tlAHWgJ4Mz KuemwDmQJD+3H5bAVK26s2s8B6Yyx1U+im74rn/xArf37iImfQ8wvG8s4xyP7tGl2HI7 cfMnlKKwFS5BheVloDdOavyEzgsSTn1m69W0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796499788; x=1797104588; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1SLCZk75xTd2c0/o7JdOqIXiJGJkvqiOaGJLQGDpBn4=; b=q8XN7ZTjBSh7MK5l0MiIyhJ3pOPx/hnYmCWCZ0kRkXMWivEGaeSLSqdGzr22uKBJeO +J4A38wmNXwbZCU2tbwLeXTSTVafK6RZDuTLdsUOsTzyu5lmr/vf/B2lum5X+cAikqky Hx516HxGPU6SJiSw3U9fWTEJE1ngICUrbyjAsxQ4gD+TPofn1YeIjqFU3mz6RllJa870 MfQqIYbiah4ntqQmSpzgP4jaAK0c4ROeSiuhRmbn2wnIyyMy9amkEcS34bx+yibuQt4e zz27h/BmQ1JxUnQ03otCOVd0DseWhIXk8Co9QemQcfTpqCi8FM+oyVsTlXoZCo1pAvkX VUwA== X-Forwarded-Encrypted: i=1; AL+hErG8KnSpUDJfzZdA2oGiRRomK8peori2Ca5wVPuXIQWMVOyASaV8uRwqT7/Y2FJhaWr51VKn4J+WGifVGfs=@vger.kernel.org X-Gm-Message-State: APuU4Z9AxbxehxZF59G0fhOgexDfIUeJh63J6J3I1hUJcPTWxkbgJz4c PnkNWi3SPN7gl9g/Sgo779Y3FWcOWJjqSE/Ppy4lTM8lgcGctNMByq9pFKmFXgfmf1KfM/clE8D Nne3CubHvXA== X-Gm-Gg: AZFdTZeNWdZ7+ayvGhtxK4Tmd4VkkBZnHAmjWSvgk1zls/PZx4pQChs2P3Pi+y7e4ya oeUDchlreS4MKvNGgsyoP6/WLW4mGAZgylZkZ10Tkph1GR7MAi9uVmhJEcCjB3zFifYlP90dkEP 754B+ilNedlYSLLbMrJvZK4g7o8Gxgoz+HLegvvmjeHj23v+LD8Egk2ARpczuJ3tHeY3OGZ/zIb bUqNg+atEsDGEMXG08O9QOhezCMUrYWv1f4hF9EIV/3Zue/bSGy5vSXFoFbAKsqguWegagEbJCD P1mFu09iYhMDsRF4dwDtsjR2M778ORU3irMZT10ShPFo8zo0bulun2b00ifEUTSmIXzcXn3+IwJ jn/TQSU1DT+EUFaqYy1UpcVkgW3JjjUkULsz538spWNllNl++1Xxrslg8DiuT3Z3Or40EZ2CaE2 YC+3DaxrOydwP5S7DzmgaLRi1IVHIr8N/CZ8quEn/ctfZDCL0OxoWyjafFy0o4PhyL4QVXksb1G +rcYMYnEJbo1pQ12apNFHWgshLjYQkbeB3ZZvF3TNMfgbRQSr9a+OmmEsTvtfzysvHB75OXjmi8 4B8M+8u5xKmGt+Lf+QGJuv2r7i3jye+fVQ5nvp9xQOoot9gr0XVWveHO8NjQ6DkvhF0rdXPGRrq +mXnAl+ST2jLeGhX88ztD214jORST8owZXtC+YglKui079XsMDF0KopsB/IXIXx7HEw== X-Received: by 2002:a05:701b:240b:b0:1a3:87c8:7efc with SMTP id a92af1059eb24-1b5d7119a27mr4995809c88.39.1796499787833; Sat, 05 Dec 2026 11:43:07 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d646217esm17267824c88.11.2026.12.05.11.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 11:43:07 -0800 (PST) From: Piyus Kedia To: Paulo Alcantara , Namjae Jeon , linux-cifs@vger.kernel.org Cc: Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] smb: client: a DFS target path longer than PATH_MAX is written past its UTF-16 buffer Date: Sun, 6 Dec 2026 01:13:01 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, cifs_strndup_to_utf16() sizes its buffer for at most maxlen bytes of the string and then converts the whole string: fs/smb/client/cifs_unicode.c:621 (cifs_strndup_to_utf16) len = cifs_local_to_utf16_bytes(src, maxlen, cp); len += 2; /* NULL */ dst = kmalloc(len, GFP_KERNEL); ... cifsConvertToUTF16(dst, src, strlen(src), cp, remap); cifs_local_to_utf16_bytes() stops after maxlen bytes. cifsConvertToUTF16() with remapping - SFM, the default, or SFU with mapchars - converts srclen bytes, here up to the end of the string; without remapping it calls cifs_strtoUTF16(target, source, PATH_MAX, cp) (cifs_unicode.c:452), which stops after PATH_MAX. Two callers pass maxlen = PATH_MAX: fs/smb/client/smb2misc.c:539 (cifs_convert_path_to_utf16) return cifs_strndup_to_utf16(start_of_path, PATH_MAX, &len, cifs_sb->local_nls, cifs_remap(cifs_sb)); fs/smb/client/smb2ops.c:3274 (smb2_get_dfs_refer) utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX, &utf16_path_len, nls_codepage, remap); so a remapped path longer than PATH_MAX bytes is written past the end of the buffer: two bytes for every character after the ones it was sized for, then the two-byte terminator. The other callers pass strlen(src) as maxlen. We reached only the first. smb2_get_dfs_refer() gets no remapping from the DFS cache (dfs_cache.c:692), so there the conversion stops at PATH_MAX; it is called with cifs_remap() only from cifs_inval_name_dfs_link_error() (misc.c:1069), which we did not try. Such a path reaches cifs_convert_path_to_utf16() in a DFS mount. The prefix path is taken from the target that the server's referral names (dfs_parse_target_referral() -> smb3_parse_devname(), dfs.c:48-53, fs_context.c:682, which do not bound it), cifs_build_path_to_root() builds the path from it and cifs_is_path_remote() converts that path (connect.c:3868-3875). With a referral to \127.0.0.1\s2\ followed by 5000 'A': BUG: KASAN: slab-out-of-bounds in cifsConvertToUTF16.part.0 (fs/smb/client/cifs_unicode.c:562) Write of size 2 at addr ffff88804d906002 by task poc/9451 cifsConvertToUTF16.part.0 (fs/smb/client/cifs_unicode.c:562) cifs_strndup_to_utf16 (fs/smb/client/cifs_unicode.c:628) cifs_convert_path_to_utf16 (fs/smb/client/smb2misc.c:539) smb2_is_path_accessible (fs/smb/client/smb2ops.c:984) cifs_is_path_remote (fs/smb/client/connect.c:3875) dfs_mount_share (fs/smb/client/dfs.c:236 fs/smb/client/dfs.c:274 fs/smb/client/dfs.c:291 fs/smb/client/dfs.c:385) cifs_mount (fs/smb/client/connect.c:3942) cifs_smb3_do_mount (fs/smb/client/cifsfs.c:1132) smb3_get_tree (fs/smb/client/fs_context.c:917) vfs_get_tree (fs/super.c:1881) ... __x64_sys_mount (fs/namespace.c:4540) page last allocated via order 2, ... (poc) ___kmalloc_large_node (mm/slub.c:5470) __kmalloc_noprof (mm/slub.c:5519 mm/slub.c:5556) cifs_strndup_to_utf16 (include/linux/slab.h:995 fs/smb/client/cifs_unicode.c:623) cifs_convert_path_to_utf16 (fs/smb/client/smb2misc.c:539) ... Memory state around the buggy address: >ffff88804d906000: 02 fe fe fe fe fe fe fe fe fe fe fe fe fe fe fe ^ The buffer is 2 * 4096 + 2 = 8194 bytes, a kmalloc_large (order 2) allocation starting at ffff88804d904000, and the report is for its first byte past the end. With multi-byte characters it is smaller. In a mount whose local charset is utf8 a target of 1500 U+4E00 is 4500 bytes, the first 4096 of which hold 1366 characters: BUG: KASAN: slab-out-of-bounds in cifsConvertToUTF16.part.0 (fs/smb/client/cifs_unicode.c:562) Write of size 2 at addr ffff888046ed6aae by task poc/9452 ... The buggy address belongs to the object at ffff888046ed6000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 0 bytes to the right of allocated 2734-byte region [ffff888046ed6000, ffff888046ed6aae) How it is reached. The reproducer is a minimal SMB 3.0 server on loopback and a mount of //127.0.0.1/dfs in the same program, with ordinary options (user=, pass=, vers=3.0; iocharset=utf8 for the second case). The server accepts NTLMSSP as guest and answers FSCTL_DFS_GET_REFERRALS with one V3 root referral whose target is the long path. The client follows it, tree-connects to s2 and converts the prefix path in cifs_is_path_remote(); the server answers the CREATE with STATUS_OBJECT_NAME_NOT_FOUND, and the mount fails with ENOENT after the report. The CREATE carried the name read back from the overrun buffer: 8192 bytes of 'A' (SMB2_open() sends at most PATH_MAX characters) and, in the second case, 3000 bytes of U+4E00, 266 of them from past the 2734-byte object. A 100-character target takes the same route with no report and a 200-byte name in the CREATE. With "nomapposix" the 5000-character target gave no report: cifs_strtoUTF16() stopped after PATH_MAX characters, and the CREATE carried the first 4096 characters of the path, so the client looked up a shorter path than the one the referral named. Impact - who can trigger it: - The SMB server that answers the client's referral request. Unless the mount has "nodfs", dfs_mount_share() asks the server it mounts for a referral (dfs.c:363-364) and follows the target it gets, so any server a client mounts can trigger it; from the code, so can a server that a referral sends the client to, which the walk asks for the next referral when it answers STATUS_PATH_NOT_COVERED. Our server accepted the client's NTLMSSP authentication without checking it. The prefix path is bounded only by the size of the referral response, which the client takes if it fits in CIFSMaxBufSize, 16384 bytes by default, plus the header (connect.c:1200), so the server can name some 8000 characters. - It needs the default SFM mapping or mapchars; with "nomapposix" there is no overflow (above). It also needs a utf8 local charset, from iocharset=utf8 or CONFIG_NLS_DEFAULT="utf8" (the setting in the kernel we tested, and in the Ubuntu 6.8 kernel of our test host). Since fa72921a0c9b ("smb: client: convert DFS target node name from cache charset on mount"), in 7.4-rc5, the target is converted from the DFS cache's utf8 to the local charset when the two differ, without remapping, and that conversion stops after PATH_MAX characters (dfs_cache.c:129-134). With iocharset=iso8859-1 the 5000-character target gave no report, and the CREATE carried 4082 characters: the 4096 that conversion kept, less the \127.0.0.1\s2\ in front. Before that commit the target went into the prefix path as the cache holds it, so on earlier kernels the local charset should not matter; we did not test an earlier kernel. - A local unprivileged user cannot trigger it directly: mount(2) of cifs needs CAP_SYS_ADMIN in the initial user namespace (the filesystem is not FS_USERNS_MOUNT). Where an administrator allows user mounts through mount.cifs, the server is the one the administrator configured; we have not tested that. - What the write does. The conversion writes the UTF-16 form of the path, after the client's remapping of the reserved characters, two bytes per character, so the server chooses how far past the buffer it goes and, within what a path can hold, what is written there. Booted with kasan_multi_shot=1, a 4100-character target gave four reports, for the two-byte writes at offsets 8194, 8196, 8198 and 8200 of the 8194-byte buffer: three characters and the terminator. With ASCII the buffer is at the start of a 16 KiB order-2 allocation, and with the default CIFSMaxBufSize a referral alone cannot make the path long enough to write past those 16 KiB: KASAN reports the write, but nothing else is in those pages. With three-byte characters the buffer is a kmalloc-4k object, and from the sizes a target of more than 2047 such characters would write past the object's 4096 bytes into the next one on a kernel without KASAN (KASAN lays the cache out with more room per object); we have not run that, nor tried to make anything of it. Seen on 7.4.0-rc5, where the fuzzer's referral (the same 5000 'A') gave the same report at the same lines (cifs_unicode.c:628, smb2misc.c:539, smb2ops.c:984, connect.c:3875, dfs.c:236, an 8194-byte buffer), and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04), whose fs/smb/client differs from mainline (c3500c5ef648, 2026-12-04) only in smbdirect.c, with KASAN: the 5000-'A' referral gave this report in 4 of 4 boots, and the 1500-U+4E00 one the kmalloc-4k report in 3 of 3. The 100-'A' control gave none in 2 of 2, and neither did the 5000 'A' with nomapposix or with iocharset=iso8859-1 (1 boot each). The code is the same in cifs-next (9b62aa64ed00, 2026-12-03). The mismatch dates from 2503a0dba989 ("CIFS: Add SMB2 support for is_path_accessible"), v3.6, which added cifs_strndup_to_utf16() and cifs_convert_path_to_utf16(); remapping then needed mapchars. Since 2baa2682531f ("Remap reserved posix characters by default (part 3/3)"), v3.18, SFM remapping is the default. A patch follows in reply to this mail. It makes cifs_strndup_to_utf16() return NULL for a string longer than maxlen, before it allocates, so the conversion never writes more than was allocated. The callers report NULL as -ENOMEM. On ksmbd-for-next, same config and image, the patch the only change between the two builds: without the patch the reports above; with nomapposix no report, but the CREATE carries the first 4096 of the 5000 characters with the patch 5000 'A', 1500 U+4E00 and 5000 'A' with nomapposix: the client sends no CREATE for the long path and the mount fails with ENOMEM; no report in any of 9 boots, which ran the first 4 times, the second 3 times, the third once, and 4100 'A' with kasan_multi_shot=1 once both the 100-'A' control: no report, a CREATE with the 200-byte name, and ENOENT A clearer errno than ENOMEM would need the callers changed; we kept the patch to the helper. Whether the client should also refuse a referral target or prefix path longer than PATH_MAX where it parses one, in dfs_parse_target_referral() or smb3_parse_devname(), we leave to you. This was found by AI-driven fuzzing built on top of syzkaller; its analysis was then checked by hand against the code and every claim above was reproduced. The reproducer is fuzzer-generated, runs a minimal SMB server and the mount in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia