linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
@ 2021-02-01 16:04 Marco Elver
  2021-02-01 16:50 ` Christoph Paasch
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Marco Elver @ 2021-02-01 16:04 UTC (permalink / raw)
  To: elver
  Cc: linux-kernel, kasan-dev, davem, kuba, jonathan.lemon, willemb,
	linmiaohe, gnault, dseok.yi, kyk.segfault, viro, netdev, glider,
	syzbot+7b99aafdcc2eedea6178, Eric Dumazet

Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
cloning an skb, save and restore truesize after pskb_expand_head(). This
can occur if the allocator decides to service an allocation of the same
size differently (e.g. use a different size class, or pass the
allocation on to KFENCE).

Because truesize is used for bookkeeping (such as sk_wmem_queued), a
modified truesize of a cloned skb may result in corrupt bookkeeping and
relevant warnings (such as in sk_stream_kill_queues()).

Link: https://lkml.kernel.org/r/X9JR/J6dMMOy1obu@elver.google.com
Reported-by: syzbot+7b99aafdcc2eedea6178@syzkaller.appspotmail.com
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Marco Elver <elver@google.com>
---
 net/core/skbuff.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 2af12f7e170c..3787093239f5 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);
  */
 static int skb_prepare_for_shift(struct sk_buff *skb)
 {
-	return skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
+	int ret = 0;
+
+	if (skb_cloned(skb)) {
+		/* Save and restore truesize: pskb_expand_head() may reallocate
+		 * memory where ksize(kmalloc(S)) != ksize(kmalloc(S)), but we
+		 * cannot change truesize at this point.
+		 */
+		unsigned int save_truesize = skb->truesize;
+
+		ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
+		skb->truesize = save_truesize;
+	}
+	return ret;
 }
 
 /**

base-commit: 14e8e0f6008865d823a8184a276702a6c3cbef3d
-- 
2.30.0.365.g02bc693789-goog


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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 16:04 [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift() Marco Elver
@ 2021-02-01 16:50 ` Christoph Paasch
  2021-02-01 17:33   ` Marco Elver
  2021-02-02 17:59 ` Eric Dumazet
  2021-02-03  2:00 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Paasch @ 2021-02-01 16:50 UTC (permalink / raw)
  To: Marco Elver
  Cc: LKML, kasan-dev, David Miller, kuba, Jonathan Lemon,
	Willem de Bruijn, linmiaohe, gnault, dseok.yi, kyk.segfault,
	Al Viro, netdev, glider, syzbot+7b99aafdcc2eedea6178,
	Eric Dumazet

