Message ID | 20220413173542.533060-2-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 3db09e762dc79584a69c10d74a6b98f89a9979f8 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net/sched: two fixes for cls_u32 | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Clearly marked for net |
netdev/fixes_present | success | Fixes tag present in non-next series |
netdev/subject_prefix | success | Link |
netdev/cover_letter | success | Series has a cover letter |
netdev/patch_count | success | Link |
netdev/header_inline | success | No static functions without inline keyword in header files |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/cc_maintainers | success | CCed 7 of 7 maintainers |
netdev/build_clang | success | Errors and warnings before: 0 this patch: 0 |
netdev/module_param | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Signed-off-by tag matches author and committer |
netdev/verify_fixes | success | Fixes tag looks correct |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/checkpatch | warning | WARNING: Possible repeated word: 'Google' |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/source_inline | success | Was 0 now: 0 |
On 2022-04-13 13:35, Eric Dumazet wrote: > From: Eric Dumazet <edumazet@google.com> > > We are now able to detect extra put_net() at the moment > they happen, instead of much later in correct code paths. > > u32_init_knode() / tcf_exts_init() populates the ->exts.net > pointer, but as mentioned in tcf_exts_init(), > the refcount on netns has not been elevated yet. > > The refcount is taken only once tcf_exts_get_net() > is called. > > So the two u32_destroy_key() calls from u32_change() > are attempting to release an invalid reference on the netns. > Looks good to me. Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> cheers, jamal
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index cf5649292ee00941e5c4a4d5b11b1c3dc98cce3f..fcba6c43ba509a069c593d525daf2943b4079538 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -386,14 +386,19 @@ static int u32_init(struct tcf_proto *tp) return 0; } -static int u32_destroy_key(struct tc_u_knode *n, bool free_pf) +static void __u32_destroy_key(struct tc_u_knode *n) { struct tc_u_hnode *ht = rtnl_dereference(n->ht_down); tcf_exts_destroy(&n->exts); - tcf_exts_put_net(&n->exts); if (ht && --ht->refcnt == 0) kfree(ht); + kfree(n); +} + +static void u32_destroy_key(struct tc_u_knode *n, bool free_pf) +{ + tcf_exts_put_net(&n->exts); #ifdef CONFIG_CLS_U32_PERF if (free_pf) free_percpu(n->pf); @@ -402,8 +407,7 @@ static int u32_destroy_key(struct tc_u_knode *n, bool free_pf) if (free_pf) free_percpu(n->pcpu_success); #endif - kfree(n); - return 0; + __u32_destroy_key(n); } /* u32_delete_key_rcu should be called when free'ing a copied @@ -900,13 +904,13 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, extack); if (err) { - u32_destroy_key(new, false); + __u32_destroy_key(new); return err; } err = u32_replace_hw_knode(tp, new, flags, extack); if (err) { - u32_destroy_key(new, false); + __u32_destroy_key(new); return err; }