Commit Graph

46 Commits

Author SHA1 Message Date
alnsn
db4395c55a Don't trigger BJ_ASSERT(false) on invalid BPF_Jxxx opcode in jmp_to_op().
This change helps survive AFL fuzzing without calling bpf_validate() first.

Also change alu_to_op() function to have a similar interface.
2016-07-29 20:29:38 +00:00
alnsn
44dbc048e9 Adapt to the new version of sljit@r313. 2016-05-29 17:20:22 +00:00
alnsn
40bda2ee5c Replace the nsaveds() function with #define NSAVEDS 3. No functional change.
Patch from Michael McConville.
2015-12-29 21:49:58 +00:00
alnsn
84db77b722 Copyright year. 2015-02-14 21:32:46 +00:00
alnsn
321f9dd4e2 In some implementations pc->k is signed. Cast it to uint32_t before comparing. 2015-02-14 21:17:05 +00:00
alnsn
7674f27971 Properly track initialisation of registers for BPF_JMP instructions. 2015-02-14 21:14:56 +00:00
alnsn
9c78c5707a Don't emit wrapped-around reads. They're dead code but dead code elimination
logic isn't smart enough to figure it out.

Found by afl fuzzer http://lcamtuf.coredump.cx/afl/.
2015-02-13 15:59:17 +00:00
alnsn
f34037ede3 Fix bugs found by afl fuzzer http://lcamtuf.coredump.cx/afl/. 2015-02-12 23:09:55 +00:00
christos
3eceacff0e rename variable to avoid conflict with "div" 2015-01-15 16:31:05 +00:00
justin
a25ec9451f Help gcc by initialising variable 2014-12-08 00:44:45 +00:00
alnsn
1bc241b440 Implement BPF_MOD. 2014-11-20 20:31:22 +00:00
alnsn
e7d5850261 Implement BPF_ALU+BPF_MOD-BPF_K when pc->k is a power of 2. Get rid of divt
and divw arguments in emit_moddiv(), they're accessible via the pc argument.
2014-11-20 19:18:52 +00:00
alnsn
e888d0e817 Follow argument convension of other emit_xxx() functions. 2014-11-20 14:35:01 +00:00
christos
bca1938abc Add BPF_MOD/BPF_XOR (untested, needs work) 2014-11-19 19:34:43 +00:00
alnsn
80a2991627 Don't use saved EREG registers because sljit 0.91 can generate
bogus code on amd64. The A and X registers are saved on the stack.

