Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 255cd50f authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller
Browse files

net: sched: fix use-after-free in tcf_action_destroy and tcf_del_walker



Recent commit d7fb60b9 ("net_sched: get rid of tcfa_rcu") removed
freeing in call_rcu, which changed already existing hard-to-hit
race condition into 100% hit:

[  598.599825] BUG: unable to handle kernel NULL pointer dereference at 0000000000000030
[  598.607782] IP: tcf_action_destroy+0xc0/0x140

Or:

[   40.858924] BUG: unable to handle kernel NULL pointer dereference at 0000000000000030
[   40.862840] IP: tcf_generic_walker+0x534/0x820

Fix this by storing the ops and use them directly for module_put call.

Fixes: a85a970a ("net_sched: move tc_action into tcf_common")
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 822f8565
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
	idr_for_each_entry_ext(idr, p, id) {
		ret = __tcf_idr_release(p, false, true);
		if (ret == ACT_P_DELETED) {
			module_put(p->ops->owner);
			module_put(ops->owner);
			n_i++;
		} else if (ret < 0) {
			goto nla_put_failure;
@@ -514,13 +514,15 @@ EXPORT_SYMBOL(tcf_action_exec);

int tcf_action_destroy(struct list_head *actions, int bind)
{
	const struct tc_action_ops *ops;
	struct tc_action *a, *tmp;
	int ret = 0;

	list_for_each_entry_safe(a, tmp, actions, list) {
		ops = a->ops;
		ret = __tcf_idr_release(a, bind, true);
		if (ret == ACT_P_DELETED)
			module_put(a->ops->owner);
			module_put(ops->owner);
		else if (ret < 0)
			return ret;
	}