From 49fae693cdba6cfe2325d76960e632c4b3451204 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Sun, 11 Oct 2026 11:23:04 +0530 Subject: [PATCH 1/2] CVE-2026-109411: s4:torture/smb2: Test case-insensitive open access check Add a regression test which verifies that a second user is denied an open of another user's restricted file when it is addressed using a different case, for both read and write access. This exercises the case-insensitive open path on case-preserving backends. BUG: https://bugzilla.samba.org/show_bug.cgi?id=16276 Signed-off-by: Anoop C S --- source3/selftest/tests.py | 5 ++ source4/torture/smb2/create.c | 151 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 8a251a43ebc..2651682e75e 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -1401,6 +1401,11 @@ for t in tests: plansmbtorture4testsuite("smb2.async_dosmode", "simpleserver", "//$SERVER_IP/async_dosmode_shadow_copy2 -U$USERNAME%$PASSWORD") + elif t == "smb2.create": + nt4_creds = " --option=torture:user2name=user1 --option=torture:user2password=$PASSWORD" + ad_creds = " --option='torture:user2name=alice' --option='torture:user2password=Secret007'" + plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD' + nt4_creds) + plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD' + ad_creds) elif t == "smb2.rename": plansmbtorture4testsuite(t, "fileserver", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD') elif t == "smb2.twrp": diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 756256dc4f5..77be9017746 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -34,6 +34,8 @@ #include "lib/cmdline/cmdline.h" #include "librpc/gen_ndr/security.h" #include "lib/events/events.h" +#include "lib/param/param.h" +#include "libcli/resolve/resolve.h" #define FNAME "test_create.dat" #define DNAME "smb2_open" @@ -3895,6 +3897,154 @@ done: return ret; } +/* + * Test to verify that a second user is denied an open of another user's + * restricted file when it is addressed using a different case, for both + * read and write access. + */ +static bool set_owner_only_sd(struct torture_context *tctx, + struct smb2_tree *tree, + struct smb2_handle handle) +{ + union smb_fileinfo q = {}; + union smb_setfileinfo s = {}; + struct security_descriptor *sd = NULL; + struct security_ace ace = {}; + NTSTATUS status; + bool ret = true; + + q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; + q.query_secdesc.in.file.handle = handle; + q.query_secdesc.in.secinfo_flags = SECINFO_OWNER | SECINFO_DACL; + status = smb2_getinfo_file(tree, tctx, &q); + CHECK_STATUS(status, NT_STATUS_OK); + + torture_assert_goto(tctx, q.query_secdesc.out.sd->owner_sid != NULL, + ret, done, "no owner sid on created file"); + + sd = security_descriptor_dacl_create(tctx, 0, NULL, NULL, NULL); + torture_assert_goto(tctx, sd != NULL, ret, done, + "security_descriptor_dacl_create failed"); + + ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED; + ace.access_mask = SEC_RIGHTS_FILE_ALL; + ace.trustee = *q.query_secdesc.out.sd->owner_sid; + + status = security_descriptor_dacl_add(sd, &ace); + CHECK_STATUS(status, NT_STATUS_OK); + + s.set_secdesc.level = RAW_SFILEINFO_SEC_DESC; + s.set_secdesc.in.file.handle = handle; + s.set_secdesc.in.secinfo_flags = SECINFO_DACL; + s.set_secdesc.in.sd = sd; + status = smb2_setinfo_file(tree, &s); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + return ret; +} + +static bool test_case_insensitive_bypass(struct torture_context *tctx, + struct smb2_tree *tree) +{ + const char *host = torture_setting_string(tctx, "host", NULL); + const char *share = torture_setting_string(tctx, "share", NULL); + struct cli_credentials *creds2 = torture_user2_credentials(tctx, tctx); + struct smbcli_options options = tree->session->transport->options; + struct smb2_tree *tree2 = NULL; + struct smb2_create c; + struct smb2_handle h = {}; + const char *fname = "Secret.txt"; + const char *fname_upper = "SECRET.TXT"; + NTSTATUS status; + bool ret = true; + size_t i; + const uint32_t access_masks[] = { + SEC_FILE_READ_DATA, + SEC_FILE_WRITE_DATA, + }; + + torture_assert(tctx, creds2 != NULL, "talloc error"); + if (cli_credentials_is_anonymous(creds2)) { + torture_skip(tctx, "valid user2 credentials are required"); + } + + status = smb2_connect(tctx, host, share, tctx->lp_ctx, + lpcfg_resolve_context(tctx->lp_ctx, tctx), + creds2, &tree2, tctx->ev, &options, + lpcfg_socket_options(tctx->lp_ctx), + lpcfg_gensec_settings(tctx, tctx->lp_ctx)); + torture_assert_ntstatus_ok(tctx, status, "smb2_connect as user2 failed"); + + for (i = 0; i < ARRAY_SIZE(access_masks); i++) { + smb2_util_unlink(tree, fname); + + c = (struct smb2_create) { + .in.desired_access = SEC_RIGHTS_FILE_ALL, + .in.file_attributes = FILE_ATTRIBUTE_NORMAL, + .in.create_disposition = NTCREATEX_DISP_CREATE, + .in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE, + .in.fname = fname, + }; + status = smb2_create(tree, tctx, &c); + CHECK_STATUS(status, NT_STATUS_OK); + h = c.out.file.handle; + + status = smb2_util_write(tree, h, "foo", 0, 3); + CHECK_STATUS(status, NT_STATUS_OK); + + ret = set_owner_only_sd(tctx, tree, h); + if (!ret) { + goto done; + } + + smb2_util_close(tree, h); + ZERO_STRUCT(h); + + /* Exact case open from a different must be denied. */ + c = (struct smb2_create) { + .in.desired_access = access_masks[i], + .in.file_attributes = FILE_ATTRIBUTE_NORMAL, + .in.create_disposition = NTCREATEX_DISP_OPEN, + .in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE, + .in.fname = fname, + }; + status = smb2_create(tree2, tctx, &c); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_ACCESS_DENIED, ret, done, + "exact-case open not denied"); + + /* + * Differently cased open with FILE_OPEN_IF must resolve to + * the same owner only file and denied. + */ + c = (struct smb2_create) { + .in.desired_access = access_masks[i], + .in.file_attributes = FILE_ATTRIBUTE_NORMAL, + .in.create_disposition = NTCREATEX_DISP_OPEN_IF, + .in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE, + .in.fname = fname_upper, + }; + status = smb2_create(tree2, tctx, &c); + if (NT_STATUS_IS_OK(status)) { + h = c.out.file.handle; + } + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_ACCESS_DENIED, ret, done, + "differently-cased FILE_OPEN_IF not denied"); + } + +done: + if (!smb2_util_handle_empty(h)) { + smb2_util_close(tree2 != NULL ? tree2 : tree, h); + } + smb2_util_unlink(tree, fname); + return ret; +} + /* basic testing of SMB2 read */ @@ -3920,6 +4070,7 @@ struct torture_suite *torture_smb2_create_init(TALLOC_CTX *ctx) torture_suite_add_1smb2_test(suite, "quota-fake-file", test_smb2_open_quota_fake_file); torture_suite_add_1smb2_test(suite, "path-length", test_path_length_test); torture_suite_add_1smb2_test(suite, "bench-path-contention-shared", test_smb2_bench_path_contention_shared); + torture_suite_add_1smb2_test(suite, "case-insensitive-bypass", test_case_insensitive_bypass); suite->description = talloc_strdup(suite, "SMB2-CREATE tests"); -- 2.56.0 From 391da3fd9ff41603c5c192de09bce610dbdce8cc Mon Sep 17 00:00:00 2001 From: Vinit Agnihotri Date: Wed, 14 Oct 2026 11:42:18 +0530 Subject: [PATCH 2/2] CVE-2026-109411: vfs_ceph_rgw: Open the name resolved by the VFS layer in openat openat() built the object path from fsp->fsp_name->base_name, ignoring the case-corrected smb_fname passed in by the caller. A differently cased open thus retried the wrong name, failed, and fell through to the create path, skipping the access check on the existing object and letting a user read or overwrite another user's file. Build the path from dirfsp and smb_fname instead, so the resolved name is honoured and the proper access check runs. BUG: https://bugzilla.samba.org/show_bug.cgi?id=16276 Reported-by: hataehoon Pair-Programmed-With: Anoop C S Signed-off-by: Vinit Agnihotri Reviewed-by: Anoop C S --- source3/modules/vfs_ceph_rgw.c | 41 +++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/source3/modules/vfs_ceph_rgw.c b/source3/modules/vfs_ceph_rgw.c index fbbec98e3d4..6bdae97858b 100644 --- a/source3/modules/vfs_ceph_rgw.c +++ b/source3/modules/vfs_ceph_rgw.c @@ -169,6 +169,16 @@ static char *normalise_name(TALLOC_CTX *ctx, const char *pathname_in) return result; } +static char *prepare_full_path(TALLOC_CTX *ctx, + const char *dir_name, + const char *base_name) +{ + if (*dir_name != '\0') { + return talloc_asprintf(ctx, "%s/%s", dir_name, base_name); + } + return talloc_strdup(ctx, base_name); +} + static int vfs_ceph_rgw_release_fh(struct vfs_ceph_rgw_fh *cfh) { cfh->rgw_fh = NULL; @@ -249,6 +259,9 @@ static int vfs_ceph_rgw_openat(struct vfs_handle_struct *handle, bool do_release = false; const struct security_unix_token *utok = NULL; char *open_name = NULL; + char *name = NULL; + char *dir_name = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); START_PROFILE_X(SNUM(handle->conn), syscall_openat); @@ -259,12 +272,24 @@ static int vfs_ceph_rgw_openat(struct vfs_handle_struct *handle, utok = get_current_utok(handle->conn); - open_name = normalise_name(talloc_tos(), fsp->fsp_name->base_name); - if (open_name == NULL) { + dir_name = normalise_name(ctx, dirfsp->fsp_name->base_name); + if (dir_name == NULL) { + DBG_ERR("[CEPH_RGW] Not enough memory for dirname\n"); + goto out; + } + + name = normalise_name(ctx, smb_fname->base_name); + if (name == NULL) { DBG_ERR("[CEPH_RGW] Not enough memory for name\n"); goto out; } + open_name = prepare_full_path(ctx, dir_name, name); + if (open_name == NULL) { + DBG_ERR("[CEPH_RGW] Not enough memory for open name\n"); + goto out; + } + DBG_DEBUG("[CEPH_RGW] base_name=[%s] dir->name=[%s] " "fsp->name=[%s] open_name=[%s]\n", smb_fname->base_name, @@ -398,7 +423,7 @@ out: RGW_FH_RELE_FLAG_NONE); vfs_ceph_rgw_remove_fh(handle, fsp); } - TALLOC_FREE(open_name); + TALLOC_FREE(ctx); END_PROFILE_X(syscall_openat); return status_code(rc); } @@ -1694,16 +1719,6 @@ out: return lstatus_code(bytes_written); } -static char *prepare_full_path(TALLOC_CTX *ctx, - const char *dir_name, - const char *base_name) -{ - if (*dir_name != '\0') { - return talloc_asprintf(ctx, "%s/%s", dir_name, base_name); - } - return talloc_strdup(ctx, base_name); -} - /* Note about rename: * librgw rename method expects file handle for source file to be in * closed state. This behaviour breaks posix compliance. -- 2.56.0