All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	Roopa Prabhu <roopa@cumulusnetworks.com>
Subject: Re: [PATCH net 6/9] sch_fq_codel: avoid double free on init failure
Date: Thu, 31 Aug 2017 00:37:21 +0300	[thread overview]
Message-ID: <152fa91b-f2a6-1fa1-f6d6-3a5a8f5db590@cumulusnetworks.com> (raw)
In-Reply-To: <CAM_iQpUZoQYPnq6z3ofFQ_j4O1f+sSChCkYgv5=_cEXRutZeag@mail.gmail.com>

On 30/08/17 20:36, Cong Wang wrote:
> On Wed, Aug 30, 2017 at 2:49 AM, Nikolay Aleksandrov
> <nikolay@cumulusnetworks.com> wrote:
>> It is very unlikely to happen but the backlogs memory allocation
>> could fail and will free q->flows, but then ->destroy() will free
>> q->flows too. For correctness remove the first free and let ->destroy
>> clean up.
>>
>> Fixes: 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation")
>> Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
>> ---
>>  net/sched/sch_fq_codel.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
>> index 337f2d6d81e4..2c0c05f2cc34 100644
>> --- a/net/sched/sch_fq_codel.c
>> +++ b/net/sched/sch_fq_codel.c
>> @@ -491,10 +491,8 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
>>                 if (!q->flows)
>>                         return -ENOMEM;
>>                 q->backlogs = kvzalloc(q->flows_cnt * sizeof(u32), GFP_KERNEL);
>> -               if (!q->backlogs) {
>> -                       kvfree(q->flows);
>> +               if (!q->backlogs)
>>                         return -ENOMEM;
>> -               }
> 
> This is fine. Or we can NULL it after kvfree().
> 
> I have no preference here. The only difference here is if we still
> expect ->init() to cleanup its own failure.
> 

We don't, that's the point of the changes that lead to these fixes,
the way ->destroy() is used by both the default qdisc infra and the
normal qdisc add suggest that it should clean up after ->init failure,
thus the change.

  reply	other threads:[~2017-08-30 21:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30  9:48 [PATCH net 0/9] net/sched: init failure fixes Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 1/9] sch_htb: fix crash on init failure Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 2/9] sch_multiq: fix double free " Nikolay Aleksandrov
2017-08-30  9:48 ` [PATCH net 3/9] sch_hhf: fix null pointer dereference " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 4/9] sch_hfsc: fix null pointer deref and double free " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 5/9] sch_cbq: fix null pointer dereferences " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 6/9] sch_fq_codel: avoid double free " Nikolay Aleksandrov
2017-08-30 17:36   ` Cong Wang
2017-08-30 21:37     ` Nikolay Aleksandrov [this message]
2017-08-30  9:49 ` [PATCH net 7/9] sch_netem: avoid null pointer deref " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 8/9] sch_sfq: fix null pointer dereference " Nikolay Aleksandrov
2017-08-30  9:49 ` [PATCH net 9/9] sch_tbf: fix two null pointer dereferences " Nikolay Aleksandrov
2017-08-30 17:37   ` Cong Wang
2017-08-30 21:39     ` Nikolay Aleksandrov
2017-08-30 12:15 ` [PATCH net 0/9] net/sched: init failure fixes Jamal Hadi Salim
2017-08-30 21:35   ` Nikolay Aleksandrov
2017-08-30 22:26   ` 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=152fa91b-f2a6-1fa1-f6d6-3a5a8f5db590@cumulusnetworks.com \
    --to=nikolay@cumulusnetworks.com \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=xiyou.wangcong@gmail.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 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.