linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: linmiaohe <linmiaohe@huawei.com>
To: David Miller <davem@davemloft.net>
Cc: "kuba@kernel.org" <kuba@kernel.org>,
	"martin.varghese@nokia.com" <martin.varghese@nokia.com>,
	"fw@strlen.de" <fw@strlen.de>,
	"pshelar@ovn.org" <pshelar@ovn.org>,
	"dcaratti@redhat.com" <dcaratti@redhat.com>,
	"edumazet@google.com" <edumazet@google.com>,
	"steffen.klassert@secunet.com" <steffen.klassert@secunet.com>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"shmulik@metanetworks.com" <shmulik@metanetworks.com>,
	"kyk.segfault@gmail.com" <kyk.segfault@gmail.com>,
	"sowmini.varadhan@oracle.com" <sowmini.varadhan@oracle.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: handle the return value of pskb_carve_frag_list() correctly
Date: Mon, 17 Aug 2020 11:58:05 +0000	[thread overview]
Message-ID: <02b2c26de261418f91106a29cd702692@huawei.com> (raw)

David Miller <davem@davemloft.net> wrote:
>> David Miller <davem@davemloft.net> wrote:
>>>> +	/* split line is in frag list */
>>>> +	if (k == 0 && pskb_carve_frag_list(skb, shinfo, off - pos, gfp_mask)) {
>>>> +		/* skb_frag_unref() is not needed here as shinfo->nr_frags = 0. */
>>>> +		if (skb_has_frag_list(skb))
>>>> +			kfree_skb_list(skb_shinfo(skb)->frag_list);
>>>> +		kfree(data);
>>>> +		return -ENOMEM;
>>>
>>>On error, the caller is going to kfree_skb(skb) which will take care of the frag list.
>>>
>> 
>> I'am sorry for my careless. The caller will take care of the frag list and kfree(data) is enough here.
>> Many thanks for review, will send v2 soon.
>
>Actually, reading this again, what about the skb_clone_fraglist() done a few lines up?  Who will release that reference to the fraglist items?
>
>Maybe the kfree_skb_list() is necessary after all?

Yep, it looks really confusing here. On error, the caller calls kfree_skb(skb) but only atomic_sub the skb_shared_info->dataref indeed because skb is cloned
here and it shares the fraglist with origin skbuff. But the skb_clone_fraglist() done a few lines up hold the extra reference to the fraglist for coming new skb->data.
As there is no new skb->data anymore, that reference to the fraglist items won't be release unless we take care of it here.

It seems this patch exactly do the right things already. :)


             reply	other threads:[~2020-08-17 11:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17 11:58 linmiaohe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-08-17  2:27 [PATCH] net: handle the return value of pskb_carve_frag_list() correctly linmiaohe
2020-08-17  4:01 ` David Miller
2020-08-15  8:46 Miaohe Lin
2020-08-16 23:01 ` David Miller
2020-08-18 22:57 ` David Miller

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=02b2c26de261418f91106a29cd702692@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=kyk.segfault@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.varghese@nokia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@ovn.org \
    --cc=shmulik@metanetworks.com \
    --cc=sowmini.varadhan@oracle.com \
    --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).