ksmbd: bound smb_check_perm_dacl() ACE walks by DACL size
Subsystems (2)
v4 cover ksmbd: bound smb_check_perm_dacl() ACE walks by DACL size
From: Hang Nan <[email protected]>
Changes in v3:
- Update SMB_SERVER_KUNIT_TESTS help text.
- Moved kunit tests under fs/smb/server/tests/.
The following patch from v2 have already been merged into #ksmbd-for-next-next:
https://lore.kernel.org/linux-cifs/CAKYAXd9XHJSNfrFr+F8thNxFnXqGGcKpS1b1qR4DNuu82+j_VQ@mail.gmail.com/
Hang Nan (3):
ksmbd: add KUnit test for the DACL walk boundary
ksmbd: test smb_check_perm_dacl() DACL walk boundary
ksmbd: test maximal-access DACL walk boundary
fs/smb/server/Kconfig | 2 + fs/smb/server/Makefile | 1 + fs/smb/server/smbacl.c | 2 + fs/smb/server/tests/Kconfig | 15 ++ fs/smb/server/tests/Makefile | 4 + fs/smb/server/tests/smbacl_kunit.c | 301 +++++++++++++++++++++++++++++ fs/smb/server/vfs.c | 2 + 7 files changed, 327 insertions(+) create mode 100644 fs/smb/server/tests/Kconfig create mode 100644 fs/smb/server/tests/Makefile create mode 100644 fs/smb/server/tests/smbacl_kunit.c
Signature · 1 line
2.55.0
PATCH v4 1/3 ksmbd: add KUnit test for the DACL walk boundary
From: Hang Nan <[email protected]>
smb_check_perm_dacl() must stop walking ACEs at the DACL declared size instead of using the enclosing security descriptor length.
Add the ksmbd KUnit test configuration and a semantic harness that verifies a crafted access-granting ACE beyond the declared DACL size is ignored.
--- fs/smb/server/Kconfig | 2 + fs/smb/server/Makefile | 1 + fs/smb/server/tests/Kconfig | 15 +++ fs/smb/server/tests/Makefile | 4 + fs/smb/server/tests/smbacl_kunit.c | 170 +++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 fs/smb/server/tests/Kconfig create mode 100644 fs/smb/server/tests/Makefile create mode 100644 fs/smb/server/tests/smbacl_kunit.c
fs/smb/server/Kconfig +2 -0
@@ -72,3 +72,5 @@ config SMB_SERVER_KERBEROS5 bool "Support for Kerberos 5" depends on SMB_SERVER default y + +source "fs/smb/server/tests/Kconfig"
fs/smb/server/Makefile +1 -0
@@ -19,3 +19,4 @@ $(obj)/ksmbd_spnego_negtokentarg.asn1.o: $(obj)/ksmbd_spnego_negtokentarg.asn1.c ksmbd-$(CONFIG_SMB_SERVER_SMBDIRECT) += transport_rdma.o ksmbd-$(CONFIG_PROC_FS) += proc.o +obj-$(CONFIG_SMB_SERVER_KUNIT_TESTS) += tests/
fs/smb/server/tests/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2026 Hang Nan <[email protected]> + +config SMB_SERVER_KUNIT_TESTS + tristate "KUnit tests for SMB3 server helpers" if !KUNIT_ALL_TESTS + depends on SMB_SERVER && SMB_KUNIT_TESTS && TMPFS_XATTR + default SMB_KUNIT_TESTS + help + This builds the KUnit tests for ksmbd server helpers. The tests + exercise internal server functionality and help detect regressions + in server-side behavior. They are intended for kernel developers + and are not suitable for production systems. + + For more information on KUnit and unit tests in the kernel, + please read Documentation/dev-tools/kunit/index.rst.
fs/smb/server/tests/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2026 Hang Nan <[email protected]> + +obj-$(CONFIG_SMB_SERVER_KUNIT_TESTS) += smbacl_kunit.o
fs/smb/server/tests/smbacl_kunit.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 2/3 ksmbd: test smb_check_perm_dacl() DACL walk boundary
In reply to [email protected]From: Hang Nan <[email protected]>
Drive smb_check_perm_dacl() through ksmbd's NTACL xattr path with a crafted descriptor whose second ACE is beyond the declared DACL size.
Verify that the out-of-boundary ACE is not selected and access remains denied.
--- fs/smb/server/smbacl.c | 2 + fs/smb/server/tests/smbacl_kunit.c | 90 ++++++++++++++++++++++++++++++ fs/smb/server/vfs.c | 2 + 3 files changed, 94 insertions(+)
fs/smb/server/smbacl.c +2 -0
@@ -7,6 +7,7 @@*/ #include <linux/fs.h> +#include <kunit/visibility.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/mnt_idmapping.h>
@@ -1652,6 +1653,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,kfree (pntsd);return rc; } +EXPORT_SYMBOL_IF_KUNIT (smb_check_perm_dacl); int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, const struct path *path, struct smb_ntsd *pntsd, int ntsd_len,
fs/smb/server/tests/smbacl_kunit.c +90 -0
114 lines not on this page · raw message
fs/smb/server/vfs.c +2 -0
@@ -5,6 +5,7 @@*/ #include <crypto/sha2.h> +#include <kunit/visibility.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/filelock.h>
@@ -1668,6 +1669,7 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,kfree (def_smb_acl);return rc; } +EXPORT_SYMBOL_IF_KUNIT (ksmbd_vfs_set_sd_xattr); int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn, struct mnt_idmap *idmap,
Signature · 1 line
2.55.0
PATCH v4 3/3 ksmbd: test maximal-access DACL walk boundary
In reply to [email protected]From: Hang Nan <[email protected]>
Add a maximal-access variant of the smb_check_perm_dacl() boundary test. The in-boundary ACE grants read access, while a trailing ACE beyond the declared DACL size grants write access.
Verify that maximal-access calculation includes the in-boundary permission and ignores the trailing permission.
--- fs/smb/server/tests/smbacl_kunit.c | 47 ++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-)
fs/smb/server/tests/smbacl_kunit.c +44 -3
@@ -12,10 +12,11 @@* sits beyond struct smb_acl::size; stopping at the declared DACL * size (the fixed behaviour) rejects it. * -* - ksmbd_smb_check_perm_dacl_boundary: drives the real +* - ksmbd_smb_check_perm_dacl_boundary and +* ksmbd_smb_check_perm_dacl_maximal_boundary: drive the real * smb_check_perm_dacl() with a descriptor stored through ksmbd's own -* NTACL xattr path on a tmpfs file, and asserts that a post-boundary -* ACE is not selected for a regular access check. +* NTACL xattr path on a tmpfs file, and assert that a post-boundary +* ACE is not selected for either a regular or maximal access check. */ #include <kunit/test.h>
@@ -242,9 +243,49 @@ static void ksmbd_smb_check_perm_dacl_boundary_test(struct kunit *test)fput (file); } +static void +ksmbd_smb_check_perm_dacl_maximal_boundary_test (struct kunit *test) +{ +struct file *file; +struct smb_ntsd *pntsd; +__le32 daccess =FILE_MAXIMAL_ACCESS_LE ; +int ntsd_size, rc; + +/* +* The in-boundary ACE grants read access. The trailing ACE grants +* write access, which must not be included in the maximal access mask. +*/ + pntsd =build_boundary_ntsd (test, &test_owner_sid,FILE_READ_DATA , +FILE_WRITE_DATA , &ntsd_size); +KUNIT_ASSERT_NOT_NULL (test, pntsd); + + file =shmem_file_setup ("ksmbd-kunit-dacl-maximal" ,0 , +mk_vma_flags (VMA_NORESERVE_BIT )); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, file); + + rc =ksmbd_vfs_set_sd_xattr (NULL ,mnt_idmap (file->f_path.mnt), + &file->f_path, pntsd, ntsd_size, + false); +KUNIT_EXPECT_EQ (test,0 , rc); +if (rc) + goto out; + + rc =smb_check_perm_dacl (NULL , &file->f_path, &daccess, +FILE_MAXIMAL_ACCESS_LE ,0 , false); +KUNIT_EXPECT_EQ (test,0 , rc); +if (rc) + goto out; + +KUNIT_EXPECT_TRUE (test,le32_to_cpu (daccess) &FILE_READ_DATA ); +KUNIT_EXPECT_FALSE (test,le32_to_cpu (daccess) &FILE_WRITE_DATA ); +out: +fput (file); +} +static struct kunit_case ksmbd_smbacl_test_cases[] = {KUNIT_CASE (ksmbd_dacl_walk_must_stop_at_declared_size),KUNIT_CASE (ksmbd_smb_check_perm_dacl_boundary_test), +KUNIT_CASE (ksmbd_smb_check_perm_dacl_maximal_boundary_test), {} };
Signature · 1 line
2.55.0
Namjae Jeon
maintainerQuoted 8 lines · On Wed, Aug 19, 2026 at 12:30 PM <[email protected]> wrote:
From: Hang Nan <[email protected]>
Changes in v3:
- Update
SMB_SERVER_KUNIT_TESTShelp text.
- Moved kunit tests underfs/smb/server/tests/.
Quoted 7 lines
The following patch from v2 have already been merged into #ksmbd-for-next-next:
https://lore.kernel.org/linux-cifs/CAKYAXd9XHJSNfrFr+F8thNxFnXqGGcKpS1b1qR4DNuu82+j_VQ@mail.gmail.com/Hang Nan (3):
ksmbd: add KUnit test for the DACL walk boundary
ksmbd: testsmb_check_perm_dacl()DACL walk boundary
ksmbd: test maximal-access DACL walk boundary
It’s a bit late to apply this to the 7.3 kernel. I will apply this patchset to the 7.4 kernel.
Thanks!