On Thu, 21 Mar 2019 11:05:21 -0700, Cong Wang wrote:
> On Wed, Mar 20, 2019 at 11:12 AM John Hurley <john.hur...@netronome.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.

Reply via email to