Commit c1f7e029 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

net: cls_flower: Remove filter from mask before freeing it

In fl_change(), when adding a new rule (i.e. fold == NULL), a driver may
reject the new rule, for example due to resource exhaustion. By that
point, the new rule was already assigned a mask, and it was added to
that mask's hash table. The clean-up path that's invoked as a result of
the rejection however neglects to undo the hash table addition, and
proceeds to free the new rule, thus leaving a dangling pointer in the
hash table.

Fix by removing fnew from the mask's hash table before it is freed.

Fixes: 35cc3cef ("net/sched: cls_flower: Reject duplicated rules also under skip_sw")
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3e5a7c98
...@@ -1371,7 +1371,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, ...@@ -1371,7 +1371,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
if (!tc_skip_hw(fnew->flags)) { if (!tc_skip_hw(fnew->flags)) {
err = fl_hw_replace_filter(tp, fnew, extack); err = fl_hw_replace_filter(tp, fnew, extack);
if (err) if (err)
goto errout_mask; goto errout_mask_ht;
} }
if (!tc_in_hw(fnew->flags)) if (!tc_in_hw(fnew->flags))
...@@ -1401,6 +1401,10 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, ...@@ -1401,6 +1401,10 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
kfree(mask); kfree(mask);
return 0; return 0;
errout_mask_ht:
rhashtable_remove_fast(&fnew->mask->ht, &fnew->ht_node,
fnew->mask->filter_ht_params);
errout_mask: errout_mask:
fl_mask_put(head, fnew->mask, false); fl_mask_put(head, fnew->mask, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment