OpenSSH: Memory corruption in AES-GCM support
A memory corruption flaw in OpenSSH's AES-GCM support meant that during rekeying, an uninitialised MAC context's cleanup callback pointer was called, potentially allowing code execution as the authenticated user. Exploitation was difficult due to heap layout and ASLR.
- Fixed in under an hour
- Paid in 27 days
- Disclosed after under an hour
-
Vulnerability
A memory corruption vulnerability exists in the post- authentication sshd process when an AES-GCM cipher ([email protected] or [email protected]) is selected during kex exchange.
If exploited, this vulnerability might permit code execution with the privileges of the authenticated user and may therefore allow bypassing restricted shell/command configurations.
-
Affected configurations
OpenSSH 6.2 and OpenSSH 6.3 when built against an OpenSSL that supports AES-GCM.
-
Mitigation
Disable AES-GCM in the server configuration. The following sshd_config option will disable AES-GCM while leaving other ciphers active:
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc
-
Details
When using AES-GCM, sshd was not initialising a Message Authentication Code (MAC) context that is unused when the cipher mode offers authentication itself. This context contains some callback pointers, including a cleanup callback that was still being invoked during a rekeying operation. As such, the address being called was derived from previous heap contents.
This vulnerability is mitigated by the difficulty of pre-loading the heap with a useful callback address and by any platform address-space layout randomisation applied to sshd and the shared libraries it depends upon.
-
Credit
This issue was identified by Markus Friedl (an OpenSSH developer) on November 7th, 2013.
-
Fix
OpenSSH 6.4 contains a fix for this vulnerability. Users who prefer to continue to use OpenSSH 6.2 or 6.3 may apply this patch:
Index: monitor_wrap.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/monitor_wrap.c,v
retrieving revision 1.76
diff -u -p -u -r1.76 monitor_wrap.c
--- monitor_wrap.c 17 May 2013 00:13:13 -0000 1.76
+++ monitor_wrap.c 6 Nov 2013 16:31:26 -0000
@@ -469,7 +469,7 @@ mm_newkeys_from_blob(u_char *blob, int b
buffer_init(&b);
buffer_append(&b, blob, blen);
- newkey = xmalloc(sizeof(*newkey));
+ newkey = xcalloc(1, sizeof(*newkey));
enc = &newkey->enc;
mac = &newkey->mac;
comp = &newkey->comp;
This document may be found at: http://www.openssh.com/txt/gcmrekey.adv
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the MAC context was allocated with xmalloc instead of xcalloc, leaving callback pointers uninitialised, and a cleanup callback was still invoked during rekeying.
Impact
If exploited, this vulnerability might permit code execution with the privileges of the authenticated user and may therefore allow bypassing restricted shell/command configurations.
What the attacker needed
Authenticated SSH session; AES-GCM cipher selected; OpenSSH 6.2 or 6.3 with AES-GCM OpenSSL
The fix
OpenSSH 6.4 contains a fix; for 6.2 or 6.3 a patch changes the allocation to zero-initialise the structure.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program uses a cipher that checks data integrity itself, it may skip setting up a separate integrity check. In this case, a pointer meant for cleanup was left uninitialised, so during a key change the program called an address from old memory. An attacker who could control that memory might run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.