提交 932cefbd 编写于 作者: S Shmulik Ladkani 提交者: Yang Yingliang

net/sched: act_mirred: Pull mac prior redir to non mac_header_xmit device

mainline inclusion
from mainline-v5.5
commit 70cf3dc73132
category: bugfix
bugzilla: 28016
CVE: NA

-------------------------------------------------

There's no skb_pull performed when a mirred action is set at egress of a
mac device, with a target device/action that expects skb->data to point
at the network header.

As a result, either the target device is errornously given an skb with
data pointing to the mac (egress case), or the net stack receives the
skb with data pointing to the mac (ingress case).

E.g:
 # tc qdisc add dev eth9 root handle 1: prio
 # tc filter add dev eth9 parent 1: prio 9 protocol ip handle 9 basic \
   action mirred egress redirect dev tun0

 (tun0 is a tun device. result: tun0 errornously gets the eth header
  instead of the iph)

Revise the push/pull logic of tcf_mirred_act() to not rely on the
skb_at_tc_ingress() vs tcf_mirred_act_wants_ingress() comparison, as it
does not cover all "pull" cases.

Instead, calculate whether the required action on the target device
requires the data to point at the network header, and compare this to
whether skb->data points to network header - and make the push/pull
adjustments as necessary.

Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: NShmulik Ladkani <sladkani@proofpoint.com>
Tested-by: NJamal Hadi Salim <jhs@mojatatu.com>
Acked-by: NJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NYueHaibing <yuehaibing@huawei.com>

Conflicts:
	net/sched/act_mirred.c
Reviewed-by: NMao Wenan <maowenan@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 b2a0e035
...@@ -205,8 +205,10 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a, ...@@ -205,8 +205,10 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
bool use_reinsert; bool use_reinsert;
bool want_ingress; bool want_ingress;
bool is_redirect; bool is_redirect;
bool expects_nh;
int m_eaction; int m_eaction;
int mac_len; int mac_len;
bool at_nh;
tcf_lastuse_update(&m->tcf_tm); tcf_lastuse_update(&m->tcf_tm);
bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb); bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
...@@ -239,19 +241,19 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a, ...@@ -239,19 +241,19 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
goto out; goto out;
} }
/* If action's target direction differs than filter's direction,
* and devices expect a mac header on xmit, then mac push/pull is
* needed.
*/
want_ingress = tcf_mirred_act_wants_ingress(m_eaction); want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
if (skb_at_tc_ingress(skb) != want_ingress && m_mac_header_xmit) {
if (!skb_at_tc_ingress(skb)) { expects_nh = want_ingress || !m_mac_header_xmit;
/* caught at egress, act ingress: pull mac */ at_nh = skb->data == skb_network_header(skb);
mac_len = skb_network_header(skb) - skb_mac_header(skb); if (at_nh != expects_nh) {
mac_len = skb_at_tc_ingress(skb) ? skb->mac_len :
skb_network_header(skb) - skb_mac_header(skb);
if (expects_nh) {
/* target device/action expect data at nh */
skb_pull_rcsum(skb2, mac_len); skb_pull_rcsum(skb2, mac_len);
} else { } else {
/* caught at ingress, act egress: push mac */ /* target device/action expect data at mac */
skb_push_rcsum(skb2, skb->mac_len); skb_push_rcsum(skb2, mac_len);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册