Bug 15072 (CVE-2022-2127) - CVE-2022-2127 [SECURITY] lm_resp_len not checked properly in winbindd_pam_auth_crap_send()
Summary: CVE-2022-2127 [SECURITY] lm_resp_len not checked properly in winbindd_pam_aut...
Status: RESOLVED FIXED
Alias: CVE-2022-2127
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Winbind (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Ralph Böhme
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks: 15396
  Show dependency treegraph
 
Reported: 2022-05-20 08:58 UTC by Volker Lendecke
Modified: 2023-07-28 12:17 UTC (History)
5 users (show)

See Also:


Attachments
patch (3.58 KB, text/plain)
2022-05-20 09:00 UTC, Volker Lendecke
no flags Details
patch (3.63 KB, patch)
2022-05-20 09:02 UTC, Volker Lendecke
no flags Details
draft advisory (1.52 KB, text/plain)
2023-06-07 10:00 UTC, Volker Lendecke
slow: review+
Details
Patch for master (2.59 KB, patch)
2023-06-15 09:29 UTC, Ralph Böhme
slow: review+
slow: ci-passed+
Details
Advisory v2 (1.95 KB, text/plain)
2023-06-16 12:48 UTC, Ralph Böhme
abartlet: review-
Details
Advisory v3 (2.73 KB, text/plain)
2023-06-19 06:23 UTC, Andrew Bartlett
slow: review+
Details
Patch for master (3.97 KB, patch)
2023-06-19 12:11 UTC, Ralph Böhme
vl: review+
slow: review+
slow: ci-passed+
Details
Patch for 4.18 (3.97 KB, patch)
2023-06-23 14:12 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for 4.17 (3.97 KB, patch)
2023-06-23 14:13 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for 4.16 (6.88 KB, patch)
2023-06-23 16:45 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for master (3.97 KB, patch)
2023-06-26 07:42 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for 4.18 (3.97 KB, patch)
2023-06-26 07:43 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for 4.17 (3.97 KB, patch)
2023-06-26 07:44 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details
Patch for 4.16 (6.88 KB, patch)
2023-06-26 07:44 UTC, Ralph Böhme
vl: review+
slow: ci-passed+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Lendecke 2022-05-20 08:58:59 UTC
Have patch, need bugnumber
Comment 1 Volker Lendecke 2022-05-20 09:00:54 UTC
Created attachment 17292 [details]
patch

The reproducer crashes winbind with wbinfo -a
Comment 2 Volker Lendecke 2022-05-20 09:02:24 UTC
Created attachment 17293 [details]
patch
Comment 3 Jeremy Allison 2022-06-08 17:26:49 UTC
Ping ? Do we need a CVE for this or can we just fix with the attached patch ?

If we need a CVE it would be nice to get this in with the upcoming security release.
Comment 4 Jeremy Allison 2022-06-15 17:18:59 UTC
According to Volker via Ralph this crashes the parent winbindd, so we need a CVE for this.
Comment 5 Jeremy Allison 2022-06-15 18:37:16 UTC
Requested a CVE from Red Hat product security.
Comment 6 Jeremy Allison 2022-06-16 16:27:14 UTC
OK, checked this some more and it's using WINBINDD_PAM_AUTH_CRAP, which is only available on the winbind privilaged pipe via wbcRequestResponsePriv().

In this case, is it a CVE-worthy bug ? I'm inclined to think this is now a self-DOS (you already need root to trigger it), which by default we don't treat as a CVE.

Ralph, can you help make an executive decision here when you're back from vacation ?

Thanks,

Jeremy.
Comment 7 Douglas Bagnall 2023-02-01 20:15:23 UTC
Do we still want the CVE? Apparently CVE-2022-2127 was offered.
Comment 8 Jeremy Allison 2023-02-02 22:43:20 UTC
Looks like this one got dropped. Ralph, do you want to make the executive decision here ? As it seems to be a self-root DoS I think we can just fix and move on.
Comment 9 Andrew Bartlett 2023-02-04 10:44:01 UTC
I think, but have not proved, that the length of an LM element from an NTLMSSP packet parsed by ntlm_auth (eg as presented to squid or mod_auth_ntlm_winbind) is passed along here.
Comment 10 Douglas Bagnall 2023-02-28 02:56:33 UTC
Is comment 9 countering comment 8 and saying maybe we really do need the CVE?
Comment 11 Andrew Bartlett 2023-03-01 03:16:29 UTC
(In reply to Douglas Bagnall from comment #10)
Yes, that is my view.
Comment 13 Andrew Bartlett 2023-03-19 00:42:29 UTC
CVSS3.1:AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H (5.9) on the basis that it would, if done successfully, crash the parent winbindd.  Attack complexity is "High" as I so far have been unable to make it crash, but have proved the flow described in comment #9 is possible.
Comment 14 Ralph Böhme 2023-06-07 08:46:18 UTC
Hi Volker!

Can you draft a CVE advisory text please? Cf the template in the team repo at doc/releases/template_security_advisory.txt.

Thanks!
Comment 15 Volker Lendecke 2023-06-07 10:00:08 UTC
Created attachment 17909 [details]
draft advisory
Comment 16 Ralph Böhme 2023-06-07 10:13:49 UTC
Comment on attachment 17909 [details]
draft advisory

Thanks! Lgtm.
Comment 17 Ralph Böhme 2023-06-15 09:29:06 UTC
Created attachment 17923 [details]
Patch for master
Comment 18 Andrew Bartlett 2023-06-15 20:10:54 UTC
We should make really clear that the exploitable path is only via ntlm_auth (to remote users) or local privileged users (with rights to access the privileged socket).

The reason is the differences between the access libraries:

this in wbc_pam.c (as used by auth_winbind in smbd as a file server)

		request.data.auth_crap.lm_resp_len =
				MIN(params->password.response.lm_length,
				    sizeof(request.data.auth_crap.lm_resp));

this is ntlm_auth.c
		request.data.auth_crap.lm_resp_len = lm_response->length;

(The AD DC, from the source4 auth_winbind module, does a SamLogon over IRPC, and is not using the winbind pipe protocol)
Comment 19 Ralph Böhme 2023-06-16 06:09:23 UTC
(In reply to Andrew Bartlett from comment #18)
I guess what you're saying is that the advisory should be expanded a bit to cover this? I see what I can do. :)
Comment 20 Ralph Böhme 2023-06-16 06:26:51 UTC
(In reply to Ralph Böhme from comment #19)
Ok, so what about adding this paragraph to the description:

To exploit this vulnarebility the user must have either access to the
priviliged winbindd UNIX domain socket or, if the system is running
Samba ntlm_auth as authentication backend for services like Squid or
FreeRADIUS, the vulnarebility is remotely exploitable.
Comment 21 Volker Lendecke 2023-06-16 06:50:55 UTC
(In reply to Ralph Böhme from comment #20)
> To exploit this vulnarebility the user must have either access to the
> priviliged winbindd UNIX domain socket or, if the system is running
        ^
  I think this is "privileged"

and I would add "(which means being root already)" to that sentence.
Comment 22 Ralph Böhme 2023-06-16 07:53:44 UTC
(In reply to Volker Lendecke from comment #21)
Fixed and added. Thanks!

Doesn't the ntlm_auth vector also imply Attack Complexity Low instead of High which gives a CVSS score of 7.5?

What about chaning the CVSS section to:

---8<---
Systems without ntlm_auth configured:

CVSS3.1:AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H (5.9)

With ntlm_auth configured:

CVSS3.1:AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H (7.5)
---8<---
Comment 23 Andrew Bartlett 2023-06-16 09:27:04 UTC
(In reply to Ralph Böhme from comment #22)
For the case with ntlm_auth I had the attack complexity as high as I couldn't make it crash 'on demand' even in the  controlled conditions in testenv.  I did however show the overflow with valgrind or address santitizer (I can't recall which), but that flow path including what you can pass over NTLMSSP actually has some restrictions (thankfully!), you can't just set the length to 0x1000000. 

The local case that Volker reproduced in comment #1 has fewer restrictions on the length, but has privileges required.  

I rate it AV:L/AC:L/PR:H/UI:N/S:U/C:N/I:N/A:H (4.4) for the local case (no ntlm_auth in use).
Comment 24 Ralph Böhme 2023-06-16 12:48:48 UTC
Created attachment 17924 [details]
Advisory v2
Comment 25 Ralph Böhme 2023-06-16 12:51:51 UTC
I wonder whether we should do an additional change to ntlm_auth that fixes setting the correct lm buffer size, like so:

--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -575,10 +575,14 @@ NTSTATUS contact_winbind_auth_crap(const char *username,
        memcpy(request.data.auth_crap.chal, challenge->data, MIN(challenge->length, 8));
 
        if (lm_response && lm_response->length) {
+               size_t capped_lm_response_len = MIN(
+                       lm_response->length,
+                       sizeof(request.data.auth_crap.lm_resp));
+
                memcpy(request.data.auth_crap.lm_resp,
                       lm_response->data,
-                      MIN(lm_response->length, sizeof(request.data.auth_crap.lm_resp)));
-               request.data.auth_crap.lm_resp_len = lm_response->length;
+                      capped_lm_response_len);
+               request.data.auth_crap.lm_resp_len = capped_lm_response_len;
        }
 
Thoughts?
Comment 26 Andrew Bartlett 2023-06-16 20:00:02 UTC
Comment on attachment 17924 [details]
Advisory v2

Thanks, this is better but to be clear, the winbind privileged socket is not root only, the typical pattern for use with ntlm_auth is to have it made available to a group that you add eg FreeRADIUS, apache2 or squid to. 

Say:

(which means being root or in a special group already, typically assigned to services like FreeRADIUS or Squid that use the ntlm_auth tool)

For workaround, say:

Removing non-root access to the winbind privileged socket (***with a detail on what that is and particularly where that is***), however this will disable use of ntlm_auth for use in (eg) Squid or FreeRADIUS.
Comment 27 Andrew Bartlett 2023-06-19 06:23:22 UTC
Created attachment 17926 [details]
Advisory v3

I think this is clearer, and rather than ask to have you fix things and ask me back, I had a go at updating the text.

The workaround instructions should be manually tested (I've not done that), but a chgrp to root should be harmless. 

I'm happy for my words to be further updated, I am just keen to help where I can with the text.
Comment 28 Ralph Böhme 2023-06-19 07:59:19 UTC
Comment on attachment 17926 [details]
Advisory v3

Excellent, thanks! Saves me a lot of headscratching... :)
Comment 29 Ralph Böhme 2023-06-19 10:27:57 UTC
(In reply to Ralph Böhme from comment #25)
ping
Comment 30 Ralph Böhme 2023-06-19 12:11:28 UTC
Created attachment 17927 [details]
Patch for master
Comment 31 Volker Lendecke 2023-06-21 14:28:01 UTC
Comment on attachment 17927 [details]
Patch for master

There's a typo in the 2nd commit message (lanmen vs lanman), but apart from that it's good.
Comment 32 Ralph Böhme 2023-06-23 14:12:41 UTC
Created attachment 17939 [details]
Patch for 4.18
Comment 33 Ralph Böhme 2023-06-23 14:13:10 UTC
Created attachment 17940 [details]
Patch for 4.17
Comment 34 Ralph Böhme 2023-06-23 16:45:27 UTC
Created attachment 17949 [details]
Patch for 4.16
Comment 35 Ralph Böhme 2023-06-26 07:42:52 UTC
Created attachment 17954 [details]
Patch for master

Fixed typo lanmen -> lanman
Comment 36 Ralph Böhme 2023-06-26 07:43:30 UTC
Created attachment 17955 [details]
Patch for 4.18

Fixed typo lanmen -> lanman
Comment 37 Ralph Böhme 2023-06-26 07:44:05 UTC
Created attachment 17956 [details]
Patch for 4.17
Comment 38 Ralph Böhme 2023-06-26 07:44:49 UTC
Created attachment 17957 [details]
Patch for 4.16

Fixed typo lanmen -> lanman
Comment 39 Ralph Böhme 2023-07-07 14:23:42 UTC
Proposed release date for this CVE is the 19th of July.
Comment 40 Jule Anger 2023-07-19 14:23:25 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 41 Samba QA Contact 2023-07-19 14:29:12 UTC
This bug was referenced in samba v4-16-stable (Release samba-4.16.11):

5c6fe5a491b16bb658c191cfafb5edc0beb5fab2
2eabbe31f64a8456813a502afb05907beb46ffad
Comment 42 Samba QA Contact 2023-07-19 14:30:24 UTC
This bug was referenced in samba v4-17-stable (Release samba-4.17.10):

a3944de6990686bf674e7a9badded501873a7cfa
53838682570135b753fa622dfcde111528563c2d
Comment 43 Samba QA Contact 2023-07-19 14:31:34 UTC
This bug was referenced in samba v4-18-stable (Release samba-4.18.5):

19dcb036cb8d21bf4e3e30d81eee3c79e54d3eff
b09567397c2f394ca224c189cfbb1bee9688a96f
Comment 44 Samba QA Contact 2023-07-19 14:56:43 UTC
This bug was referenced in samba v4-16-test:

5c6fe5a491b16bb658c191cfafb5edc0beb5fab2
2eabbe31f64a8456813a502afb05907beb46ffad
Comment 45 Samba QA Contact 2023-07-19 14:59:38 UTC
This bug was referenced in samba v4-17-test:

a3944de6990686bf674e7a9badded501873a7cfa
53838682570135b753fa622dfcde111528563c2d
Comment 46 Samba QA Contact 2023-07-19 15:07:26 UTC
This bug was referenced in samba v4-18-test:

19dcb036cb8d21bf4e3e30d81eee3c79e54d3eff
b09567397c2f394ca224c189cfbb1bee9688a96f
Comment 47 Samba QA Contact 2023-07-21 13:04:13 UTC
This bug was referenced in samba master:

b2de71734f09ee4eb80cf70de8a66f628246f2ba
e067c523b17951a93b6daafd349e9371f8f81e56
Comment 48 Jule Anger 2023-07-21 14:59:50 UTC
Pushed to all branches.
Closing out bug report.
Thanks!
Comment 49 Samba QA Contact 2023-07-28 12:14:39 UTC
This bug was referenced in samba v4-19-test:

b2de71734f09ee4eb80cf70de8a66f628246f2ba
e067c523b17951a93b6daafd349e9371f8f81e56
Comment 50 Samba QA Contact 2023-07-28 12:17:14 UTC
This bug was referenced in samba v4-19-stable (Release samba-4.19.0rc1):

b2de71734f09ee4eb80cf70de8a66f628246f2ba
e067c523b17951a93b6daafd349e9371f8f81e56