Skip to content

Commit

Permalink
net_sched: refetch skb protocol for each filter
Browse files Browse the repository at this point in the history
[ Upstream commit cd0c4e7 ]

Martin reported a set of filters don't work after changing
from reclassify to continue. Looking into the code, it
looks like skb protocol is not always fetched for each
iteration of the filters. But, as demonstrated by Martin,
TC actions could modify skb->protocol, for example act_vlan,
this means we have to refetch skb protocol in each iteration,
rather than using the one we fetch in the beginning of the loop.

This bug is _not_ introduced by commit 3b3ae88
("net: sched: consolidate tc_classify{,_compat}"), technically,
if act_vlan is the only action that modifies skb protocol, then
it is commit c7e2b96 ("sched: introduce vlan action") which
introduced this bug.

Reported-by: Martin Olsson <martin.olsson+netdev@sentorsecurity.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
congwang authored and gregkh committed Jan 31, 2019
1 parent bff7432 commit 147bb6f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/sched/sch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,14 +1850,14 @@ static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb)
int tc_classify(struct sk_buff *skb, const struct tcf_proto *tp,
struct tcf_result *res, bool compat_mode)
{
__be16 protocol = tc_skb_protocol(skb);
#ifdef CONFIG_NET_CLS_ACT
const struct tcf_proto *old_tp = tp;
int limit = 0;

reclassify:
#endif
for (; tp; tp = rcu_dereference_bh(tp->next)) {
__be16 protocol = tc_skb_protocol(skb);
int err;

if (tp->protocol != protocol &&
Expand All @@ -1884,7 +1884,6 @@ int tc_classify(struct sk_buff *skb, const struct tcf_proto *tp,
}

tp = old_tp;
protocol = tc_skb_protocol(skb);
goto reclassify;
#endif
}
Expand Down

0 comments on commit 147bb6f

Please sign in to comment.