All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net] net: make pskb_trim_rcsum_slow() robust
@ 2018-10-30  0:35 Cong Wang
  2018-10-30  2:14 ` Eric Dumazet
  2018-10-31 19:36 ` David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Cong Wang @ 2018-10-30  0:35 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Eric Dumazet

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 <edumazet@google.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 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;
+	return ret;
 }
 EXPORT_SYMBOL(pskb_trim_rcsum_slow);
 
-- 
2.16.4

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  0:35 [Patch net] net: make pskb_trim_rcsum_slow() robust Cong Wang
@ 2018-10-30  2:14 ` Eric Dumazet
  2018-10-30  2:21   ` Cong Wang
  2018-10-31 19:36 ` David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30  2:14 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: Eric Dumazet



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 <edumazet@google.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  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);
>  
> 

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  2:14 ` Eric Dumazet
@ 2018-10-30  2:21   ` Cong Wang
  2018-10-30  2:25     ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Cong Wang @ 2018-10-30  2:21 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Linux Kernel Network Developers, Eric Dumazet

On Mon, Oct 29, 2018 at 7:14 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ?

For !CHECKSUM_COMPLETE, ip_summed should be untouched, right?

If you mean only setting to CHECKSUM_NONE for CHECKSUM_COMPLETE case,
the end result may not be simpler.

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  2:21   ` Cong Wang
@ 2018-10-30  2:25     ` Eric Dumazet
  2018-10-30  2:41       ` Cong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30  2:25 UTC (permalink / raw)
  To: Cong Wang, Eric Dumazet; +Cc: Linux Kernel Network Developers, Eric Dumazet



On 10/29/2018 07:21 PM, Cong Wang wrote:
> On Mon, Oct 29, 2018 at 7:14 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>
>> Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ?
> 
> For !CHECKSUM_COMPLETE, ip_summed should be untouched, right?
> 
> If you mean only setting to CHECKSUM_NONE for CHECKSUM_COMPLETE case,
> the end result may not be simpler.

I meant to reinstate what was there before my patch in this error case

       if (skb->ip_summed == CHECKSUM_COMPLETE)
               skb->ip_summed = CHECKSUM_NONE;

That would only be run in error (quite unlikely) path, instead of saving old_csum in all cases.

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  2:25     ` Eric Dumazet
@ 2018-10-30  2:41       ` Cong Wang
  2018-10-30  3:08         ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Cong Wang @ 2018-10-30  2:41 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Linux Kernel Network Developers, Eric Dumazet

On Mon, Oct 29, 2018 at 7:25 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
>
> On 10/29/2018 07:21 PM, Cong Wang wrote:
> > On Mon, Oct 29, 2018 at 7:14 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >>
> >> Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ?
> >
> > For !CHECKSUM_COMPLETE, ip_summed should be untouched, right?
> >
> > If you mean only setting to CHECKSUM_NONE for CHECKSUM_COMPLETE case,
> > the end result may not be simpler.
>
> I meant to reinstate what was there before my patch in this error case
>
>        if (skb->ip_summed == CHECKSUM_COMPLETE)
>                skb->ip_summed = CHECKSUM_NONE;
>
> That would only be run in error (quite unlikely) path, instead of saving old_csum in all cases.

I know your point, however, I am not sure that is a desired behavior.