The most recent version of sljit fixes bogus code generation but
it's not backward compatible with sljit 0.91.
2014-07-26 11:23:46 +00:00
alnsn
9f32be6c56 For P[X+0] load, don't emit wrap around check and copy X intead of emitting X+0. 2014-07-24 22:54:38 +00:00
alnsn
5e176a43dc Two tweaks: don't use a temporary register to dereference the err agrument
after xcall and don't generate ((tmp1 & 0xf) << 2) twice in emit_msh().
2014-07-22 08:29:51 +00:00
alnsn
6435b9414c Don't use scratch registers for X and to restore A after BPF_COPX call. 2014-07-22 08:20:08 +00:00
alnsn
7d10db2303 Refactor BPF_COPX code. New version doesn't load buf and buflen after copx call. 2014-07-13 21:54:46 +00:00
alnsn
981f777cfd Don't use BJ_TMP2REG for 32bit packet reads. Assign this register to (buf+X)
in BPF_LD+BPF_IND and save one instruction.
2014-07-13 18:48:27 +00:00
alnsn
4c9cf960fe emit_xcall: check overflow by comparing X with (UINT32_MAX - pk->k), restore
the A register after checking that xcall succeeded.
2014-07-12 20:14:18 +00:00
alnsn
ea84cea2f2 Initialise status to avoid -Wuninitialized warning. 2014-07-12 16:52:57 +00:00
alnsn
d35700dd8f Some small changes: add missing error checks; move sjump initialisation away
from optimize(); +BJ_HINT_PKT, -BJ_HINT_IND; tweak comments.
2014-07-12 16:13:57 +00:00
alnsn
b81423b783 Handle overflow in BPF_LD+BPF_IND for mbuf chains and make two minor changes:
move sljit_emit_return() to generate_insn_code() and use a different register
for checking errors after xcall.
2014-07-11 20:43:33 +00:00
alnsn
b8f42e532b Most filter programs in the kernel need 3 scratch registers. 2014-07-08 11:30:31 +00:00
alnsn
b7e8e67d4c Review some SLJIT_MOV instructions with respect to width. 2014-07-05 11:13:13 +00:00
alnsn
24d883a5bc Add optimization hints. They replace nscratches and ncopfuncs and improve
readability.
2014-07-04 21:32:08 +00:00
alnsn
c676220d8a Move the main loop in bpfjit_generate_code() to a new function and make few
small changes.
2014-07-01 16:18:55 +00:00
alnsn
c9a2e5bb28 Default initialize external memwords.
This change doesn't affect performance of valid bpf kernel programs
because bpf_filter_ext() checks that all memwords are initialized
explicitly.
2014-06-25 13:53:40 +00:00
alnsn
6ba0a195e1 New jitcode takes two arguments. 2014-06-25 11:58:15 +00:00
alnsn
e8d0d0ec8c Use SLJIT_MOV_P to copy extmem pointer. 2014-06-25 11:13:28 +00:00
rmind
296dce2c93 bpfjit_generate_code: emit the instruction correctly. 2014-06-25 01:21:36 +00:00
rmind
dd10cc70db - Improve the comments in bpf.h and KNF a little.
- Rename bpf_ctx_t member noinit to preinited (reflects the meaning better).
2014-06-24 22:19:36 +00:00
alnsn
19fed70d36 Implement copfuncs and external memory in bpfjit. 2014-06-24 10:53:30 +00:00
alnsn
33abe179f5 Update code to the latest sljit version. 2014-06-17 16:52:33 +00:00
alnsn
08d17fbe34 Enable ABC optimization when one branch returns 0. 2014-05-23 22:04:09 +00:00
alnsn
a9f8710044 Loads at offsets UINT32_MAX or greater are unreachable. 2014-05-23 19:51:16 +00:00
alnsn
1bf51582a4 Implement unconditional jump to "return 0" for loads at UINT32_MAX+1 or greater. 2014-05-23 19:11:22 +00:00
alnsn
74e580d299 Some small changes in preparation for a bigger change.
- typedef for ABC variables and MAX_ABC_LENGTH constant,
- cast pc->k to uint32_t in more places,
- whitespaces.
2014-05-22 13:35:45 +00:00
alnsn
98f8ebfbda Refactor bpfjit code.
- Implement Array Bounds Check Elimination for packet bytes.
 - Track initialization of registers and memwords.
 - Remove "bj_" prefix from struct members.
 - Shorten "BPFJIT_" prefix to "BJ_".
 - Other small improvements.
2014-05-15 22:20:08 +00:00
pooka
c4a2c1fa88 XXXgcc Wuninitialized kludge 2013-12-15 21:18:01 +00:00
rmind
df5750d833 Fix the bpfjit build. 2013-11-15 13:56:21 +00:00
rmind
d0748eb941 - Add bpf_args_t and convert bpf_filter_ext() to use it. This allows the
caller to initialise (and re-use) the memory store.
- Add bpf_jit_generate() and bpf_jit_freecode() wrappers.
2013-11-15 00:12:44 +00:00
rmind
24e8f8767c bpfjit: replace malloc with kmem, KNF a little, add RCS ID. 2013-09-20 23:19:52 +00:00
alnsn
85151d38ab Add RCSID and fix -Wsign-compare warnings. 2012-11-10 22:12:31 +00:00
alnsn
e8c0d6c662 Add bpfjit and enable it for amd64. 2012-10-27 22:36:11 +00:00