From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796465859; b=5iU2ArHW/5pFVN+Qu9vtsWFACr6dElLaq/dSITJY58d4u7h6c12cplVJWsrjdm3GCdam fTHBxHmPt7cZW0t9L5joRHRq6ITqLk7NrytCBjMp1kOtKjr0A68LNzO4gFEQ99FpnAuOR 9axjw3Tqz06jICBAvUgUUNFMbo4ErR3L0zLNgRmkfGkh1eZEIc46QIc/ZalAql2VT78Ur Tck9F/u9ztuxK0ozX5Q9UGxKROYgcLNzdNJuPw0O3M2nyPJMo65rscRmT4w4WL9EUZH4Z 4re807OHrwoYLb0hcZjJ4ITxPPidYAAW+b//0C+8WXq3fBVQm61Ny6clN2VKbs3oULQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796465859; 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=y3Wsy2zrsa/2MQjn8ZThB51OaTEEVlQYNpvlR9S/8JY=; b=XOmF1luabaH/pMeCmwCxvalQOoAzfoIplxpvbMV6K9IDSP3q0YkE4NXN941kOFU++mGE fSs7IsqoF4b0wyeQ5pQxdEiYgrvp4HxLzGAr788Ek1qSGssZYyMZfClldq/qs24P1xSUE AIpTLYdix4MVrOKNooz/XXJEwfohHiiaoXQdp7lzFG9fSXyL1uys9f3HldWo2cfW7nqc6 qf94G7/PnMy1WWtilBK9IYwQ1e4NBoBlWiN9uoFRFdtSpows6Zh7cqT+2ANXaX9wfvLT0 CknFOu/stlKQ5NVP0DcDWoBu/q1+NIdbbANG6DB18ijZE51Jtq6QHKX2XmmKgK6VjQw== 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=Mgn6FhtZ; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 21787606A322 for ; Sat, 5 Dec 2026 10:17:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 21787606A322 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=Mgn6FhtZ Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-386c336eab8so3573197eec.0 for ; Sat, 05 Dec 2026 02:17:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796465858; x=1797070658; 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=y3Wsy2zrsa/2MQjn8ZThB51OaTEEVlQYNpvlR9S/8JY=; b=Mgn6FhtZghzyTe5mzhGxhTuYpE60e2oJczuJr+VMBuVpcGl2hh5rVKyOmirg/tP2Pi V0hvxvG6VloKp9FesZtcFZuCD68mR1gOSmlb3baxT9jZDNc4igIfpdC4K1FUH8jq6kfz qnUruQQeKKAkWbnOPE8oaJkScM2qA3q5Lss10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796465858; x=1797070658; 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=y3Wsy2zrsa/2MQjn8ZThB51OaTEEVlQYNpvlR9S/8JY=; b=vn7NU4M24fVpGBIiTzs+JDLzdZyI9h2BuDT1LYAu/LhNkThte++4qQL3qKoR1G/g81 mRip/cVlph24lblyskJj7Ugtb6cFQw6gNz/4262NWjeu4CqhZQZ07BlOTvNO7qRfxoL7 NNcdyAc7YrF8pqJX878TS9Hty3VfldxgAgzx6Eq7f9D5R04GJTpIldbOIlfr8QZ5Ls7x rDy6bb9bKmwkmg73zBZZfpTHG6PtXzTpxrSnGB772A8uDcrFAMF0FWdjUXo97xBHeyn0 beCjPUOd3MDqVdJu07PYJ8F0ai/Mn2XPD0Ny8YyCv8Vl6qzLFCveIuycSDGa/wILrNPu 7Diw== X-Forwarded-Encrypted: i=1; AL+hErGveZIpT1YP8UfnaDp2CmjeAsLnq3bw9EBXtMP9KHAq2mmaTdD7CbqG34jf5EspQsIhy6Y+cpJAeXPR@vger.kernel.org X-Gm-Message-State: AB4q+uGb4eax7qe/RqQAZewHdPxqZte+Yvugs+LaViCHRUlHiSoLPc8S hgMEBU/IxQQFkK3rhPDGmNmd44ncmi5mCD/tX2AbqYo5wa44UE+sypZ0YCh6xGh1Zkm+rUayB9b yRTd2oYBs7g== X-Gm-Gg: AZFdTZcorBEVC0keWWfma6BuTxahFZtKtlBcyF57vd+7wfN0Pb/1nG29RqL1hPyN0Y4 t2PnvK6obfshW7SKT3T7XXojDKeCPUY46mygI0r7/clFWhORghZ0y8Gk2Rj2Fondyon0mR5lNJu 9sgOOODOPMtTT0cG9xm1sB9/CwQW+lF1JiQ2jE3rlUWdGwhFEMEWAjAgsxn2PzAh01gnvlywxp2 65gJ2nZhfZF1tBWqaEjDgOFwOlajiDk34FG5kVAT9p+bz+nWT8l1i1wqk+cJDnwsAUl7K4BwWFX lf7sWTN8ntawKIKkeU+yqtWhnOiOGN9JOtg8/YzBcgPsVrBqOwkuXpmcwOw4ZVOEc4d033Gj10Q bZ/dunVvNmCToBVuyS7qMVRLEttmUyYnSjesZ1+LyFOf/ByB7TSppFng1niZfuOfNSE4/RsMLoK 6u/vTc9pK+XQLvlBdYQz3F9cgvaOhNF28D1g6QyBWvRfk82AuIhiboPGrk0Qh8C4kQMiWluziXu r9/4wXKWwtrJMqrKCyW9DRNaUUobciNng+nCgaeVCh71AnID3CqGArE8sgq/9xCfVbKQVMOSICR 4nuOVH9wwKZxYrv/i7CvZ9wgYOH1bQGbsTG3qzZqvt7psp9uusxagtsD4oOLAraqgNUDyNcU+lt ifgJ1+xNKprbBl27R8I+fVTKe5P87h5Q0nAu1g4Nw9ZIgX4r5tBqEUMNAMWES0Hn+l/7G/5MkIz O6RqhnbYoXOw== X-Received: by 2002:a05:7300:dc10:b0:384:a3c5:35b8 with SMTP id 5a478bee46e88-38742cf7d1amr10303692eec.8.1796465858021; Sat, 05 Dec 2026 02:17:38 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5c89sm27857330eec.18.2026.12.05.02.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 02:17:37 -0800 (PST) From: Piyus Kedia To: Namjae Jeon , linux-cifs@vger.kernel.org Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] ksmbd: slab-out-of-bounds reads past a directory entry name in __query_dir() Date: Sat, 5 Dec 2026 15:47:32 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-cifs@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, __query_dir(), the iterate_dir() actor of SMB2 QUERY_DIRECTORY, gets each entry as the name and length the filesystem emitted, and the name need not be NUL-terminated. Three of its checks read it as a C string (fs/smb/server/smb2pdu.c:6836-6841 on ksmbd-for-next): if (!strcmp(".", name) || !strcmp("..", name)) ... if (ksmbd_share_veto_filename(priv->work->tcon->share_conf, name)) ... if (!match_pattern(name, namlen, priv->search_pattern)) Two of them can walk past the end of the name until they find a NUL byte, and on ext4 without dir_index that reaches past a slab object. 1. The veto check. ksmbd_share_veto_filename() matches the name against each pattern of the share's "veto files" list with match_wildcard() (lib/parser.c), which takes no length and walks while (*s). With a veto pattern that starts with '*', such as "*.tmp", it walks every name that does not match to its end and on. 2. match_pattern(). It is given the length, and walks fs/smb/server/misc.c:36 while (*s && len) { but len is decremented only when a character is consumed by a match (misc.c:40 and :53). When a mismatch after a '*' restarts the comparison one character further on, len is left alone: fs/smb/server/misc.c:56 if (!star) return false; str++; s = str; p = pattern; so it no longer says how much of the name is left. After a mismatch at the first character of an attempt it overstates it, and the walk goes on past the end of the name. For a name of 48 'a's and the search pattern "*Z", every attempt fails at its first character, len stays 48 throughout, and the 49th attempt starts at name[48]: attempt s at *s *p len 1 name[0] 'a' 'Z' 48 mismatch: str++, s = str 2 name[1] 'a' 'Z' 48 mismatch: str++, s = str ... 48 name[47] 'a' 'Z' 48 mismatch: str++, s = str 49 name[48] the loop test reads the byte after the name (The strcmp() against "." and ".." reads at most two bytes past a name that is "." or "..".) On ext4 without dir_index, ext4_read_inline_dir() emits an inline directory's names from a kmalloc(inline_size) copy of the inline data (fs/ext4/inline.c:1439), 60 bytes when it all fits in i_block. After 4 bytes of parent inode number and an 8-byte entry header, a 48-byte name ends at the last byte of that buffer. On ksmbd-for-next, with KASAN, a QUERY_DIRECTORY for "*Z" on a share without a veto list: BUG: KASAN: slab-out-of-bounds in match_pattern (fs/smb/server/misc.c:36) Read of size 1 at addr ffff88801bbff8bc by task kworker/0:2/55 Workqueue: ksmbd-io handle_ksmbd_work match_pattern (fs/smb/server/misc.c:36) __query_dir (fs/smb/server/smb2pdu.c:6841) ext4_read_inline_dir (fs/ext4/inline.c:1539) ext4_readdir (fs/ext4/dir.c:165) iterate_dir (fs/readdir.c:114) smb2_query_dir (fs/smb/server/smb2pdu.c:7034) handle_ksmbd_work (fs/smb/server/server.c:223) Allocated by task 55: __kmalloc_noprof (mm/slub.c:5556) ext4_read_inline_dir (fs/ext4/inline.c:1439) ext4_readdir (fs/ext4/dir.c:165) iterate_dir (fs/readdir.c:114) smb2_query_dir (fs/smb/server/smb2pdu.c:7034) The buggy address belongs to the object at ffff88801bbff880 which belongs to the cache kmalloc-64 of size 64 The buggy address is located 0 bytes to the right of allocated 60-byte region [ffff88801bbff880, ffff88801bbff8bc) and a QUERY_DIRECTORY for "*", which match_pattern() accepts at once, on a share whose veto list is "*.tmp": BUG: KASAN: slab-out-of-bounds in match_wildcard (lib/parser.c:290) Read of size 1 at addr ffff888048c3823c by task kworker/1:1/53 Workqueue: ksmbd-io handle_ksmbd_work match_wildcard (lib/parser.c:290) ksmbd_share_veto_filename (fs/smb/server/mgmt/share_config.c:370) __query_dir (fs/smb/server/smb2pdu.c:6839) ext4_read_inline_dir (fs/ext4/inline.c:1539) ext4_readdir (fs/ext4/dir.c:165) iterate_dir (fs/readdir.c:114) smb2_query_dir (fs/smb/server/smb2pdu.c:7034) (the same kind of object: 0 bytes to the right of a 60-byte region in kmalloc-64 allocated by ext4_read_inline_dir) The bytes after the name also decide the answer, and match_pattern()'s miscount goes wrong the other way too: an attempt that matched k characters before failing moves s back by k - 1 without giving len back, so len understates what is left and the walk can stop before the end of the name. Measured through QUERY_DIRECTORY on the same ext4 filesystem, against what a plain '*'/'?' matcher lists: - in a directory holding "file.txt" and then "b", "file.txt" is not listed for "*.txt", but is listed for "*.txt?" and for "*.txt\x0f", and not for "*.txt\x10": the byte after the name is the low byte of b's inode number, 15, which is the next entry's first field; - "aaab" is not listed for "*aab", and "aaaaab" is listed for "aa*aa", though both names are followed by zero padding; - "*", "?", "*.txt", "*.TXT", "a*b*c", "README" and "*E*" on names followed by zero padding are listed correctly. How it is reached. The reproducer makes an ext4 image with -O inline_data,^dir_index on a loop device, creates a directory holding one file whose name is 48 'a's, and shares the filesystem. It then registers itself as the ksmbd daemon over the ksmbd generic netlink family, answering the login as a guest and the share config with or without the veto list "*.tmp", and as an SMB 3.1.1 client over loopback opens the directory and sends QUERY_DIRECTORY (FileDirectoryInformation). The queries answer as they should (STATUS_NO_MORE_FILES for "*Z", the file for "*"), and KASAN reports the reads above: the match_pattern() one in 4 of 4 runs, the match_wildcard() one in 3 of 3. With a 44-byte name, which leaves zero padding after it in the buffer, neither reports anything. Impact - who can trigger it: - Any SMB client that can list a directory on a share: an authenticated user, or anyone where guest access is enabled (our runs used a guest session). It needs no other request and can be done remotely. On any share, the client chooses the search pattern, and a '*' followed by a character that a name does not contain, as in "*Z", takes match_pattern() to the byte after that name, and on past it unless that byte is a NUL. On a share with a veto pattern that starts with '*', every listing does the same in match_wildcard(), whatever the search pattern. - What follows a name is up to the filesystem. From the source, ext2, ext4 directories without dir_index (block and inline), xfs, btrfs, f2fs and fuse emit pointers into their own directory buffers; ext4 with dir_index (the mkfs default) normally emits a NUL-terminated copy, as do tmpfs, overlayfs and nfs. We ran only ext4; with -O inline_data alone, that is with dir_index, the fuzzer's 48-byte run on 7.4.0-rc5 reported nothing. Elsewhere the walk goes into whatever the filesystem keeps after the name: in xfs with the ftype feature (the default), the entry's file type byte, which is not zero for a file or a directory; for fuse, bytes the fuse daemon wrote. For the read to leave a slab object, as above, a name has to end exactly at the end of an inline directory's buffer, which a user who can create files in the shared directory can arrange. KASAN sees nothing when the read stays inside the buffer. - What the reads do: they read up to the next NUL byte, and let those bytes decide whether the entry is listed (or vetoed). Nothing read is copied to the client, but the listing is an oracle on them, as the "*.txt\x0f" query above shows for the next entry's inode number. In the inline case on a kernel without KASAN, the bytes read are the start of the next slab object, up to its first zero byte; we have not measured what a client can learn about them that way. We have not seen a walk fault. Seen on 7.4.0-rc5 and REPRODUCED ON ksmbd-for-next (d70570cf8003, 2026-12-04) with KASAN; the excerpts above are from ksmbd-for-next. On 7.4.0-rc5 the same reports came through __query_dir at smb2pdu.c:6581 (match_pattern) and :6579 (the veto check, with a veto list of "*z"). The code is the same in mainline (c3500c5ef648, 2026-12-04). All three checks have read the name this way since e2f34481b24d ("cifsd: add server-side procedures for SMB3"), v5.15; b24c93358035 ("cifsd: Pass string length parameter to match_pattern()"), in the same release, gave match_pattern() its len bound for names that are not NUL-terminated, but not on the backtracking path. A patch follows in reply to this mail. It does two things: - __query_dir() gives its checks a NUL-terminated copy of the name, in a PATH_MAX buffer allocated once per request (a fuse name can be up to PATH_MAX - 1 bytes). One copy covers all three checks, and any added later; giving each its own bound would need a length-taking variant of match_wildcard() in lib/parser.c, and the copy costs a memcpy() of each name. - match_pattern() is bounded by a pointer to the end of the name instead of a count, so that restarting the comparison needs no bookkeeping; it still stops at a NUL as before. With the copy it no longer reads past the name either way, but this is what makes "*aab" and "aa*aa" answer correctly. We compared the old and new match_pattern() side by side in userspace, against a plain recursive matcher, on all 21,330,666 pairs of names over {a,b,A,B} up to 6 characters and patterns over {a,b,A,*,?} up to 5, and on 3,000,000 random pairs over a wider alphabet, every name NUL-terminated: they answer differently for 621,384 and 3,919 pairs, and in each of those the new one agrees with the plain matcher and the old one does not. Where both disagree with it, the pattern has two '*' in a row (the trailing-'*' handling, which the patch leaves alone). With each name placed against a PROT_NONE page, the new one never read past it. On ksmbd-for-next with KASAN, same config and image, only the patch between the two builds: before "*Z", 48-byte name KASAN in match_pattern, 4 of 4 "*", veto "*.tmp", 48 KASAN in match_wildcard, 3 of 3 both with 44-byte names no report (2 runs, 1 run) 13 listing queries 5 answered wrong (those above) after "*Z", 48-byte name no report, 4 of 4 runs "*", veto "*.tmp", 48 no report, 3 of 3 runs; x.tmp in another directory still vetoed (checked in 2 of them) 13 listing queries all answered right (The 44-byte controls were not run on the patched kernel.) With only the match_pattern() half of the patch, the match_pattern() read was gone (3 runs) and the match_wildcard() one was not (1 run). 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 derived from the fuzzer's program, runs the daemon and the client in one program over loopback, and we are happy to send it on request. Kapil Vaswani Piyus Kedia