Skip to contentSkip to conversation

net: ipv6: tcp: fix potential use after free in tcp_v6_do_rcv

PATCH Applied Daniel Borkmann 5 participants 10 messages Sep 3, 2013 – Sep 4, 2013

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

PATCH 1/1 net: ipv6: tcp: fix potential use after free in tcp_v6_do_rcv

In tcp_v6_do_rcv() code, when processing pkt options, we soley work on our skb clone opt_skb that we've created earlier before entering tcp_rcv_established() on our way. However, only in condition ...

  if (np->rxopt.bits.rxtclass)
    np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));

... we work on skb itself. As we extract every other information out of opt_skb in ipv6_pktoptions path, this seems wrong, since skb can already be released by tcp_rcv_established() earlier on. When we try to access it in ipv6_hdr(), we will dereference freed skb.

---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +1 -1
index 6e1649d..eeb4cb0 100644
@@ -1427,7 +1427,7 @@ ipv6_pktoptions:
 		if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
 			np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
 		if (np->rxopt.bits.rxtclass)
-			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
+			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
 		if (ipv6_opt_accepted(sk, opt_skb)) {
 			skb_set_owner_r(opt_skb, sk);
 			opt_skb = xchg(&np->pktoptions, opt_skb);
Signature · 1 line
1.7.11.7
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Daniel Borkmann

In tcp_v6_do_rcv() code, when processing pkt options, we soley work on our skb clone opt_skb that we've created earlier before entering tcp_rcv_established() on our way. However, only in condition ...

  if (np->rxopt.bits.rxtclass)
    np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));

... we work on skb itself. As we extract every other information out of opt_skb in ipv6_pktoptions path, this seems wrong, since skb can already be released by tcp_rcv_established() earlier on. When we try to access it in ipv6_hdr(), we will dereference freed skb.

---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +0 -0
index 6e1649d..eeb4cb0 100644

net/ipv6/tcp_ipv6.c ipv6_pktoptions: · line 1433

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -1
@@ -1427,7 +1427,7 @@ ipv6_pktoptions:
 		if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
 			np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
 		if (np->rxopt.bits.rxtclass)
-			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
+			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
 		if (ipv6_opt_accepted(sk, opt_skb)) {
 			skb_set_owner_r(opt_skb, sk);
 			opt_skb = xchg(&np->pktoptions, opt_skb);

Bug added in commit 4c507d2897bd9b
("net: implement IP_RECVTOS for IP_PKTOPTIONS")

CC Jiri

#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 10:48:33 -0700

Quoted 37 lines · Daniel Borkmann
Quoted 23 lines

In tcp_v6_do_rcv() code, when processing pkt options, we soley work on our skb clone opt_skb that we've created earlier before entering tcp_rcv_established() on our way. However, only in condition ...

  if (np->rxopt.bits.rxtclass)
    np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));

... we work on skb itself. As we extract every other information out of opt_skb in ipv6_pktoptions path, this seems wrong, since skb can already be released by tcp_rcv_established() earlier on. When we try to access it in ipv6_hdr(), we will dereference freed skb.

---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +0 -0
index 6e1649d..eeb4cb0 100644

net/ipv6/tcp_ipv6.c ipv6_pktoptions: · line 1433

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -1
@@ -1427,7 +1427,7 @@ ipv6_pktoptions:
 		if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
 			np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
 		if (np->rxopt.bits.rxtclass)
-			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
+			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
 		if (ipv6_opt_accepted(sk, opt_skb)) {
 			skb_set_owner_r(opt_skb, sk);
 			opt_skb = xchg(&np->pktoptions, opt_skb);

Bug added in commit 4c507d2897bd9b
("net: implement IP_RECVTOS for IP_PKTOPTIONS")

Quoted 3 lines

CC Jiri

You made a mistake.

It was introduced in commit e7219858a ("ipv6: Use ipv6_get_dsfield() instead of ipv6_tclass()").

Cc the right party.

Signature · 1 line
Jean Sacren
#3 lore raw
Quoted 39 lines · Jean Sacren

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 10:48:33 -0700

Quoted 37 lines · Daniel Borkmann
Quoted 23 lines

In tcp_v6_do_rcv() code, when processing pkt options, we soley work on our skb clone opt_skb that we've created earlier before entering tcp_rcv_established() on our way. However, only in condition ...

  if (np->rxopt.bits.rxtclass)
    np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));

... we work on skb itself. As we extract every other information out of opt_skb in ipv6_pktoptions path, this seems wrong, since skb can already be released by tcp_rcv_established() earlier on. When we try to access it in ipv6_hdr(), we will dereference freed skb.

