Skip to contentSkip to conversation

udp: prevent bugcheck if filter truncates packet too much

PATCH In review Michal Kubecek 6 participants 7 messages Jul 8, 2016 – Jul 11, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp: prevent bugcheck if filter truncates packet too much

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")
---
 net/ipv4/udp.c | 2 ++
 net/ipv6/udp.c | 2 ++
 2 files changed, 4 insertions(+)
net/ipv4/udp.c +2 -0
index ca5e8ea29538..4aed8fc23d32 100644
@@ -1583,6 +1583,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
net/ipv6/udp.c +2 -0
index 005dc82c2138..acc09705618b 100644
@@ -620,6 +620,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
Signature · 1 line
2.9.0
Acked-by on v1 1/1
#1 lore raw
Quoted 33 lines · Michal Kubecek

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")
---
 net/ipv4/udp.c | 2 ++
 net/ipv6/udp.c | 2 ++
 2 files changed, 4 insertions(+)
net/ipv4/udp.c +2 -0
index ca5e8ea29538..4aed8fc23d32 100644
@@ -1583,6 +1583,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
net/ipv6/udp.c +0 -0
index 005dc82c2138..acc09705618b 100644

net/ipv6/udp.c int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 627

Quoted 8 lines
net/ipv6/udp.c +2 -0
@@ -620,6 +620,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {

Arg :(

Thanks !

#2 lore raw
Quoted 40 lines · Eric Dumazet
Quoted 39 lines · Michal Kubecek

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")
---
 net/ipv4/udp.c | 2 ++
 net/ipv6/udp.c | 2 ++
 2 files changed, 4 insertions(+)
net/ipv4/udp.c +2 -0
index ca5e8ea29538..4aed8fc23d32 100644
@@ -1583,6 +1583,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
net/ipv6/udp.c +2 -0
index 005dc82c2138..acc09705618b 100644
@@ -620,6 +620,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
Quoted 7 lines

net/ipv6/udp.c int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 627

Quoted 2 lines
net/ipv6/udp.c +0 -0
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {

Arg :(

this is incomplete fix. Please do not apply. See discussion at security@kernel

#3 lore raw
Quoted 47 lines · Alexei Starovoitov
Quoted 46 lines · Eric Dumazet
Quoted 33 lines · Michal Kubecek

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")
---
  net/ipv4/udp.c | 2 ++
  net/ipv6/udp.c | 2 ++
  2 files changed, 4 insertions(+)
net/ipv4/udp.c +2 -0
index ca5e8ea29538..4aed8fc23d32 100644
@@ -1583,6 +1583,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
  	if (sk_filter(sk, skb))
  		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
  	udp_csum_pull_header(skb);
  	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
net/ipv6/udp.c +0 -0
index 005dc82c2138..acc09705618b 100644

net/ipv6/udp.c int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 627

Quoted 8 lines
net/ipv6/udp.c +2 -0
@@ -620,6 +620,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
  	if (sk_filter(sk, skb))
  		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
  	udp_csum_pull_header(skb);
  	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {

Arg :(

Quoted 3 lines
Quoted 1 line

this is incomplete fix. Please do not apply. See discussion at security@kernel

Ohh well, didn't see it earlier before starting the discussion at security@...

I'm okay if we take this for now as a quick band aid and find a better way how to deal with the underlying issue long-term so that it's /guaranteed/ that it doesn't bite us any further in such fragile ways.

#4 lore raw
Quoted 50 lines · Daniel Borkmann
Quoted 49 lines · Alexei Starovoitov
Quoted 47 lines · Eric Dumazet
Quoted 33 lines · Michal Kubecek

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")
---
 net/ipv4/udp.c | 2 ++
 net/ipv6/udp.c | 2 ++
 2 files changed, 4 insertions(+)
net/ipv4/udp.c +2 -0
index ca5e8ea29538..4aed8fc23d32 100644
@@ -1583,6 +1583,8 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
net/ipv6/udp.c +0 -0
index 005dc82c2138..acc09705618b 100644

net/ipv6/udp.c int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) · line 627

Quoted 8 lines
net/ipv6/udp.c +2 -0
@@ -620,6 +620,8 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 	if (sk_filter(sk, skb))
 		goto drop;
+	if (unlikely(skb->len < sizeof(struct udphdr)))
+		goto drop;
 
 	udp_csum_pull_header(skb);
 	if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {

Arg :(

Quoted 7 lines
Quoted 1 line

this is incomplete fix. Please do not apply. See discussion at security@kernel

Ohh well, didn't see it earlier before starting the discussion at security@...

I'm okay if we take this for now as a quick band aid and find a better way how to deal with the underlying issue long-term so that it's /guaranteed/ that it doesn't bite us any further in such fragile ways.

Agreed. As rc7 is due in a day or two, rushing a complex and intrusive solution in might be too risky.

Michal Kubecek

#5 lore raw
Quoted 20 lines · Michal Kubecek
Quoted 19 lines · Daniel Borkmann
Quoted 17 lines · Alexei Starovoitov
Quoted 8 lines · Eric Dumazet
Quoted 7 lines · Michal Kubecek

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Quoted 6 lines
Quoted 4 lines
Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")

---

this is incomplete fix. Please do not apply. See discussion at security@kernel

Quoted 8 lines
Quoted 5 lines

Ohh well, didn't see it earlier before starting the discussion at security@...

I'm okay if we take this for now as a quick band aid and find a better way how to deal with the underlying issue long-term so that it's /guaranteed/ that it doesn't bite us any further in such fragile ways.

Agreed. As rc7 is due in a day or two, rushing a complex and intrusive solution in might be too risky.

Thanks, Michal.

maintainer
#6 lore raw
In reply to Michal Kubecek

From: Michal Kubecek <[email protected]>
Date: Fri, 8 Jul 2016 17:52:33 +0200 (CEST)

Quoted 10 lines

If socket filter truncates an udp packet below the length of UDP header in udpv6_queue_rcv_skb() or udp_queue_rcv_skb(), it will trigger a BUG_ON in skb_pull_rcsum(). This BUG_ON (and therefore a system crash if kernel is configured that way) can be easily enforced by an unprivileged user which was reported as CVE-2016-6162. For a reproducer, see
http://seclists.org/oss-sec/2016/q3/8

Fixes e6afc8ace6dd ("udp: remove headers from UDP packets before queueing")

Applied and queued up for -stable, thanks.