mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jianhao Xu" <jianhao_xu@smail.nju.edu.cn>
To: edumazet <edumazet@google.com>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>, jhs <jhs@mojatatu.com>,
	"xiyou.wangcong" <xiyou.wangcong@gmail.com>,
	jiri <jiri@resnulli.us>, davem <davem@davemloft.net>,
	kuba <kuba@kernel.org>, pabeni <pabeni@redhat.com>,
	netdev <netdev@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: sched: fix potential null pointer deref
Date: Sat, 11 Jun 2022 13:00:48 +0200	[thread overview]
Message-ID: <tencent_4CF4EFF2144A820D7BBECA7D@qq.com> (raw)
In-Reply-To: <CANn89iKHfi=kQY1FC=07COJfVX4ROTnGkM_1uKvOfPfdhqt4Ow@mail.gmail.com>

Thanks for your advice and sorry for the noise.

> All netdev devices have their dev->_tx allocated in netif_alloc_netdev_queues()
> 
> There is absolutely no way MQ qdisc could be attached to a device that
> has failed netif_alloc_netdev_queues() step.

I believe this makes sense. But I am still a bit confused, especially after we 
cross-checked the similar context of mq, mqprio, taprio. To be specific, we 
cross-checked whether `mq_class_ops`, `mqprio_class_ops`, and 
`taprio_class_ops` check the return value of  their respective version of 
`_queue_get` before dereferencing it. 

--------------- ----- --------- --------- 
class_ops      whether check the ret value of _queue_get
                     mq |  mqprio | taprio   
--------------- ----- --------- ---------  
select_queue    -     -         -         
graft               no    yes      yes       
leaf                 no    yes      yes       
find                yes    -         yes       
walk                -      -          -         
dump              no    no       no        
dump_stats     no    no       no     
--------------- ----- --------- --------- 
  
As shown in this table, `mq_leaf()` does not check the return value of 
`mq__queue_get()` before using the pointer, while `mqprio_leaf()` and 
`taprio_leaf()` do have such a NULL check. 

FYI, here is the code of `mqprio_leaf()` and we can find the NULL check.
```
//net/sched/sch_mqprio.c
static struct Qdisc *mqprio_leaf(struct Qdisc *sch, unsigned long cl)
{
	struct netdev_queue *dev_queue = mqprio_queue_get(sch, cl);

	if (!dev_queue)
		return NULL;

	return dev_queue->qdisc_sleeping;
}
```

That is also the situation of `mq_graft()`, `mqprio_graft()` and `taprio_graft()`. 
I am not sure whether it is reasonable to expect the class_ops of mq, mqprio, 
and taprio to be consistent in this way. If so, does it mean that it is possible 
that`mq_leaf()`and `mq_graft` may miss a check here, or mqprio, taprio have 
redundant checks?

Thanks again for your time. I apologize if my question is stupid.

      reply	other threads:[~2022-06-11 11:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10  2:14 Jianhao Xu
2022-06-10  7:14 ` Daniel Borkmann
     [not found]   ` <tencent_29981C021E6150B064C7DBA3@qq.com>
2022-06-10  8:40     ` Eric Dumazet
2022-06-11 11:00       ` Jianhao Xu [this message]

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=tencent_4CF4EFF2144A820D7BBECA7D@qq.com \
    --to=jianhao_xu@smail.nju.edu.cn \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®