Bug 15885 (CVE-2025-9640) - CVE-2025-9640 [SECURITY] vfs_streams_xattr uninitialized memory write possible
Summary: CVE-2025-9640 [SECURITY] vfs_streams_xattr uninitialized memory write possible
Status: RESOLVED FIXED
Alias: CVE-2025-9640
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: 4.22.2
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jule Anger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks: 15929
  Show dependency treegraph
 
Reported: 2025-07-17 20:38 UTC by Andrew Walker
Modified: 2025-10-21 20:58 UTC (History)
5 users (show)

See Also:


Attachments
v4.23 fix (1.39 KB, patch)
2025-08-28 19:44 UTC, Andrew Walker
vl: review+
Details
v4.23 test (8.09 KB, patch)
2025-08-28 19:45 UTC, Andrew Walker
vl: review+
Details
drafdt advisory (1.51 KB, text/plain)
2025-09-10 07:44 UTC, Douglas Bagnall
no flags Details
draft patch v2 (9.71 KB, patch)
2025-10-03 03:19 UTC, Douglas Bagnall
no flags Details
advisory v2 (1.61 KB, text/plain)
2025-10-03 03:36 UTC, Douglas Bagnall
no flags Details
draft patch v3 (10.62 KB, patch)
2025-10-03 03:51 UTC, Douglas Bagnall
no flags Details
patch v4 (10.60 KB, patch)
2025-10-04 00:48 UTC, Douglas Bagnall
no flags Details
patch v4 (10.60 KB, patch)
2025-10-04 00:49 UTC, Douglas Bagnall
vl: review+
Details
patch v5 (10.73 KB, patch)
2025-10-05 01:06 UTC, Douglas Bagnall
vl: review+
dbagnall: review? (awalker)
Details
patch for 4.23 (10.73 KB, patch)
2025-10-05 09:08 UTC, Douglas Bagnall
vl: review+
Details
patch for 4.22 (10.73 KB, patch)
2025-10-05 09:09 UTC, Douglas Bagnall
vl: review+
Details
patch for 4.21 (10.73 KB, patch)
2025-10-05 09:10 UTC, Douglas Bagnall
vl: review+
Details
advisory v3 (1.96 KB, text/plain)
2025-10-12 21:04 UTC, Douglas Bagnall
vl: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Walker 2025-07-17 20:38:39 UTC
streams_xattr_pwrite() in vfs_streams_xattr can write uninitialized memory to alternate data streams if you issue a write request that creates a hole in the file because we don't zero out the new buffer. For example, first write a small stream, then issue a write to a high offset, then look at xattr contents.


https://gitlab.com/samba-team/samba/-/blob/master/source3/modules/vfs_streams_xattr.c?ref_type=heads#L1051

as opposed to

https://gitlab.com/samba-team/samba/-/blob/master/source3/modules/vfs_streams_xattr.c?ref_type=heads#L1325

This allows clients to basically write uninitialized memory to the
xattr, then read it back, (rinse and repeat).

The following appears to resolve the issue:
```
diff --git a/source3/modules/vfs_streams_xattr.c
b/source3/modules/vfs_streams_xattr.c
index ac01cc46043..d2d3562d368 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -1047,18 +1047,18 @@ static ssize_t
streams_xattr_pwrite(vfs_handle_struct *handle,

         if ((offset + n) > ea.value.length-1) {
                uint8_t *tmp;
+               size_t new_sz = offset + n + 1;

-               tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8_t,
-                                          offset + n + 1);
+               tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8_t, new_sz);

                if (tmp == NULL) {
                        TALLOC_FREE(ea.value.data);
                         errno = ENOMEM;
                         return -1;
                 }
+               memset(tmp + ea.value.length, 0, new_sz - ea.value.length);
                ea.value.data = tmp;
-               ea.value.length = offset + n + 1;
-               ea.value.data[offset+n] = 0;
+               ea.value.length = new_sz;
         }
```
Comment 1 Douglas Bagnall 2025-08-20 00:55:50 UTC
My guess at CVSS 3.1 is 4.3 or 6.5:

AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N

via https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator

depending on whether I set "confidentiality impact" to low or high, assuming it needs an authenticated user and low complexity.
Comment 2 Volker Lendecke 2025-08-27 15:32:50 UTC
Where are we with the discussion if this is worth a CVE? I'm currently working on streams_xattr and I would like to be able to propose code in that area.
Comment 3 Ralph Böhme 2025-08-27 16:38:02 UTC
(In reply to Douglas Bagnall from comment #1)
To me it's C:L so the score is 4.3. That would iirc mean we don't do a full security release and instead just release this as a bugfix with a CVE assigned.
Comment 4 Douglas Bagnall 2025-08-27 22:10:54 UTC
(In reply to Ralph Böhme from comment #3)
> To me it's C:L so the score is 4.3. That would iirc mean we don't do 
> a full security release and instead just release this as a bugfix 
> with a CVE assigned.

Yeah, depending also on how we feel about it, but so far nobody seems too bothered.

I've asked for a CVE. Andrew, can you git-format-patch the fix?

I think we are absolved from writing the full security advisory if we don't do a security release.
Comment 5 Andrew Walker 2025-08-28 19:44:34 UTC
Created attachment 18696 [details]
v4.23 fix
Comment 6 Andrew Walker 2025-08-28 19:45:44 UTC
Created attachment 18697 [details]
v4.23 test
Comment 7 Andrew Walker 2025-08-28 19:48:27 UTC
I wrote this initial patchset against v4.23-stable. Let me know if you want changes to either the patch or the test and I can rework as needed.
Comment 8 Volker Lendecke 2025-08-29 08:52:04 UTC
Comment on attachment 18697 [details]
v4.23 test

Haven't tested it myself, but the test looks good just from looking at it.
Comment 9 Douglas Bagnall 2025-09-10 07:44:41 UTC
Created attachment 18713 [details]
drafdt advisory

I wrote

> I think we are absolved from writing the full security advisory if we don't do a security release.

Actually on second thoughts we might as well, since we need to explain what is going on anyway.

I have had a bit of a go. Andrew or Volker, can you expand it a little bit and/or make it make sense?
Comment 10 Volker Lendecke 2025-09-10 08:06:55 UTC
One problem: I've already published a different fix as part of MR4212. This bug was the reason why I created talloc_realloc_zero(), nobody seemed too worried.
Comment 11 Douglas Bagnall 2025-09-12 04:43:09 UTC
(In reply to Volker Lendecke from comment #10)
I did wonder if that touched on this.

Is it backportable?

I'm don't know what the right thing to do is.
Comment 12 Douglas Bagnall 2025-09-18 02:59:08 UTC
(In reply to Douglas Bagnall from comment #11)
> Is it backportable?
>
> I'm don't know what the right thing to do is.

I'm thinking the simple fix should become part of the October 1 security release that we are already doing, then !4212 can go on top in master.
Comment 13 Douglas Bagnall 2025-10-03 03:19:08 UTC
Created attachment 18736 [details]
draft patch v2

The test needed a couple of tweaks to compile (also some trailing whitespace removed):

--- c/source4/torture/vfs/streams_xattr.c
+++ w/source4/torture/vfs/streams_xattr.c
@@ -39,7 +39,7 @@ static bool get_stream_handle(struct torture_context *tctx,
                              const char *sname,
                              struct smb2_handle *hdl_in)
 {
-       bool ret = true, ok;
+       bool ret = true;
        NTSTATUS status;
        struct smb2_handle fhandle = {{0}};
        struct smb2_handle dhandle = {{0}};
@@ -88,7 +88,7 @@ static bool read_stream(struct torture_context *tctx,
        status = smb2_read(tree, mem_ctx, &r);
        torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "stream read\n");
 
-       *data_out = r.out.data.data;
+       *data_out = (char *)r.out.data.data;
        *data_out_sz = r.out.data.length;
 

but I am still having trouble finding a way to make it run, so that I can check it fails.

Are the source4/torture/vfs/ tests run at all?
Comment 14 Douglas Bagnall 2025-10-03 03:36:29 UTC
Created attachment 18737 [details]
advisory v2
Comment 15 Douglas Bagnall 2025-10-03 03:51:18 UTC
Created attachment 18738 [details]
draft patch v3

patched the test into source3/selftest/tests.py, though it isn't failing without the fix.
Comment 16 Douglas Bagnall 2025-10-04 00:48:15 UTC
Created attachment 18739 [details]
patch v4
Comment 17 Douglas Bagnall 2025-10-04 00:49:31 UTC
Created attachment 18740 [details]
patch v4
Comment 18 Douglas Bagnall 2025-10-04 00:50:36 UTC
(In reply to Douglas Bagnall from comment #15)
> it isn't failing without the fix.

This is still the case.
Comment 19 Douglas Bagnall 2025-10-05 01:06:55 UTC
Created attachment 18741 [details]
patch v5

> it isn't failing without the fix.

because I wasn't running it in a share with streams_xattr.

NOW it fails without the fix.
Comment 20 Douglas Bagnall 2025-10-05 09:08:25 UTC
Created attachment 18745 [details]
patch for 4.23
Comment 21 Douglas Bagnall 2025-10-05 09:09:37 UTC
Created attachment 18746 [details]
patch for 4.22
Comment 22 Douglas Bagnall 2025-10-05 09:10:29 UTC
Created attachment 18747 [details]
patch for 4.21
Comment 23 Douglas Bagnall 2025-10-12 21:04:00 UTC
Created attachment 18753 [details]
advisory v3

Advisory v3 with $VERSIONS expanded.
Comment 24 Samba QA Contact 2025-10-15 12:18:45 UTC
This bug was referenced in samba v4-21-stable (Release samba-4.21.9):

ad80099b697d280bc03e47b9b8ab33615b0db262
52969774d136644360f998b329736c19e43f8140
Comment 25 Samba QA Contact 2025-10-15 12:19:21 UTC
This bug was referenced in samba v4-22-stable (Release samba-4.22.5):

44d71234dfffa52ad2579924813b67c9d8a37822
06bc23b5977f564fef31285a92ec28dc80b68edb
Comment 26 Samba QA Contact 2025-10-15 12:20:48 UTC
This bug was referenced in samba v4-23-stable (Release samba-4.23.2):

25cad91bcf14bbccb53077ceb8b5be2d1ef9ebc3
26b3ff3752eb90d21c2c1db51c16ba8a15fd7429
Comment 27 Jule Anger 2025-10-15 12:28:31 UTC
Removing vendor CC (so that any public comments don't need to be broadcast so widely) and opening these bugs to the public.
If you wish to continue to be informed about any changes here please CC individually.
Comment 28 Samba QA Contact 2025-10-15 13:16:36 UTC
This bug was referenced in samba v4-23-test:

25cad91bcf14bbccb53077ceb8b5be2d1ef9ebc3
26b3ff3752eb90d21c2c1db51c16ba8a15fd7429
Comment 29 Samba QA Contact 2025-10-15 13:17:18 UTC
This bug was referenced in samba v4-22-test:

44d71234dfffa52ad2579924813b67c9d8a37822
06bc23b5977f564fef31285a92ec28dc80b68edb
Comment 30 Samba QA Contact 2025-10-15 13:21:06 UTC
This bug was referenced in samba v4-21-test:

ad80099b697d280bc03e47b9b8ab33615b0db262
52969774d136644360f998b329736c19e43f8140
Comment 31 Samba QA Contact 2025-10-16 19:48:04 UTC
This bug was referenced in samba master:

59158cc3b74835193e0b058561206a3198adc3fe
1e899521e821f2ee4cbb93f6a3befd37f5ba0403