From: Marco Elver <elver@google.com> Date: 2021-02-01 16:05:55
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(-)
@@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);*/staticintskb_prepare_for_shift(structsk_buff*skb){-returnskb_cloned(skb)&&pskb_expand_head(skb,0,0,GFP_ATOMIC);+intret=0;++if(skb_cloned(skb)){+/* Save and restore truesize: pskb_expand_head() may reallocate+*memorywhereksize(kmalloc(S))!=ksize(kmalloc(S)),butwe+*cannotchangetruesizeatthispoint.+*/+unsignedintsave_truesize=skb->truesize;++ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+skb->truesize=save_truesize;+}+returnret;}/**
From: Christoph Paasch <hidden> Date: 2021-02-01 16:51:42
On Mon, Feb 1, 2021 at 8:09 AM Marco Elver [off-list ref] wrote:
quoted hunk
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(-)
@@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);*/staticintskb_prepare_for_shift(structsk_buff*skb){-returnskb_cloned(skb)&&pskb_expand_head(skb,0,0,GFP_ATOMIC);+intret=0;++if(skb_cloned(skb)){+/* Save and restore truesize: pskb_expand_head() may reallocate+*memorywhereksize(kmalloc(S))!=ksize(kmalloc(S)),butwe+*cannotchangetruesizeatthispoint.+*/+unsignedintsave_truesize=skb->truesize;++ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+skb->truesize=save_truesize;+}+returnret;
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 <redacted>
From: Marco Elver <elver@google.com> Date: 2021-02-01 17:35:41
On Mon, 1 Feb 2021 at 17:50, Christoph Paasch
[off-list ref] wrote:
On Mon, Feb 1, 2021 at 8:09 AM Marco Elver [off-list ref] wrote:
quoted
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(-)
@@ -3289,7 +3289,19 @@ EXPORT_SYMBOL(skb_split);*/staticintskb_prepare_for_shift(structsk_buff*skb){-returnskb_cloned(skb)&&pskb_expand_head(skb,0,0,GFP_ATOMIC);+intret=0;++if(skb_cloned(skb)){+/* Save and restore truesize: pskb_expand_head() may reallocate+*memorywhereksize(kmalloc(S))!=ksize(kmalloc(S)),butwe+*cannotchangetruesizeatthispoint.+*/+unsignedintsave_truesize=skb->truesize;++ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+skb->truesize=save_truesize;+}+returnret;
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 <redacted>
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
From: Eric Dumazet <edumazet@google.com> Date: 2021-02-01 17:59:24
On Mon, Feb 1, 2021 at 6:34 PM Marco Elver [off-list ref] wrote:
On Mon, 1 Feb 2021 at 17:50, Christoph Paasch
quoted
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 <redacted>
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 ;)
From: Christoph Paasch <hidden> Date: 2021-02-02 17:01:34
On Mon, Feb 1, 2021 at 9:58 AM Eric Dumazet [off-list ref] wrote:
On Mon, Feb 1, 2021 at 6:34 PM Marco Elver [off-list ref] wrote:
quoted
On Mon, 1 Feb 2021 at 17:50, Christoph Paasch
quoted
quoted
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 <redacted>
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
From: Eric Dumazet <edumazet@google.com> Date: 2021-02-02 18:04:15
On Mon, Feb 1, 2021 at 5:04 PM Marco Elver [off-list ref] 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>
From: Marco Elver <elver@google.com> Date: 2021-02-02 18:38:13
On Tue, 2 Feb 2021 at 18:59, Eric Dumazet [off-list ref] wrote:
On Mon, Feb 1, 2021 at 5:04 PM Marco Elver [off-list ref] wrote:
quoted
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>
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()).
[...]