Skip to content

Commit 3f2ab13

Browse files
Daniel Borkmanndavem330
authored andcommitted
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: 7d1d65c ("net: sched: cls_bpf: add BPF-based classifier") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Jiri Pirko <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7913ecf commit 3f2ab13

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/sched/cls_bpf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
220220
struct cls_bpf_head *head)
221221
{
222222
unsigned int i = 0x80000000;
223+
u32 handle;
223224

224225
do {
225226
if (++head->hgen == 0x7FFFFFFF)
226227
head->hgen = 1;
227228
} while (--i > 0 && cls_bpf_get(tp, head->hgen));
228-
if (i == 0)
229+
230+
if (unlikely(i == 0)) {
229231
pr_err("Insufficient number of handles\n");
232+
handle = 0;
233+
} else {
234+
handle = head->hgen;
235+
}
230236

231-
return i;
237+
return handle;
232238
}
233239

234240
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,

0 commit comments

Comments
 (0)