bpf: x86: fix epilogue generation for eBPF programs
commit769e0de6475e5512f88bfb4dbf6d6323fd23514f
authorAlexei Starovoitov <ast@plumgrid.com>
Sat, 29 Nov 2014 22:46:13 +0000 (29 14:46 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 6 Dec 2014 05:23:54 +0000 (5 21:23 -0800)
treed6a8648b1dcc509a47e47f995159f70bcb0572c6
parent6fb2a756739aa507c1fd5b8126f0bfc2f070dc46
bpf: x86: fix epilogue generation for eBPF programs

classic BPF has a restriction that last insn is always BPF_RET.
eBPF doesn't have BPF_RET instruction and this restriction.
It has BPF_EXIT insn which can appear anywhere in the program
one or more times and it doesn't have to be last insn.
Fix eBPF JIT to emit epilogue when first BPF_EXIT is seen
and all other BPF_EXIT instructions will be emitted as jump.

Since jump offset to epilogue is computed as:
jmp_offset = ctx->cleanup_addr - addrs[i]
we need to change type of cleanup_addr to signed to compute the offset as:
(long long) ((int)20 - (int)30)
instead of:
(long long) ((unsigned int)20 - (int)30)

Fixes: 622582786c9e ("net: filter: x86: internal BPF JIT")
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/x86/net/bpf_jit_comp.c