On failure, I think the whole skb should be restored to its previous state
before entering this function, changing it to CHECKSUM_NONE on failure
is inconsistent with success case.

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  2:41       ` Cong Wang
@ 2018-10-30  3:08         ` Eric Dumazet
  2018-10-30 18:57           ` Cong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2018-10-30  3:08 UTC (permalink / raw)
  To: Cong Wang, Eric Dumazet; +Cc: Linux Kernel Network Developers, Eric Dumazet



On 10/29/2018 07:41 PM, Cong Wang wrote:
> On Mon, Oct 29, 2018 at 7:25 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>
>>
>>
>> On 10/29/2018 07:21 PM, Cong Wang wrote:
>>> On Mon, Oct 29, 2018 at 7:14 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>>>
>>>> Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ?
>>>
>>> For !CHECKSUM_COMPLETE, ip_summed should be untouched, right?
>>>
>>> If you mean only setting to CHECKSUM_NONE for CHECKSUM_COMPLETE case,
>>> the end result may not be simpler.
>>
>> I meant to reinstate what was there before my patch in this error case
>>
>>        if (skb->ip_summed == CHECKSUM_COMPLETE)
>>                skb->ip_summed = CHECKSUM_NONE;
>>
>> That would only be run in error (quite unlikely) path, instead of saving old_csum in all cases.
> 
> I know your point, however, I am not sure that is a desired behavior.
> 
> On failure, I think the whole skb should be restored to its previous state
> before entering this function, changing it to CHECKSUM_NONE on failure
> is inconsistent with success case.
> 

Before my patch, we were changing skb->ip_summed to CHECKSUM_NONE, 
so why suddenly we need to be consistent ?

In any case, ip_check_defrag() should really drop this skb, as for other allocation
failures (like skb_share_check()), if really we want consistency.

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  3:08         ` Eric Dumazet
@ 2018-10-30 18:57           ` Cong Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Cong Wang @ 2018-10-30 18:57 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Linux Kernel Network Developers, Eric Dumazet

On Mon, Oct 29, 2018 at 8:08 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
>
> On 10/29/2018 07:41 PM, Cong Wang wrote:
> > On Mon, Oct 29, 2018 at 7:25 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >>
> >>
> >>
> >> On 10/29/2018 07:21 PM, Cong Wang wrote:
> >>> On Mon, Oct 29, 2018 at 7:14 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >>>>
> >>>> Would not it be simpler to set ip_summed to CHECKSUM_NONE (no need to save old_csum) ?
> >>>
> >>> For !CHECKSUM_COMPLETE, ip_summed should be untouched, right?
> >>>
> >>> If you mean only setting to CHECKSUM_NONE for CHECKSUM_COMPLETE case,
> >>> the end result may not be simpler.
> >>
> >> I meant to reinstate what was there before my patch in this error case
> >>
> >>        if (skb->ip_summed == CHECKSUM_COMPLETE)
> >>                skb->ip_summed = CHECKSUM_NONE;
> >>
> >> That would only be run in error (quite unlikely) path, instead of saving old_csum in all cases.
> >
> > I know your point, however, I am not sure that is a desired behavior.
> >
> > On failure, I think the whole skb should be restored to its previous state
> > before entering this function, changing it to CHECKSUM_NONE on failure
> > is inconsistent with success case.
> >
>
> Before my patch, we were changing skb->ip_summed to CHECKSUM_NONE,
> so why suddenly we need to be consistent ?

That is because setting it to CHECKSUM_NONE _was_ how the success
case works and nothing _was_ needed for failure case.

You changed how we handle checksum for success case, it is why we need
to change for the failure case too.


>
> In any case, ip_check_defrag() should really drop this skb, as for other allocation
> failures (like skb_share_check()), if really we want consistency.

I have the same feeling, just not brave enough to change the logic of
ip_check_defrag() where pskb_may_pull() failure is treated in a same way.

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

* Re: [Patch net] net: make pskb_trim_rcsum_slow() robust
  2018-10-30  0:35 [Patch net] net: make pskb_trim_rcsum_slow() robust Cong Wang
  2018-10-30  2:14 ` Eric Dumazet
@ 2018-10-31 19:36 ` David Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David Miller @ 2018-10-31 19:36 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, edumazet

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Mon, 29 Oct 2018 17:35:15 -0700

> 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 <edumazet@google.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

I kind of agree with Eric that we should make all callers, including
ip_check_defrag(), fail just as with any memory allocation failure.

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-30  0:35 [Patch net] net: make pskb_trim_rcsum_slow() robust Cong Wang
2018-10-30  2:14 ` Eric Dumazet
2018-10-30  2:21   ` Cong Wang
2018-10-30  2:25     ` Eric Dumazet
2018-10-30  2:41       ` Cong Wang
2018-10-30  3:08         ` Eric Dumazet
2018-10-30 18:57           ` Cong Wang
2018-10-31 19:36 ` 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.