Bug 15420 - reply_sesssetup_and_X() can dereference uninitialized tmp pointer
Summary: reply_sesssetup_and_X() can dereference uninitialized tmp pointer
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jule Anger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks: 15430
  Show dependency treegraph
 
Reported: 2023-07-13 11:03 UTC by Robert Morris
Modified: 2023-09-07 09:03 UTC (History)
1 user (show)

See Also:


Attachments
demo client program (4.80 KB, text/x-csrc)
2023-07-14 15:31 UTC, Robert Morris
no flags Details
Patch under gitlab ci. (12.59 KB, patch)
2023-08-11 18:03 UTC, Jeremy Allison
no flags Details
WIP patches for master. (12.49 KB, patch)
2023-08-11 22:23 UTC, Jeremy Allison
no flags Details
git-am fix for 4.19.next, 4.18.next. (13.20 KB, patch)
2023-08-14 17:13 UTC, Jeremy Allison
vl: review+
Details
git-am fix for 4.17.next (13.15 KB, patch)
2023-08-14 17:14 UTC, Jeremy Allison
vl: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Morris 2023-07-13 11:03:12 UTC
reply_sesssetup_and_X() in source3/smbd/smb1_sesssetup.c contains:

        char *tmp;
        ...;
                p += srvstr_pull_req_talloc(state, req, &tmp, p,
                                            STR_TERMINATE);
                state->user = tmp ? tmp : "";

But srvstr_pull_req_talloc() returns without setting tmp if there
is nothing left in the input string:

size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req,
                              char **dest, const uint8_t *src, int flags)
{
        ssize_t bufrem = smbreq_bufrem(req, src);
        if (bufrem == 0) {
                return 0;
        }

This will cause subsequent use of state->user[] to dereference whatever
garbage value happened to be in tmp.

A client can make this happen by sending a SMB_COM_SESSION_SETUP_ANDX
message whose SMB Data ends at just the point where the AccountName
should start.
Comment 1 Jeremy Allison 2023-07-14 03:10:17 UTC
Again, can you attach your test code please ? That will make it much easier for us to write a regression test case.

Thanks !
Comment 2 Robert Morris 2023-07-14 15:31:26 UTC
Created attachment 17984 [details]
demo client program
Comment 3 Robert Morris 2023-07-14 15:33:31 UTC
(In reply to Jeremy Allison from comment #1)
I've added a demo client.

To see a crash, modify reply_sesssetup_and_X to explicitly
initialize tmp to some illegal address.
Comment 4 Robert Morris 2023-07-14 16:35:59 UTC
Another place this comes up is in reply_trans() in smb1_ipc.c,
where this call will leave state->name uninitialized if
the SMB_Data part of an SMB_COM_NT_TRANSACT ends just where
the \pipe\ name ought to start:

        srvstr_pull_req_talloc(state, req, &state->name, req->buf,
                               STR_TERMINATE);
Comment 5 Jeremy Allison 2023-07-14 18:06:14 UTC
Thanks, I'll do a thorough review of all code that matches this pattern and try and fix them all at once.

This looks like a self-DOS though, not a security issue I think. Can't see any way this can be exploited.
Comment 6 Jeremy Allison 2023-08-11 16:41:31 UTC
I have a test case reproducer for this that crashes smbd.

Now I just need to figure out why the test harness isn't noticing that smbd crashed :-).
Comment 7 Jeremy Allison 2023-08-11 18:03:25 UTC
Created attachment 18042 [details]
Patch under gitlab ci.
Comment 8 Jeremy Allison 2023-08-11 20:08:47 UTC
MR: https://gitlab.com/samba-team/samba/-/merge_requests/3220
Comment 9 Jeremy Allison 2023-08-11 22:23:53 UTC
Created attachment 18044 [details]
WIP patches for master.
Comment 10 Samba QA Contact 2023-08-14 15:56:04 UTC
This bug was referenced in samba master:

e7bf94b4e3a7f994aa6f0b859089c5add2ad380f
963fd8aa9b76361ab9aeb63307773f2498b17879
9220c45cc191b34e293190f6a923ba463edd5db9
5bc50d2ea4444244721e72b4264311c7005d2f3c
5379b8d557a9a16b81eafb87b60b81debc4bfccb
Comment 11 Jeremy Allison 2023-08-14 17:13:06 UTC
Created attachment 18046 [details]
git-am fix for 4.19.next, 4.18.next.

Cherry-picked from master.
Comment 12 Jeremy Allison 2023-08-14 17:14:41 UTC
Created attachment 18047 [details]
git-am fix for 4.17.next

Back-ported from master.
Comment 13 Jule Anger 2023-08-15 14:19:10 UTC
Pushed to autobuild-v4-{19,18,17}-test.
Comment 14 Samba QA Contact 2023-08-15 15:21:04 UTC
This bug was referenced in samba v4-19-test:

7b84b08693bab381634c3a0d28212fd7706b74dc
60cbe064ba1fcbc3b53c54d2ba4a04cf1f8f91ce
116c740cb9c30bc2471dcb7ba2a771c86b02061a
a36f30498db60d876467f9df87231838bab7a038
18bd1f75d4f03e755020151925e08ebac3866d0c
Comment 15 Samba QA Contact 2023-08-16 09:48:28 UTC
This bug was referenced in samba v4-17-test:

bce87c64b717bbb7ad78063f5918e715403f49fd
ec8887be3f6f128911be4855c6ad302140d4d5ff
3a123fbbe86dbc8dba8612095554bff8309ab381
b958e82d0b67654a76fc95edde646c6ea8f99ae1
0dbba5f655f6e84b07f04c8e23719a72c67594ed
Comment 16 Samba QA Contact 2023-08-16 11:50:21 UTC
This bug was referenced in samba v4-18-test:

8e31fd2d5998d08f66bad617aecbc6dc4a9490cf
6fef976770c596e5663f49a3cf194b0e6cdf83e6
4c27dfe322c28e01a5657e1e707000474d2343f9
f025f51ac5c363c37f4a80baa06c40106ae2bdae
e6c0d4f122d8083273009d0f61e099bb34fbcf51
Comment 17 Samba QA Contact 2023-08-16 16:57:39 UTC
This bug was referenced in samba v4-18-stable (Release samba-4.18.6):

8e31fd2d5998d08f66bad617aecbc6dc4a9490cf
6fef976770c596e5663f49a3cf194b0e6cdf83e6
4c27dfe322c28e01a5657e1e707000474d2343f9
f025f51ac5c363c37f4a80baa06c40106ae2bdae
e6c0d4f122d8083273009d0f61e099bb34fbcf51
Comment 18 Jule Anger 2023-08-17 07:40:46 UTC
Closing out bug report.

Thanks!
Comment 19 Samba QA Contact 2023-08-18 11:21:30 UTC
This bug was referenced in samba v4-19-stable (Release samba-4.19.0rc3):

7b84b08693bab381634c3a0d28212fd7706b74dc
60cbe064ba1fcbc3b53c54d2ba4a04cf1f8f91ce
116c740cb9c30bc2471dcb7ba2a771c86b02061a
a36f30498db60d876467f9df87231838bab7a038
18bd1f75d4f03e755020151925e08ebac3866d0c
Comment 20 Samba QA Contact 2023-09-07 09:03:40 UTC
This bug was referenced in samba v4-17-stable (Release samba-4.17.11):

bce87c64b717bbb7ad78063f5918e715403f49fd
ec8887be3f6f128911be4855c6ad302140d4d5ff
3a123fbbe86dbc8dba8612095554bff8309ab381
b958e82d0b67654a76fc95edde646c6ea8f99ae1
0dbba5f655f6e84b07f04c8e23719a72c67594ed