[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190321112236.77bc1f18@cakuba.netronome.com>
Date: Thu, 21 Mar 2019 11:22:36 -0700
From: Jakub Kicinski <jakub.kicinski@...ronome.com>
To: Cong Wang <xiyou.wangcong@...il.com>
Cc: John Hurley <john.hurley@...ronome.com>,
Jiri Pirko <jiri@...lanox.com>,
David Miller <davem@...emloft.net>,
Linux Kernel Network Developers <netdev@...r.kernel.org>,
Vlad Buslov <vladbu@...lanox.com>, oss-drivers@...ronome.com
Subject: Re: [PATCH net 1/1] net: sched: fix cleanup NULL pointer exception
in act_mirr
On Thu, 21 Mar 2019 11:05:21 -0700, Cong Wang wrote:
> On Wed, Mar 20, 2019 at 11:12 AM John Hurley <john.hurley@...ronome.com> wrote:
> >
> > A new mirred action is created by the tcf_mirred_init function. This
> > contains a list head struct which is inserted into a global list on
> > successful creation of a new action. However, after a creation, it is
> > still possible to error out if the egress device does not exist. This
> > calls the act_mirr cleanup function via __tcf_idr_release and
> > __tcf_action_put. This cleanup function tries to delete the list entry
> > which is as yet uninitialised, leading to a NULL pointer exception.
>
> Hmm, good catch but can this be just fixed by initializing it before
> taking the netdevice refcnt? Like this:
>
> @@ -163,6 +163,9 @@ static int tcf_mirred_init(struct net *net, struct
> nlattr *nla,
> m->tcf_action = parm->action;
> m->tcfm_eaction = parm->eaction;
>
> + if (ret == ACT_P_CREATED)
> + INIT_LIST_HEAD(&m->tcfm_list);
> +
> if (parm->ifindex) {
> dev = dev_get_by_index(net, parm->ifindex);
> if (!dev) {
>
> which is also much simpler.
That's the initial way John fixed it, but I asked him to go back to the
previous way this code was written.
I think having the parameters validated before any allocations happen
is less error prone, especially with the strange way actions get the
release call even when init failed. It's just a more reliable code
patter for actions' init callback.
Powered by blists - more mailing lists