All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net] net: drop skb on failure in ip_check_defrag()
@ 2018-11-01 19:02 Cong Wang
  2018-11-01 19:08 ` Eric Dumazet
  2018-11-01 20:56 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2018-11-01 19:02 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Eric Dumazet

Most callers of pskb_trim_rcsum() simply drop the skb when
it fails, however, ip_check_defrag() still continues to pass
the skb up to stack. This is suspicious.

In ip_check_defrag(), after we learn the skb is an IP fragment,
passing the skb to callers makes no sense, because callers expect
fragments are defrag'ed on success. So, dropping the skb when we
can't defrag it is reasonable.

Note, prior to commit 88078d98d1bb, this is not a big problem as
checksum will be fixed up anyway. After it, the checksum is not
correct on failure.

Found this during code review.

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/ipv4/ip_fragment.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 9b0158fa431f..d6ee343fdb86 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -722,10 +722,14 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
 	if (ip_is_fragment(&iph)) {
 		skb = skb_share_check(skb, GFP_ATOMIC);
 		if (skb) {
-			if (!pskb_may_pull(skb, netoff + iph.ihl * 4))
-				return skb;
-			if (pskb_trim_rcsum(skb, netoff + len))
-				return skb;
+			if (!pskb_may_pull(skb, netoff + iph.ihl * 4)) {
+				kfree_skb(skb);
+				return NULL;
+			}
+			if (pskb_trim_rcsum(skb, netoff + len)) {
+				kfree_skb(skb);
+				return NULL;
+			}
 			memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
 			if (ip_defrag(net, skb, user))
 				return NULL;
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: drop skb on failure in ip_check_defrag()
  2018-11-01 19:02 [Patch net] net: drop skb on failure in ip_check_defrag() Cong Wang
@ 2018-11-01 19:08 ` Eric Dumazet
  2018-11-01 20:56 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2018-11-01 19:08 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: Eric Dumazet



On 11/01/2018 12:02 PM, Cong Wang wrote:
> Most callers of pskb_trim_rcsum() simply drop the skb when
> it fails, however, ip_check_defrag() still continues to pass
> the skb up to stack. This is suspicious.
> 
> In ip_check_defrag(), after we learn the skb is an IP fragment,
> passing the skb to callers makes no sense, because callers expect
> fragments are defrag'ed on success. So, dropping the skb when we
> can't defrag it is reasonable.
> 
> Note, prior to commit 88078d98d1bb, this is not a big problem as
> checksum will be fixed up anyway. After it, the checksum is not
> correct on failure.
> 
> Found this during code review.
> 
> Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Thanks Cong !

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: drop skb on failure in ip_check_defrag()
  2018-11-01 19:02 [Patch net] net: drop skb on failure in ip_check_defrag() Cong Wang
  2018-11-01 19:08 ` Eric Dumazet
@ 2018-11-01 20:56 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-11-01 20:56 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, edumazet

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Thu,  1 Nov 2018 12:02:37 -0700

> Most callers of pskb_trim_rcsum() simply drop the skb when
> it fails, however, ip_check_defrag() still continues to pass
> the skb up to stack. This is suspicious.
> 
> In ip_check_defrag(), after we learn the skb is an IP fragment,
> passing the skb to callers makes no sense, because callers expect
> fragments are defrag'ed on success. So, dropping the skb when we
> can't defrag it is reasonable.
> 
> Note, prior to commit 88078d98d1bb, this is not a big problem as
> checksum will be fixed up anyway. After it, the checksum is not
> correct on failure.
> 
> Found this during code review.
> 
> Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-02  6:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01 19:02 [Patch net] net: drop skb on failure in ip_check_defrag() Cong Wang
2018-11-01 19:08 ` Eric Dumazet
2018-11-01 20:56 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.