On Mon, Feb 1, 2021 at 8:09 AM Marco Elver <elver@google.com> wrote:
>
> Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
> cloning an skb, save and restore truesize after pskb_expand_head(). This
> can occur if the allocator decides to service an allocation of the same
> size differently (e.g. use a different size class, or pass the
> allocation on to KFENCE).
>
> Because truesize is used for bookkeeping (such as sk_wmem_queued), a
> modified truesize of a cloned skb may result in corrupt bookkeeping and
> relevant warnings (such as in sk_stream_kill_queues()).
>
> Link: https://lkml.kernel.org/r/X9JR/J6dMMOy1obu@elver.google.com
> Reported-by: syzbot+7b99aafdcc2eedea6178@syzkaller.appspotmail.com
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Marco Elver <elver@google.com>
> ---
>  net/core/skbuff.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 2af12f7e170c..3787093239f5 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);
>   */
>  static int skb_prepare_for_shift(struct sk_buff *skb)
>  {
> -       return skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
> +       int ret = 0;
> +
> +       if (skb_cloned(skb)) {
> +               /* Save and restore truesize: pskb_expand_head() may reallocate
> +                * memory where ksize(kmalloc(S)) != ksize(kmalloc(S)), but we
> +                * cannot change truesize at this point.
> +                */
> +               unsigned int save_truesize = skb->truesize;
> +
> +               ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
> +               skb->truesize = save_truesize;
> +       }
> +       return ret;

just a few days ago we found out that this also fixes a syzkaller
issue on MPTCP (https://github.com/multipath-tcp/mptcp_net-next/issues/136).
I confirmed that this patch fixes the issue for us as well:

Tested-by: Christoph Paasch <christoph.paasch@gmail.com>





>  }
>
>  /**
>
> base-commit: 14e8e0f6008865d823a8184a276702a6c3cbef3d
> --
> 2.30.0.365.g02bc693789-goog
>

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 16:50 ` Christoph Paasch
@ 2021-02-01 17:33   ` Marco Elver
  2021-02-01 17:58     ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Marco Elver @ 2021-02-01 17:33 UTC (permalink / raw)
  To: Christoph Paasch
  Cc: LKML, kasan-dev, David Miller, Jakub Kicinski, Jonathan Lemon,
	Willem de Bruijn, linmiaohe, gnault, dseok.yi, kyk.segfault,
	Al Viro, netdev, Alexander Potapenko, syzbot, Eric Dumazet

On Mon, 1 Feb 2021 at 17:50, Christoph Paasch
<christoph.paasch@gmail.com> wrote:
> On Mon, Feb 1, 2021 at 8:09 AM Marco Elver <elver@google.com> wrote:
> >
> > Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
> > cloning an skb, save and restore truesize after pskb_expand_head(). This
> > can occur if the allocator decides to service an allocation of the same
> > size differently (e.g. use a different size class, or pass the
> > allocation on to KFENCE).
> >
> > Because truesize is used for bookkeeping (such as sk_wmem_queued), a
> > modified truesize of a cloned skb may result in corrupt bookkeeping and
> > relevant warnings (such as in sk_stream_kill_queues()).
> >
> > Link: https://lkml.kernel.org/r/X9JR/J6dMMOy1obu@elver.google.com
> > Reported-by: syzbot+7b99aafdcc2eedea6178@syzkaller.appspotmail.com
> > Suggested-by: Eric Dumazet <edumazet@google.com>
> > Signed-off-by: Marco Elver <elver@google.com>
> > ---
> >  net/core/skbuff.c | 14 +++++++++++++-
> >  1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > index 2af12f7e170c..3787093239f5 100644
> > --- a/net/core/skbuff.c
> > +++ b/net/core/skbuff.c
> > @@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);
> >   */
> >  static int skb_prepare_for_shift(struct sk_buff *skb)
> >  {
> > -       return skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
> > +       int ret = 0;
> > +
> > +       if (skb_cloned(skb)) {
> > +               /* Save and restore truesize: pskb_expand_head() may reallocate
> > +                * memory where ksize(kmalloc(S)) != ksize(kmalloc(S)), but we
> > +                * cannot change truesize at this point.
> > +                */
> > +               unsigned int save_truesize = skb->truesize;
> > +
> > +               ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
> > +               skb->truesize = save_truesize;
> > +       }
> > +       return ret;
>
> just a few days ago we found out that this also fixes a syzkaller
> issue on MPTCP (https://github.com/multipath-tcp/mptcp_net-next/issues/136).
> I confirmed that this patch fixes the issue for us as well:
>
> Tested-by: Christoph Paasch <christoph.paasch@gmail.com>

That's interesting, because according to your config you did not have
KFENCE enabled. Although it's hard to say what exactly caused the
truesize mismatch in your case, because it clearly can't be KFENCE
that caused ksize(kmalloc(S))!=ksize(kmalloc(S)) for you.

Thanks,
-- Marco

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 17:33   ` Marco Elver
@ 2021-02-01 17:58     ` Eric Dumazet
  2021-02-02 16:58       ` Christoph Paasch
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2021-02-01 17:58 UTC (permalink / raw)
  To: Marco Elver
  Cc: Christoph Paasch, LKML, kasan-dev, David Miller, Jakub Kicinski,
	Jonathan Lemon, Willem de Bruijn, linmiaohe, Guillaume Nault,
	Dongseok Yi, Yadu Kishore, Al Viro, netdev, Alexander Potapenko,
	syzbot

On Mon, Feb 1, 2021 at 6:34 PM Marco Elver <elver@google.com> wrote:
>
> On Mon, 1 Feb 2021 at 17:50, Christoph Paasch

> > just a few days ago we found out that this also fixes a syzkaller
> > issue on MPTCP (https://github.com/multipath-tcp/mptcp_net-next/issues/136).
> > I confirmed that this patch fixes the issue for us as well:
> >
> > Tested-by: Christoph Paasch <christoph.paasch@gmail.com>
>
> That's interesting, because according to your config you did not have
> KFENCE enabled. Although it's hard to say what exactly caused the
> truesize mismatch in your case, because it clearly can't be KFENCE
> that caused ksize(kmalloc(S))!=ksize(kmalloc(S)) for you.

Indeed, this seems strange. This might be a different issue.

Maybe S != S ;)

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 17:58     ` Eric Dumazet
@ 2021-02-02 16:58       ` Christoph Paasch
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Paasch @ 2021-02-02 16:58 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Marco Elver, LKML, kasan-dev, David Miller, Jakub Kicinski,
	Jonathan Lemon, Willem de Bruijn, linmiaohe, Guillaume Nault,
	Dongseok Yi, Yadu Kishore, Al Viro, netdev, Alexander Potapenko,
	syzbot

On Mon, Feb 1, 2021 at 9:58 AM Eric Dumazet <edumazet@google.com> wrote:
>
> On Mon, Feb 1, 2021 at 6:34 PM Marco Elver <elver@google.com> wrote:
> >
> > On Mon, 1 Feb 2021 at 17:50, Christoph Paasch
>
> > > just a few days ago we found out that this also fixes a syzkaller
> > > issue on MPTCP (https://github.com/multipath-tcp/mptcp_net-next/issues/136).
> > > I confirmed that this patch fixes the issue for us as well:
> > >
> > > Tested-by: Christoph Paasch <christoph.paasch@gmail.com>
> >
> > That's interesting, because according to your config you did not have
> > KFENCE enabled. Although it's hard to say what exactly caused the
> > truesize mismatch in your case, because it clearly can't be KFENCE
> > that caused ksize(kmalloc(S))!=ksize(kmalloc(S)) for you.
>
> Indeed, this seems strange. This might be a different issue.
>
> Maybe S != S ;)

Seems like letting syzkaller run for a few more days made it
eventually find the WARN again. As if Marco's change makes it harder
for us to trigger the issue.

Anyways, you can remove my "Tested-by" ;-)


Christoph

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 16:04 [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift() Marco Elver
  2021-02-01 16:50 ` Christoph Paasch
@ 2021-02-02 17:59 ` Eric Dumazet
  2021-02-02 18:34   ` Marco Elver
  2021-02-03  2:00 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2021-02-02 17:59 UTC (permalink / raw)
  To: Marco Elver
  Cc: LKML, kasan-dev, David Miller, Jakub Kicinski, Jonathan Lemon,
	Willem de Bruijn, linmiaohe, Guillaume Nault, Dongseok Yi,
	Yadu Kishore, Al Viro, netdev, Alexander Potapenko, syzbot

On Mon, Feb 1, 2021 at 5:04 PM Marco Elver <elver@google.com> wrote:
>
> Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
> cloning an skb, save and restore truesize after pskb_expand_head(). This
> can occur if the allocator decides to service an allocation of the same
> size differently (e.g. use a different size class, or pass the
> allocation on to KFENCE).
>
> Because truesize is used for bookkeeping (such as sk_wmem_queued), a
> modified truesize of a cloned skb may result in corrupt bookkeeping and
> relevant warnings (such as in sk_stream_kill_queues()).
>
> Link: https://lkml.kernel.org/r/X9JR/J6dMMOy1obu@elver.google.com
> Reported-by: syzbot+7b99aafdcc2eedea6178@syzkaller.appspotmail.com
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Marco Elver <elver@google.com>

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

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-02 17:59 ` Eric Dumazet
@ 2021-02-02 18:34   ` Marco Elver
  0 siblings, 0 replies; 8+ messages in thread
From: Marco Elver @ 2021-02-02 18:34 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: LKML, kasan-dev, David Miller, Jakub Kicinski, Jonathan Lemon,
	Willem de Bruijn, linmiaohe, Guillaume Nault, Dongseok Yi,
	Yadu Kishore, Al Viro, netdev, Alexander Potapenko, syzbot

On Tue, 2 Feb 2021 at 18:59, Eric Dumazet <edumazet@google.com> wrote:
>
> On Mon, Feb 1, 2021 at 5:04 PM Marco Elver <elver@google.com> wrote:
> >
> > Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
> > cloning an skb, save and restore truesize after pskb_expand_head(). This
> > can occur if the allocator decides to service an allocation of the same
> > size differently (e.g. use a different size class, or pass the
> > allocation on to KFENCE).
> >
> > Because truesize is used for bookkeeping (such as sk_wmem_queued), a
> > modified truesize of a cloned skb may result in corrupt bookkeeping and
> > relevant warnings (such as in sk_stream_kill_queues()).
> >
> > Link: https://lkml.kernel.org/r/X9JR/J6dMMOy1obu@elver.google.com
> > Reported-by: syzbot+7b99aafdcc2eedea6178@syzkaller.appspotmail.com
> > Suggested-by: Eric Dumazet <edumazet@google.com>
> > Signed-off-by: Marco Elver <elver@google.com>
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Thank you!

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

* Re: [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
  2021-02-01 16:04 [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift() Marco Elver
  2021-02-01 16:50 ` Christoph Paasch
  2021-02-02 17:59 ` Eric Dumazet
@ 2021-02-03  2:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-03  2:00 UTC (permalink / raw)
  To: Marco Elver
  Cc: linux-kernel, kasan-dev, davem, kuba, jonathan.lemon, willemb,
	linmiaohe, gnault, dseok.yi, kyk.segfault, viro, netdev, glider,
	syzbot+7b99aafdcc2eedea6178, edumazet

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Mon,  1 Feb 2021 17:04:20 +0100 you wrote:
> Avoid the assumption that ksize(kmalloc(S)) == ksize(kmalloc(S)): when
> cloning an skb, save and restore truesize after pskb_expand_head(). This
> can occur if the allocator decides to service an allocation of the same
> size differently (e.g. use a different size class, or pass the
> allocation on to KFENCE).
> 
> Because truesize is used for bookkeeping (such as sk_wmem_queued), a
> modified truesize of a cloned skb may result in corrupt bookkeeping and
> relevant warnings (such as in sk_stream_kill_queues()).
> 
> [...]

Here is the summary with links:
  - [net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift()
    https://git.kernel.org/netdev/net-next/c/097b9146c0e2

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-02-03  2:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 16:04 [PATCH net-next] net: fix up truesize of cloned skb in skb_prepare_for_shift() Marco Elver
2021-02-01 16:50 ` Christoph Paasch
2021-02-01 17:33   ` Marco Elver
2021-02-01 17:58     ` Eric Dumazet
2021-02-02 16:58       ` Christoph Paasch
2021-02-02 17:59 ` Eric Dumazet
2021-02-02 18:34   ` Marco Elver
2021-02-03  2:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).