Skip to content

Commit

Permalink
In userland, sign extend the offset for JA instructions.
Browse files Browse the repository at this point in the history
We currently use that to implement "ip6 protochain", and "pc" might be
wider than "pc->k", in which case we need to arrange that "pc->k" be
sign-extended, by casting it to bpf_int32.
  • Loading branch information
guyharris committed May 5, 2011
1 parent f3e011b commit ecdc5c0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bpf/net/bpf_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,18 @@ bpf_filter(pc, p, wirelen, buflen)
continue;

case BPF_JMP|BPF_JA:
#if defined(KERNEL) || defined(_KERNEL)
/*
* No backward jumps allowed.
*/
pc += pc->k;
#else
/*
* XXX - we currently implement "ip6 protochain"
* with backward jumps, so sign-extend pc->k.
*/
pc += (bpf_int32)pc->k;
#endif
continue;

case BPF_JMP|BPF_JGT|BPF_K:
Expand Down

0 comments on commit ecdc5c0

Please sign in to comment.