Subject: Re: [PATCH net] net/sched: fix NULL dereference in the error path of tcf_vlan_init()

From: Roman Mashak <[email-masked]>
Date: Thu, 15 Mar 2018 10:28:24 -0400

Davide Caratti <[email-masked]> writes:

> when the following command
>
>  # tc actions replace action vlan pop index 100
>
> is run for the first time, and tcf_vlan_init() fails allocating struct
> tcf_vlan_params, tcf_vlan_cleanup() calls kfree_rcu(NULL, ...). This causes
> the following error:
>

[...]

> fix this in tcf_vlan_cleanup(), ensuring that kfree_rcu(p, ...) is called
> only when p is not NULL.
>
> Fixes: 4c5b9d9642c8 ("act_vlan: VLAN action rewrite to use RCU lock/unlock and update")
> Signed-off-by: Davide Caratti <[email-masked]>
> ---
>  net/sched/act_vlan.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
> index e1a1b3f3983a..c2914e9a4a6f 100644
> --- a/net/sched/act_vlan.c
> +++ b/net/sched/act_vlan.c
> @@ -225,7 +225,8 @@ static void tcf_vlan_cleanup(struct tc_action *a)
>  	struct tcf_vlan_params *p;
>  
>  	p = rcu_dereference_protected(v->vlan_p, 1);
> -	kfree_rcu(p, rcu);
> +	if (p)
> +		kfree_rcu(p, rcu);
>  }
>  
>  static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,

Good catch. I think you can propagate the fix on the other actions
->cleanup(), where private parameters structure may not be present at
cleanup time, e.g. csum, ife.