Skip to content

Commit

Permalink
CVE-2023-3961:s3:torture: Add test SMB2-INVALID-PIPENAME to show we a…
Browse files Browse the repository at this point in the history
…llow bad pipenames with unix separators through to the UNIX domain socket code.

The raw SMB2-INVALID-PIPENAME test passes against Windows 2022,
as it just returns NT_STATUS_OBJECT_NAME_NOT_FOUND.

Add the knownfail.

BUG:https://bugzilla.samba.org/show_bug.cgi?id=15422

Signed-off-by: Jeremy Allison <[email protected]>
  • Loading branch information
jrasamba authored and Jule Anger committed Oct 10, 2023
1 parent ae476e1 commit c39f90a
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions selftest/knownfail.d/badpipename
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^samba3.smbtorture_s3.smb2.SMB2-INVALID-PIPENAME.smbtorture\(fileserver\)
14 changes: 14 additions & 0 deletions source3/selftest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ def is_module_enabled(module):
smbtorture3,
"-mSMB2"])

# BUG: https://bugzilla.samba.org/show_bug.cgi?id=15422
# Prevent bad pipenames.
#
plantestsuite("samba3.smbtorture_s3.smb2.SMB2-INVALID-PIPENAME",
"fileserver",
[os.path.join(samba3srcdir,
"script/tests/test_smbtorture_s3.sh"),
'SMB2-INVALID-PIPENAME',
'//$SERVER_IP/tmp',
'$USERNAME',
'$PASSWORD',
smbtorture3,
"-mSMB2"])

#
# SMB2-NON-DFS-SHARE needs to run against a special share non-msdfs-pathname-share
# This is an empty non-DFS share with no links, used merely to test
Expand Down
1 change: 1 addition & 0 deletions source3/torture/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ bool run_smb2_non_dfs_share(int dummy);
bool run_smb2_dfs_share_non_dfs_path(int dummy);
bool run_smb2_dfs_filename_leading_backslash(int dummy);
bool run_smb2_pipe_read_async_disconnect(int dummy);
bool run_smb2_invalid_pipename(int dummy);
bool run_smb1_dfs_paths(int dummy);
bool run_smb1_dfs_search_paths(int dummy);
bool run_smb1_dfs_operations(int dummy);
Expand Down
110 changes: 110 additions & 0 deletions source3/torture/test_smb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5359,3 +5359,113 @@ bool run_smb2_pipe_read_async_disconnect(int dummy)
}
return retval;
}

bool run_smb2_invalid_pipename(int dummy)
{
struct cli_state *cli = NULL;
NTSTATUS status;
uint64_t fid_persistent = 0;
uint64_t fid_volatile = 0;
const char *unknown_pipe = "badpipe";
const char *invalid_pipe = "../../../../../../../../../badpipe";

printf("Starting SMB2-INVALID-PIPENAME\n");

if (!torture_init_connection(&cli)) {
return false;
}

status = smbXcli_negprot(cli->conn,
cli->timeout,
PROTOCOL_SMB2_02,
PROTOCOL_SMB3_11,
NULL,
NULL,
NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("smbXcli_negprot returned %s\n", nt_errstr(status));
return false;
}

status = cli_session_setup_creds(cli, torture_creds);
if (!NT_STATUS_IS_OK(status)) {
printf("cli_session_setup returned %s\n", nt_errstr(status));
return false;
}

status = cli_tree_connect(cli, "IPC$", "?????", NULL);
if (!NT_STATUS_IS_OK(status)) {
printf("cli_tree_connect returned %s\n", nt_errstr(status));
return false;
}

/* Try and connect to an unknown pipename. */
status = smb2cli_create(cli->conn,
cli->timeout,
cli->smb2.session,
cli->smb2.tcon,
unknown_pipe,
SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
SEC_STD_SYNCHRONIZE|
SEC_FILE_READ_DATA|
SEC_FILE_WRITE_DATA|
SEC_FILE_READ_ATTRIBUTE, /* desired_access, */
FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
FILE_CREATE, /* create_disposition, */
0, /* create_options, */
NULL, /* smb2_create_blobs *blobs */
&fid_persistent,
&fid_volatile,
NULL, /* struct smb_create_returns * */
talloc_tos(), /* mem_ctx. */
NULL, /* struct smb2_create_blobs * */
NULL); /* struct symlink_reparse_struct */
/* We should get NT_STATUS_OBJECT_NAME_NOT_FOUND */
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("%s:%d smb2cli_create on name %s returned %s\n",
__FILE__,
__LINE__,
unknown_pipe,
nt_errstr(status));
return false;
}

/* Try and connect to an invalid pipename containing unix separators. */
status = smb2cli_create(cli->conn,
cli->timeout,
cli->smb2.session,
cli->smb2.tcon,
invalid_pipe,
SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */
SEC_STD_SYNCHRONIZE|
SEC_FILE_READ_DATA|
SEC_FILE_WRITE_DATA|
SEC_FILE_READ_ATTRIBUTE, /* desired_access, */
FILE_ATTRIBUTE_NORMAL, /* file_attributes, */
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */
FILE_CREATE, /* create_disposition, */
0, /* create_options, */
NULL, /* smb2_create_blobs *blobs */
&fid_persistent,
&fid_volatile,
NULL, /* struct smb_create_returns * */
talloc_tos(), /* mem_ctx. */
NULL, /* struct smb2_create_blobs * */
NULL); /* struct symlink_reparse_struct */
/*
* We should still get NT_STATUS_OBJECT_NAME_NOT_FOUND
* (tested against Windows 2022).
*/
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("%s:%d smb2cli_create on name %s returned %s\n",
__FILE__,
__LINE__,
invalid_pipe,
nt_errstr(status));
return false;
}
return true;
}
4 changes: 4 additions & 0 deletions source3/torture/torture.c
Original file line number Diff line number Diff line change
Expand Up @@ -15844,6 +15844,10 @@ static struct {
.name = "SMB2-QUOTA1",
.fn = run_smb2_quota1,
},
{
.name = "SMB2-INVALID-PIPENAME",
.fn = run_smb2_invalid_pipename,
},
{
.name = "SMB2-STREAM-ACL",
.fn = run_smb2_stream_acl,
Expand Down

0 comments on commit c39f90a

Please sign in to comment.