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=1796540687; b=KImaN6jDXBgc8wh3LRYrmPbxPkLtb2h2o2Exxub+3awtrM6y2JrWQXxiRM/krp4ddo4i y5wQt36YSXByCY8svU6c7tzlFBIIynN68WPxHenLO2j+nXNMqw0IY7eVgEys0JHTJcTHN v2eujVylIvyHLxgBQCmSuJ3Xf9jZpNdC6j1hSZ7eybIkvQVmx6KrNbrK6W0zDu5q6PQMe ez5XO+8aPcf73NuOuv3v+ZCDku9MidEN+3rjgTH057rNprVlgh1baS5v0M4RwZFHVP8fo 03IN/MYwT2n946XhKV0lgKjys6j1jWVXWwD3XsnP25VwcBafC4O7d0k5lpXIF4DnanQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796540687; h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted: X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To: From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID: Subject:To:Cc:Content-Type:Content-Transfer-Encoding; bh=0ZMIe8mksE/NtJ/EG9qaRtnhapfeiYd75wBwljqN7fg=; b=pjJJn5eI/bNA8j7/AksTpSI0cf6/Dv1aYy4Hd30BOq9wq3sbK/6HBqsxT9zrxMZXg9VB U3WMKJwI5CR6Xw5FHiVnqJh9s1OjF5PoGjAYCw9U+45HsedRpF53RwwK16GwYjDLuzbuq Ke/nAkbLAm5HmtKc5pc0x0qdhEhOS6UZN7YbAuzeLD+wWLlvKLeTgu19JO0eak1zlZtEe lRmycYYISQIfbC6rd0RyITCzigE/zdAPTuTYeM0q0VEYSYcE+SUR8+TCdZtexr3RC8LIo 4m69kRkvQJkwOtlEy3lmmjF1hIYfBSNR1dB7UQ6aSJeHI3Vor7/8VGqBR0BIFcUJK0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OKQV6a4W; 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 5C679606A31F for ; Sun, 6 Dec 2026 07:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OKQV6a4W Received: by smtp.kernel.org (Postfix) with ESMTPSA id E443F1F00A11 for ; Sun, 6 Dec 2026 07:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796540686; bh=0ZMIe8mksE/NtJ/EG9qaRtnhapfeiYd75wBwljqN7fg=; h=References:In-Reply-To:From:Date:Subject:To:Cc; b=OKQV6a4W395Ypwt9Ogp4HbBQVIbxdKOK7IA8X4UwvpBOSbTm2Z4fBRGvGDRsm20Vi ZGfv1Q4xsbj+JuxoVScKJfsyOAAdKquuPOwaOHOiNYu1gEZfHKzdqV+/GrY/Fq+ooK Tipvn4XbGzOfxPKYJLDzvomAOIfZxKmobFCzSdoT0YU739IxspCEV1ACOlRRK75ptM FhprokPAPUx/sRYKevfCwTMZamNQ7/IjQq9yv9CxbFU0ZwpQOJCIAf0un1ALgMFlXV faNfOcE4r61qbIfLhVscFHNC+e1crJVr1tLMlapdoNhCIrXbpmaW9P15t8s7cegHak nVQBDRWDZv54Q== Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-c55435ba668so82778066b.0 for ; Sat, 05 Dec 2026 23:04:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AL+hErGrk1kxjQa1Jgo0ik1SNtNzydSwLi0m38bR3law8ggXWNqi6VUrLDmUJH55ytjgmM9MbGr1TeIB7k0l1fo=@vger.kernel.org X-Gm-Message-State: APuU4Z80karHcW8n52aZ6g8iZ7Gr4M6K+eo8QX9c6IJwzy4Xl8GjPCNz +qYRJ0s7fIe3csHK3V03BF8Y8qH1d3yhM8Otfm4EiBPiJOdSCSb5RCOd2xxyV3fGo49W5JNIOuK a3V9i449Vh4n4QsPxnccuqIog838Bg0E= X-Received: by 2002:a17:907:60c9:b0:c51:c6e1:3cf4 with SMTP id a640c23a62f3a-c5261ecb436mr454322066b.6.1796540685542; Sat, 05 Dec 2026 23:04:45 -0800 (PST) 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 References: <20261205195745.508424-1-piyus@iiitd.ac.in> In-Reply-To: <20261205195745.508424-1-piyus@iiitd.ac.in> From: Namjae Jeon Date: Sun, 6 Dec 2026 16:04:33 +0900 X-Gmail-Original-Message-ID: X-Gm-Features: Aa3M54poOxLMHLcAb-Vhx0cXUE1daWsLw6CnrBUYQUaQ1VJ_6YWX3ngZ-M-DECg Message-ID: Subject: Re: [PATCH v2] ksmbd: do not read past a directory entry name in __query_dir() To: Piyus Kedia Cc: linux-cifs@vger.kernel.org, Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-kernel@vger.kernel.org, Kapil Vaswani Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Dec 6, 2026 at 4:57=E2=80=AFAM Piyus Kedia wrot= e: > > __query_dir(), the iterate_dir() actor of SMB2 QUERY_DIRECTORY, gets > each entry as a name and a length, and the name need not be > NUL-terminated: ext2, ext4 without dir_index, xfs, btrfs, f2fs and fuse > pass a pointer into their own directory buffers. Three of its checks > read it as a C string: > > - strcmp() against "." and ".."; > > - ksmbd_share_veto_filename(), whose match_wildcard() walks the name > up to a NUL; > > - match_pattern(), which is given the length but walks > while (*s && len), and decrements len only when a character is > consumed by a match. A mismatch after a '*' restarts the comparison > one character further on (str++; s =3D str;) and leaves len alone, so > after a mismatch at the first character of an attempt len > overstates what is left, and the walk goes on to a NUL; after a > partial match of two or more characters it understates it, and the > walk stops early. > > On ext4 without dir_index, an inline directory's names are emitted > from a kmalloc()ed copy of the inline data, and a 48-byte name ends at > the end of that 60-byte buffer. A search pattern of "*Z" then reads > past it in match_pattern(), and on a share with a veto list such as > "*.tmp" any QUERY_DIRECTORY reads past it in match_wildcard(): > > BUG: KASAN: slab-out-of-bounds in match_pattern (fs/smb/server/misc.c:3= 6) > 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) > > 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) > > (both: 0 bytes to the right of a 60-byte region in kmalloc-64, > allocated by ext4_read_inline_dir() at fs/ext4/inline.c:1439) > > What lies past the name also decides the answer: in an ext4 directory > without dir_index, "file.txt" followed by another entry is not listed > for "*.txt", because the walk takes in the next entry's inode number. > And the miscount gets terminated names wrong as well: "aaab" does not > match "*aab", and "aaaaab" matches "aa*aa". > > Make all three checks go by the length. Use name_is_dot_dotdot() for > "." and "..". Add ksmbd_share_veto_filename_len(), which matches the > veto patterns with a copy of match_wildcard() bounded by the length, so > the veto rules themselves do not change; the open and rename paths, > whose names are NUL-terminated, keep ksmbd_share_veto_filename(). And > bound match_pattern() by a pointer to the end of the name instead of a > count, so that restarting the comparison needs no bookkeeping. > > We found this with a syzkaller-based fuzzing harness driven by an AI tool= . > > Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") > Closes: https://lore.kernel.org/linux-cifs/ksmbd-match-pattern-overread.2= 0261205@iiitd.ac.in/ > Cc: stable@vger.kernel.org > Signed-off-by: Kapil Vaswani > Signed-off-by: Piyus Kedia Applied it to #ksmbd-for-next. Thanks.