提交 3f2ab135 编写于 作者: D Daniel Borkmann 提交者: David S. Miller

net: cls_bpf: fix auto generation of per list handles

When creating a bpf classifier in tc with priority collisions and
invoking automatic unique handle assignment, cls_bpf_grab_new_handle()
will return a wrong handle id which in fact is non-unique. Usually
altering of specific filters is being addressed over major id, but
in case of collisions we result in a filter chain, where handle ids
address individual cls_bpf_progs inside the classifier.

Issue is, in cls_bpf_grab_new_handle() we probe for head->hgen handle
in cls_bpf_get() and in case we found a free handle, we're supposed
to use exactly head->hgen. In case of insufficient numbers of handles,
we bail out later as handle id 0 is not allowed.

Fixes: 7d1d65cb ("net: sched: cls_bpf: add BPF-based classifier")
Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
Acked-by: NJiri Pirko <jiri@resnulli.us>
Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 7913ecf6
...@@ -220,15 +220,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp, ...@@ -220,15 +220,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
struct cls_bpf_head *head) struct cls_bpf_head *head)
{ {
unsigned int i = 0x80000000; unsigned int i = 0x80000000;
u32 handle;
do { do {
if (++head->hgen == 0x7FFFFFFF) if (++head->hgen == 0x7FFFFFFF)
head->hgen = 1; head->hgen = 1;
} while (--i > 0 && cls_bpf_get(tp, head->hgen)); } while (--i > 0 && cls_bpf_get(tp, head->hgen));
if (i == 0)
if (unlikely(i == 0)) {
pr_err("Insufficient number of handles\n"); pr_err("Insufficient number of handles\n");
handle = 0;
} else {
handle = head->hgen;
}
return i; return handle;
} }
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册