Skip to contentSkip to conversation

slirp: udp: fix NULL pointer dereference because of uninitialized socket

PATCH Applied Petr Matousek 6 participants 6 messages Sep 18, 2014 – Sep 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 slirp: udp: fix NULL pointer dereference because of uninitialized socket

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Fix this by checking that the socket is not just a socket stub.

This is CVE-2014-3640.

---
v1 -> v2
* change the check so that it's consistent with the rest of the code

 slirp/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/udp.c +1 -1
index 8cc6cb6..f77e00f 100644
@@ -152,7 +152,7 @@ udp_input(register struct mbuf *m, int iphlen)
 	 * Locate pcb for datagram.
 	 */
 	so = slirp->udp_last_so;
-	if (so->so_lport != uh->uh_sport ||
+	if (so == &slirp->udb || so->so_lport != uh->uh_sport ||
 	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
 		struct socket *tmp;
 
Signature · 1 line
1.9.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 25 lines · Petr Matousek

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Fix this by checking that the socket is not just a socket stub.

This is CVE-2014-3640.

---
v1 -> v2
* change the check so that it's consistent with the rest of the code

 slirp/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/udp.c +0 -0
index 8cc6cb6..f77e00f 100644

slirp/udp.c udp_input(register struct mbuf *m, int iphlen) · line 158

Quoted 8 lines
slirp/udp.c +1 -1
@@ -152,7 +152,7 @@ udp_input(register struct mbuf *m, int iphlen)
 	 * Locate pcb for datagram.
 	 */
 	so = slirp->udp_last_so;
-	if (so->so_lport != uh->uh_sport ||
+	if (so == &slirp->udb || so->so_lport != uh->uh_sport ||
 	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
 		struct socket *tmp;
 

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
Reviewed-by on v2 1/1
#2 lore raw
In reply to Petr Matousek
Quoted 5 lines · Petr Matousek

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Quoted 7 lines

Fix this by checking that the socket is not just a socket stub.

This is CVE-2014-3640.

Quoted 22 lines

---
v1 -> v2
* change the check so that it's consistent with the rest of the code

 slirp/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/udp.c +1 -1
index 8cc6cb6..f77e00f 100644
@@ -152,7 +152,7 @@ udp_input(register struct mbuf *m, int iphlen)
 	 * Locate pcb for datagram.
 	 */
 	so = slirp->udp_last_so;
-	if (so->so_lport != uh->uh_sport ||
+	if (so == &slirp->udb || so->so_lport != uh->uh_sport ||
 	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
 		struct socket *tmp;
 
Signature · 1 line
1.9.3
#3 lore raw
In reply to Petr Matousek

Quoting Petr Matousek (2014-09-18 01:35:37)

Quoted 5 lines

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Quoted 7 lines

Fix this by checking that the socket is not just a socket stub.

This is CVE-2014-3640.

Ping. Looking to pull this in for 2.1.2. Release is "asap"

Quoted 22 lines

---
v1 -> v2
* change the check so that it's consistent with the rest of the code

 slirp/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/udp.c +1 -1
index 8cc6cb6..f77e00f 100644
@@ -152,7 +152,7 @@ udp_input(register struct mbuf *m, int iphlen)
         * Locate pcb for datagram.
         */
        so = slirp->udp_last_so;
-       if (so->so_lport != uh->uh_sport ||
+       if (so == &slirp->udb || so->so_lport != uh->uh_sport ||
            so->so_laddr.s_addr != ip->ip_src.s_addr) {
                struct socket *tmp;
 
Signature · 1 line
1.9.3
Reviewed-by on v2 1/1
#4 lore raw
In reply to Petr Matousek
Quoted 5 lines · Petr Matousek

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Quoted 7 lines

Fix this by checking that the socket is not just a socket stub.

This is CVE-2014-3640.

slirp->udb initially is a dummy element of the list which initially points to itself and never gets used (and slirp->udp_last_so initially points to it too).

Thanks,

/mjt

Quoted 17 lines
 slirp/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
slirp/udp.c +1 -1
index 8cc6cb6..f77e00f 100644
@@ -152,7 +152,7 @@ udp_input(register struct mbuf *m, int iphlen)
 	 * Locate pcb for datagram.
 	 */
 	so = slirp->udp_last_so;
-	if (so->so_lport != uh->uh_sport ||
+	if (so == &slirp->udb || so->so_lport != uh->uh_sport ||
 	    so->so_laddr.s_addr != ip->ip_src.s_addr) {
 		struct socket *tmp;
 
#5 lore raw
Quoted 8 lines · Michael Tokarev
Quoted 7 lines · Petr Matousek

When guest sends udp packet with source port and source addr 0, uninitialized socket is picked up when looking for matching and already created udp sockets, and later passed to sosendto() where NULL pointer dereference is hit during so->slirp->vnetwork_mask.s_addr access.

Fix this by checking that the socket is not just a socket stub.

Quoted 7 lines
Quoted 5 lines

This is CVE-2014-3640.

Applied to master, thanks.

-- PMM