linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: linmiaohe <linmiaohe@huawei.com>
Cc: David Miller <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>, Florian Westphal <fw@strlen.de>,
	Pablo Neira Ayuso <pablo@netfilter.org>,
	Eric Dumazet <edumazet@google.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	rdunlap@infradead.org, decui@microsoft.com,
	Jakub Sitnicki <jakub@cloudflare.com>,
	jeremy@azazel.net, mashirle@us.ibm.com,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/5] net: Fix potential deadloop in skb_copy_ubufs()
Date: Thu, 6 Aug 2020 14:25:54 +0200	[thread overview]
Message-ID: <CA+FuTSf48QvUhzmUROmSe-3W_H-FuCigq8Rg7otB0-XprDu6-A@mail.gmail.com> (raw)
In-Reply-To: <1596714642-25183-1-git-send-email-linmiaohe@huawei.com>

On Thu, Aug 6, 2020 at 1:48 PM linmiaohe <linmiaohe@huawei.com> wrote:
>
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> We could be trapped in deadloop when we try to copy userspace skb frags
> buffers to kernel with a cloned skb:
>
> [kbox] catch panic event, panic reason:kernel stack overflow
> [kbox] catch panic event, start logging.
> CPU: 3 PID: 4083 Comm: insmod Kdump: loaded Tainted: G       OE  4.19 #6
> Hardware name: linux,dummy-virt (DT)
> Call trace:
>         dump_backtrace+0x0/0x198
>         show_stack+0x24/0x30
>         dump_stack+0xa4/0xcc
>         kbox_panic_notifier_callback+0x1d0/0x310 [kbox]
>         notifier_call_chain+0x5c/0xa0
>         atomic_notifier_call_chain+0x3c/0x50
>         panic+0x164/0x314
>         __stack_chk_fail+0x0/0x28
>         handle_bad_stack+0xfc/0x108
>         __bad_stack+0x90/0x94
>         pskb_expand_head+0x0/0x2c8
>         pskb_expand_head+0x290/0x2c8
>         skb_copy_ubufs+0x3cc/0x520
>         pskb_expand_head+0x290/0x2c8
>         skb_copy_ubufs+0x3cc/0x520
>         pskb_expand_head+0x290/0x2c8
>         skb_copy_ubufs+0x3cc/0x520
>         pskb_expand_head+0x290/0x2c8
>         skb_copy_ubufs+0x3cc/0x520
>         ...
>         pskb_expand_head+0x290/0x2c8
>         skb_copy_ubufs+0x3cc/0x520
>         ...
>
> Reproduce code snippet:
>         skb = alloc_skb(UBUF_DATA_LEN, GFP_ATOMIC);
>         clone = skb_clone(skb, GFP_ATOMIC);
>         skb_zcopy_set_nouarg(clone, NULL);
>         pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
>
> Catch this unexpected case and return -EINVAL in skb_orphan_frags() before
> we call skb_copy_ubufs() to fix it.

Is this a hypothetical codepath?

skb zerocopy carefully tracks clone calls where necessary. See the
call to skb_orphan_frags in skb_clone, and the implementation of that
callee.

The only caller of skb zerocopy with nouarg is tpacket_fill_skb, as
of commit 5cd8d46ea156 ("packet: copy user buffers before orphan or
clone").

As the commit subject indicates, this sets skb_zcopy_set_nouarg
exactly to be sure that any clone will trigger a copy of "zerocopy"
user data to private kernel memory.

No clone must happen between alloc_skb and
skb_zcopy_set_nouarg, indeed. But AFAIK, none exists.

  reply	other threads:[~2020-08-06 17:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-06 11:50 [PATCH 1/5] net: Fix potential deadloop in skb_copy_ubufs() linmiaohe
2020-08-06 12:25 ` Willem de Bruijn [this message]
2020-08-07  9:48 linmiaohe
2020-08-14  7:14 linmiaohe
2020-08-14 15:14 ` Eric Dumazet
2020-08-15  2:18 linmiaohe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+FuTSf48QvUhzmUROmSe-3W_H-FuCigq8Rg7otB0-XprDu6-A@mail.gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=jakub@cloudflare.com \
    --cc=jeremy@azazel.net \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mashirle@us.ibm.com \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=rdunlap@infradead.org \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).