From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [Patch net] net: make pskb_trim_rcsum_slow() robust Date: Mon, 29 Oct 2018 19:14:44 -0700 Message-ID: References: <20181030003515.12075-1-xiyou.wangcong@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: Eric Dumazet To: Cong Wang , netdev@vger.kernel.org Return-path: Received: from mail-pl1-f195.google.com ([209.85.214.195]:43405 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbeJ3LGO (ORCPT ); Tue, 30 Oct 2018 07:06:14 -0400 Received: by mail-pl1-f195.google.com with SMTP id g59-v6so705664plb.10 for ; Mon, 29 Oct 2018 19:14:47 -0700 (PDT) In-Reply-To: <20181030003515.12075-1-xiyou.wangcong@gmail.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 10/29/2018 05:35 PM, Cong Wang wrote: > Most callers of pskb_trim_rcsum() simply drops the skb when > it fails, however, ip_check_defrag() still continues to pass > the skb up to stack. In that case, we should restore its previous > csum if __pskb_trim() fails. > > Found this during code review. > > Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends") > Cc: Eric Dumazet > Signed-off-by: Cong Wang > --- > net/core/skbuff.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 946de0e24c87..5decd6e6d2b6 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -1843,6 +1843,9 @@ EXPORT_SYMBOL(___pskb_trim); > */ > int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len) > { > + __wsum old_csum = skb->csum; > + int ret; > + > if (skb->ip_summed == CHECKSUM_COMPLETE) { > int delta = skb->len - len; > > @@ -1850,7 +1853,10 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len) > skb_checksum(skb, len, delta, 0), > len); > } > - return __pskb_trim(skb, len); > + ret = __pskb_trim(skb, len); > + if (unlikely(ret)) > + skb->csum = old_csum; Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ? > + return ret; > } > EXPORT_SYMBOL(pskb_trim_rcsum_slow); > >