---
 net/ipv6/tcp_ipv6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +0 -0
index 6e1649d..eeb4cb0 100644

net/ipv6/tcp_ipv6.c ipv6_pktoptions: · line 1433

Quoted 8 lines
net/ipv6/tcp_ipv6.c +1 -1
@@ -1427,7 +1427,7 @@ ipv6_pktoptions:
 		if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
 			np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
 		if (np->rxopt.bits.rxtclass)
-			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
+			np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
 		if (ipv6_opt_accepted(sk, opt_skb)) {
 			skb_set_owner_r(opt_skb, sk);
 			opt_skb = xchg(&np->pktoptions, opt_skb);

Bug added in commit 4c507d2897bd9b
("net: implement IP_RECVTOS for IP_PKTOPTIONS")

Quoted 5 lines
Quoted 3 lines

CC Jiri

You made a mistake.

Really ?

Quoted 6 lines

It was introduced in commit e7219858a ("ipv6: Use ipv6_get_dsfield() instead of ipv6_tclass()").

Cc the right party.

Nope, I did no mistake.

The bug was really added in commit 4c507d2897bd9b as I said.

Then commit e7219858a just did no change : skb was used before and after the patch

- np->rcv_tclass = ipv6_tclass(ipv6_hdr(skb));
+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));

How did you get your conclusion ?

#4 lore raw

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 13:35:17 -0700

Quoted 2 lines

How did you get your conclusion ?

If one changes one line of code, doesn't one own that line?

Signature · 1 line
Jean Sacren
#5 lore raw
Quoted 6 lines · Jean Sacren

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 13:35:17 -0700

Quoted 2 lines

How did you get your conclusion ?

If one changes one line of code, doesn't one own that line?

The question is not about who currently "owns" the line, but who first *introduced* an error.

#6 lore raw
In reply to Jean Sacren
Quoted 7 lines · Jean Sacren

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 13:35:17 -0700

Quoted 2 lines

How did you get your conclusion ?

If one changes one line of code, doesn't one own that line?

'Owning' like he is the guy who can sell it ? OK I understand now so many people send 'cleanups' ;)

Someone adding a space is not responsible for the real bug.

You'll have to be very careful to do proper attributions.

This is _critical_ for proper stable submissions.

In this case we want the fix to reach linux-3.4 and further versions.

The commit you pointed out was for linux-3.9, and added no bug.

#7 lore raw

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 15:29:12 -0700

Quoted 12 lines · Jean Sacren
Quoted 7 lines

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 13:35:17 -0700

Quoted 2 lines

How did you get your conclusion ?

If one changes one line of code, doesn't one own that line?

'Owning' like he is the guy who can sell it ? OK I understand now so many people send 'cleanups' ;)

'Owning' like he is the guy who is responsible for the change. Whether you understand it or not, that's your own business.

The idea was by taking one example to determine who is really to blame
for: Is the one passing on the bug responsible? Thanks to Daniel Borkmann for the answer.

Signature · 1 line
Jean Sacren
Acked-by
#8 lore raw
Quoted 15 lines · Jean Sacren

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 15:29:12 -0700

Quoted 12 lines · Jean Sacren
Quoted 7 lines

From: Eric Dumazet <[email protected]>
Date: Tue, 03 Sep 2013 13:35:17 -0700

Quoted 2 lines

How did you get your conclusion ?

If one changes one line of code, doesn't one own that line?

'Owning' like he is the guy who can sell it ? OK I understand now so many people send 'cleanups' ;)

Quoted 6 lines

'Owning' like he is the guy who is responsible for the change. Whether you understand it or not, that's your own business.

The idea was by taking one example to determine who is really to blame
for: Is the one passing on the bug responsible? Thanks to Daniel Borkmann for the answer.

Eric is correct, the bug was introduced by me.

Sorry for it. Daniel, thanks for fixing it.

Signature · 1 line
Jiri Benc
maintainer Applied
#9 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Tue, 3 Sep 2013 19:29:12 +0200

Quoted 7 lines

In tcp_v6_do_rcv() code, when processing pkt options, we soley work on our skb clone opt_skb that we've created earlier before entering tcp_rcv_established() on our way. However, only in condition ...

  if (np->rxopt.bits.rxtclass)
    np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
Quoted 7 lines

... we work on skb itself. As we extract every other information out of opt_skb in ipv6_pktoptions path, this seems wrong, since skb can already be released by tcp_rcv_established() earlier on. When we try to access it in ipv6_hdr(), we will dereference freed skb.

Applied.