Commit 166c2c8a authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

net/sched: act_mirred: don't override retval if we already lost the skb

If we're redirecting the skb, and haven't called tcf_mirred_forward(),
yet, we need to tell the core to drop the skb by setting the retcode
to SHOT. If we have called tcf_mirred_forward(), however, the skb
is out of our hands and returning SHOT will lead to UaF.

Move the retval override to the error path which actually need it.
Reviewed-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Fixes: e5cf1baf ("act_mirred: use TC_ACT_REINSERT when possible")
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52f671db
...@@ -266,8 +266,7 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, ...@@ -266,8 +266,7 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
if (unlikely(!(dev->flags & IFF_UP)) || !netif_carrier_ok(dev)) { if (unlikely(!(dev->flags & IFF_UP)) || !netif_carrier_ok(dev)) {
net_notice_ratelimited("tc mirred to Houston: device %s is down\n", net_notice_ratelimited("tc mirred to Houston: device %s is down\n",
dev->name); dev->name);
err = -ENODEV; goto err_cant_do;
goto out;
} }
/* we could easily avoid the clone only if called by ingress and clsact; /* we could easily avoid the clone only if called by ingress and clsact;
...@@ -279,10 +278,8 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, ...@@ -279,10 +278,8 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
tcf_mirred_can_reinsert(retval); tcf_mirred_can_reinsert(retval);
if (!dont_clone) { if (!dont_clone) {
skb_to_send = skb_clone(skb, GFP_ATOMIC); skb_to_send = skb_clone(skb, GFP_ATOMIC);
if (!skb_to_send) { if (!skb_to_send)
err = -ENOMEM; goto err_cant_do;
goto out;
}
} }
want_ingress = tcf_mirred_act_wants_ingress(m_eaction); want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
...@@ -319,15 +316,16 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, ...@@ -319,15 +316,16 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
} else { } else {
err = tcf_mirred_forward(at_ingress, want_ingress, skb_to_send); err = tcf_mirred_forward(at_ingress, want_ingress, skb_to_send);
} }
if (err)
if (err) {
out:
tcf_action_inc_overlimit_qstats(&m->common); tcf_action_inc_overlimit_qstats(&m->common);
if (is_redirect)
retval = TC_ACT_SHOT;
}
return retval; return retval;
err_cant_do:
if (is_redirect)
retval = TC_ACT_SHOT;
tcf_action_inc_overlimit_qstats(&m->common);
return retval;
} }
static int tcf_blockcast_redir(struct sk_buff *skb, struct tcf_mirred *m, static int tcf_blockcast_redir(struct sk_buff *skb, struct tcf_mirred *m,
......
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