1. 30 6月, 2018 1 次提交
  2. 05 6月, 2018 2 次提交
  3. 15 5月, 2018 1 次提交
  4. 04 5月, 2018 1 次提交
  5. 27 1月, 2018 1 次提交
  6. 20 1月, 2018 1 次提交
  7. 18 1月, 2018 8 次提交
    • R
      ARM: net: bpf: clarify tail_call index · 091f0248
      Russell King 提交于
      As per 90caccdd ("bpf: fix bpf_tail_call() x64 JIT"), the index used
      for array lookup is defined to be 32-bit wide. Update a misleading
      comment that suggests it is 64-bit wide.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      091f0248
    • R
      ARM: net: bpf: fix LDX instructions · ec19e02b
      Russell King 提交于
      When the source and destination register are identical, our JIT does not
      generate correct code, which leads to kernel oopses.
      
      Fix this by (a) generating more efficient code, and (b) making use of
      the temporary earlier if we will overwrite the address register.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      ec19e02b
    • R
      ARM: net: bpf: fix register saving · 02088d9b
      Russell King 提交于
      When an eBPF program tail-calls another eBPF program, it enters it after
      the prologue to avoid having complex stack manipulations.  This can lead
      to kernel oopses, and similar.
      
      Resolve this by always using a fixed stack layout, a CPU register frame
      pointer, and using this when reloading registers before returning.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      02088d9b
    • R
      ARM: net: bpf: correct stack layout documentation · 0005e55a
      Russell King 提交于
      The stack layout documentation incorrectly suggests that the BPF JIT
      scratch space starts immediately below BPF_FP. This is not correct,
      so let's fix the documentation to reflect reality.
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      0005e55a
    • R
      ARM: net: bpf: move stack documentation · 70ec3a6c
      Russell King 提交于
      Move the stack documentation towards the top of the file, where it's
      relevant for things like the register layout.
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      70ec3a6c
    • R
      ARM: net: bpf: fix stack alignment · d1220efd
      Russell King 提交于
      As per 2dede2d8 ("ARM EABI: stack pointer must be 64-bit aligned
      after a CPU exception") the stack should be aligned to a 64-bit boundary
      on EABI systems.  Ensure that the eBPF JIT appropraitely aligns the
      stack.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      d1220efd
    • R
      ARM: net: bpf: fix tail call jumps · f4483f2c
      Russell King 提交于
      When a tail call fails, it is documented that the tail call should
      continue execution at the following instruction.  An example tail call
      sequence is:
      
        12: (85) call bpf_tail_call#12
        13: (b7) r0 = 0
        14: (95) exit
      
      The ARM assembler for the tail call in this case ends up branching to
      instruction 14 instead of instruction 13, resulting in the BPF filter
      returning a non-zero value:
      
        178:	ldr	r8, [sp, #588]	; insn 12
        17c:	ldr	r6, [r8, r6]
        180:	ldr	r8, [sp, #580]
        184:	cmp	r8, r6
        188:	bcs	0x1e8
        18c:	ldr	r6, [sp, #524]
        190:	ldr	r7, [sp, #528]
        194:	cmp	r7, #0
        198:	cmpeq	r6, #32
        19c:	bhi	0x1e8
        1a0:	adds	r6, r6, #1
        1a4:	adc	r7, r7, #0
        1a8:	str	r6, [sp, #524]
        1ac:	str	r7, [sp, #528]
        1b0:	mov	r6, #104
        1b4:	ldr	r8, [sp, #588]
        1b8:	add	r6, r8, r6
        1bc:	ldr	r8, [sp, #580]
        1c0:	lsl	r7, r8, #2
        1c4:	ldr	r6, [r6, r7]
        1c8:	cmp	r6, #0
        1cc:	beq	0x1e8
        1d0:	mov	r8, #32
        1d4:	ldr	r6, [r6, r8]
        1d8:	add	r6, r6, #44
        1dc:	bx	r6
        1e0:	mov	r0, #0		; insn 13
        1e4:	mov	r1, #0
        1e8:	add	sp, sp, #596	; insn 14
        1ec:	pop	{r4, r5, r6, r7, r8, sl, pc}
      
      For other sequences, the tail call could end up branching midway through
      the following BPF instructions, or maybe off the end of the function,
      leading to unknown behaviours.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      f4483f2c
    • R
      ARM: net: bpf: avoid 'bx' instruction on non-Thumb capable CPUs · e9062481
      Russell King 提交于
      Avoid the 'bx' instruction on CPUs that have no support for Thumb and
      thus do not implement this instruction by moving the generation of this
      opcode to a separate function that selects between:
      
      	bx	reg
      
      and
      
      	mov	pc, reg
      
      according to the capabilities of the CPU.
      
      Fixes: 39c13c20 ("arm: eBPF JIT compiler")
      Signed-off-by: NRussell King <rmk+kernel@armlinux.org.uk>
      e9062481
  8. 18 12月, 2017 1 次提交
  9. 23 8月, 2017 1 次提交
    • S
      arm: eBPF JIT compiler · 39c13c20
      Shubham Bansal 提交于
      The JIT compiler emits ARM 32 bit instructions. Currently, It supports
      eBPF only. Classic BPF is supported because of the conversion by BPF core.
      
      This patch is essentially changing the current implementation of JIT compiler
      of Berkeley Packet Filter from classic to internal with almost all
      instructions from eBPF ISA supported except the following
      	BPF_ALU64 | BPF_DIV | BPF_K
      	BPF_ALU64 | BPF_DIV | BPF_X
      	BPF_ALU64 | BPF_MOD | BPF_K
      	BPF_ALU64 | BPF_MOD | BPF_X
      	BPF_STX | BPF_XADD | BPF_W
      	BPF_STX | BPF_XADD | BPF_DW
      
      Implementation is using scratch space to emulate 64 bit eBPF ISA on 32 bit
      ARM because of deficiency of general purpose registers on ARM. Currently,
      only LITTLE ENDIAN machines are supported in this eBPF JIT Compiler.
      
      Tested on ARMv7 with QEMU by me (Shubham Bansal).
      
      Testing results on ARMv7:
      
      1) test_bpf: Summary: 341 PASSED, 0 FAILED, [312/333 JIT'ed]
      2) test_tag: OK (40945 tests)
      3) test_progs: Summary: 30 PASSED, 0 FAILED
      4) test_lpm: OK
      5) test_lru_map: OK
      
      Above tests are all done with following flags enabled discreatly.
      
      1) bpf_jit_enable=1
      	a) CONFIG_FRAME_POINTER enabled
      	b) CONFIG_FRAME_POINTER disabled
      2) bpf_jit_enable=1 and bpf_jit_harden=2
      	a) CONFIG_FRAME_POINTER enabled
      	b) CONFIG_FRAME_POINTER disabled
      
      See Documentation/networking/filter.txt for more information.
      Signed-off-by: NShubham Bansal <illusionist.neo@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      39c13c20
  10. 09 5月, 2017 1 次提交
  11. 06 1月, 2016 2 次提交
  12. 17 11月, 2015 1 次提交
  13. 05 10月, 2015 2 次提交
  14. 03 10月, 2015 1 次提交
  15. 28 7月, 2015 3 次提交
  16. 22 7月, 2015 3 次提交
  17. 13 5月, 2015 1 次提交
  18. 11 5月, 2015 2 次提交
    • N
      ARM: net: delegate filter to kernel interpreter when imm_offset() return value... · 0b59d880
      Nicolas Schichan 提交于
      ARM: net: delegate filter to kernel interpreter when imm_offset() return value can't fit into 12bits.
      
      The ARM JIT code emits "ldr rX, [pc, #offset]" to access the literal
      pool. #offset maximum value is 4095 and if the generated code is too
      large, the #offset value can overflow and not point to the expected
      slot in the literal pool. Additionally, when overflow occurs, bits of
      the overflow can end up changing the destination register of the ldr
      instruction.
      
      Fix that by detecting the overflow in imm_offset() and setting a flag
      that is checked for each BPF instructions converted in
      build_body(). As of now it can only be detected in the second pass. As
      a result the second build_body() call can now fail, so add the
      corresponding cleanup code in that case.
      
      Using multiple literal pools in the JITed code is going to require
      lots of intrusive changes to the JIT code (which would better be done
      as a feature instead of fix), just delegating to the kernel BPF
      interpreter in that case is a more straight forward, minimal fix and
      easy to backport.
      
      Fixes: ddecdfce ("ARM: 7259/3: net: JIT compiler for packet filters")
      Signed-off-by: NNicolas Schichan <nschichan@freebox.fr>
      Acked-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      0b59d880
    • N
      ARM: net fix emit_udiv() for BPF_ALU | BPF_DIV | BPF_K intruction. · 19fc99d0
      Nicolas Schichan 提交于
      In that case, emit_udiv() will be called with rn == ARM_R0 (r_scratch)
      and loading rm first into ARM_R0 will result in jit_udiv() function
      being called the same dividend and divisor. Fix that by loading rn
      first into ARM_R1 and then rm into ARM_R0.
      Signed-off-by: NNicolas Schichan <nschichan@freebox.fr>
      Cc: <stable@vger.kernel.org> # v3.13+
      Fixes: aee636c4 (bpf: do not use reciprocal divide)
      Acked-by: NMircea Gherzan <mgherzan@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      19fc99d0
  19. 24 9月, 2014 1 次提交
    • D
      net: bpf: arm: make hole-faulting more robust · e8b56d55
      Daniel Borkmann 提交于
      Will Deacon pointed out, that the currently used opcode for filling holes,
      that is 0xe7ffffff, seems not robust enough ...
      
        $ echo 0xffffffe7 | xxd -r > test.bin
        $ arm-linux-gnueabihf-objdump -m arm -D -b binary test.bin
        ...
        0: e7ffffff     udf    #65535  ; 0xffff
      
      ... while for Thumb, it ends up as ...
      
        0: ffff e7ff    vqshl.u64  q15, <illegal reg q15.5>, #63
      
      ... which is a bit fragile. The ARM specification defines some *permanently*
      guaranteed undefined instruction (UDF) space, for example for ARM in ARMv7-AR,
      section A5.4 and for Thumb in ARMv7-M, section A5.2.6.
      
      Similarly, ptrace, kprobes, kgdb, bug and uprobes make use of such instruction
      as well to trap. Given mentioned section from the specification, we can find
      such a universe as (where 'x' denotes 'don't care'):
      
        ARM:    xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
        Thumb:  1101 1110 xxxx xxxx
      
      We therefore should use a more robust opcode that fits both. Russell King
      suggested that we can even reuse a single 32-bit word, that is, 0xe7fddef1
      which will fault if executed in ARM *or* Thumb mode as done in f928d4f2
      ("ARM: poison the vectors page"). That will still hold our requirements:
      
        $ echo 0xf1defde7 | xxd -r > test.bin
        $ arm-unknown-linux-gnueabi-objdump -m arm -D -b binary test.bin
        ...
        0: e7fddef1     udf    #56801 ; 0xdde1
        $ echo 0xf1defde7f1defde7f1defde7 | xxd -r > test.bin
        $ arm-unknown-linux-gnueabi-objdump -marm -Mforce-thumb -D -b binary test.bin
        ...
        0: def1         udf    #241 ; 0xf1
        2: e7fd         b.n    0x0
        4: def1         udf    #241 ; 0xf1
        6: e7fd         b.n    0x4
        8: def1         udf    #241 ; 0xf1
        a: e7fd         b.n    0x8
      
      So on ARM 0xe7fddef1 conforms to the above UDF pattern, and the low 16 bit
      likewise correspond to UDF in Thumb case. The 0xe7fd part is an unconditional
      branch back to the UDF instruction.
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Mircea Gherzan <mgherzan@gmail.com>
      Cc: Alexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      e8b56d55
  20. 10 9月, 2014 2 次提交
  21. 06 9月, 2014 1 次提交
    • D
      net: bpf: make eBPF interpreter images read-only · 60a3b225
      Daniel Borkmann 提交于
      With eBPF getting more extended and exposure to user space is on it's way,
      hardening the memory range the interpreter uses to steer its command flow
      seems appropriate.  This patch moves the to be interpreted bytecode to
      read-only pages.
      
      In case we execute a corrupted BPF interpreter image for some reason e.g.
      caused by an attacker which got past a verifier stage, it would not only
      provide arbitrary read/write memory access but arbitrary function calls
      as well. After setting up the BPF interpreter image, its contents do not
      change until destruction time, thus we can setup the image on immutable
      made pages in order to mitigate modifications to that code. The idea
      is derived from commit 314beb9b ("x86: bpf_jit_comp: secure bpf jit
      against spraying attacks").
      
      This is possible because bpf_prog is not part of sk_filter anymore.
      After setup bpf_prog cannot be altered during its life-time. This prevents
      any modifications to the entire bpf_prog structure (incl. function/JIT
      image pointer).
      
      Every eBPF program (including classic BPF that are migrated) have to call
      bpf_prog_select_runtime() to select either interpreter or a JIT image
      as a last setup step, and they all are being freed via bpf_prog_free(),
      including non-JIT. Therefore, we can easily integrate this into the
      eBPF life-time, plus since we directly allocate a bpf_prog, we have no
      performance penalty.
      
      Tested with seccomp and test_bpf testsuite in JIT/non-JIT mode and manual
      inspection of kernel_page_tables.  Brad Spengler proposed the same idea
      via Twitter during development of this patch.
      
      Joint work with Hannes Frederic Sowa.
      Suggested-by: NBrad Spengler <spender@grsecurity.net>
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Signed-off-by: NHannes Frederic Sowa <hannes@stressinduktion.org>
      Cc: Alexei Starovoitov <ast@plumgrid.com>
      Cc: Kees Cook <keescook@chromium.org>
      Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      60a3b225
  22. 03 8月, 2014 1 次提交
    • A
      net: filter: split 'struct sk_filter' into socket and bpf parts · 7ae457c1
      Alexei Starovoitov 提交于
      clean up names related to socket filtering and bpf in the following way:
      - everything that deals with sockets keeps 'sk_*' prefix
      - everything that is pure BPF is changed to 'bpf_*' prefix
      
      split 'struct sk_filter' into
      struct sk_filter {
      	atomic_t        refcnt;
      	struct rcu_head rcu;
      	struct bpf_prog *prog;
      };
      and
      struct bpf_prog {
              u32                     jited:1,
                                      len:31;
              struct sock_fprog_kern  *orig_prog;
              unsigned int            (*bpf_func)(const struct sk_buff *skb,
                                                  const struct bpf_insn *filter);
              union {
                      struct sock_filter      insns[0];
                      struct bpf_insn         insnsi[0];
                      struct work_struct      work;
              };
      };
      so that 'struct bpf_prog' can be used independent of sockets and cleans up
      'unattached' bpf use cases
      
      split SK_RUN_FILTER macro into:
          SK_RUN_FILTER to be used with 'struct sk_filter *' and
          BPF_PROG_RUN to be used with 'struct bpf_prog *'
      
      __sk_filter_release(struct sk_filter *) gains
      __bpf_prog_release(struct bpf_prog *) helper function
      
      also perform related renames for the functions that work
      with 'struct bpf_prog *', since they're on the same lines:
      
      sk_filter_size -> bpf_prog_size
      sk_filter_select_runtime -> bpf_prog_select_runtime
      sk_filter_free -> bpf_prog_free
      sk_unattached_filter_create -> bpf_prog_create
      sk_unattached_filter_destroy -> bpf_prog_destroy
      sk_store_orig_filter -> bpf_prog_store_orig_filter
      sk_release_orig_filter -> bpf_release_orig_filter
      __sk_migrate_filter -> bpf_migrate_filter
      __sk_prepare_filter -> bpf_prepare_filter
      
      API for attaching classic BPF to a socket stays the same:
      sk_attach_filter(prog, struct sock *)/sk_detach_filter(struct sock *)
      and SK_RUN_FILTER(struct sk_filter *, ctx) to execute a program
      which is used by sockets, tun, af_packet
      
      API for 'unattached' BPF programs becomes:
      bpf_prog_create(struct bpf_prog **)/bpf_prog_destroy(struct bpf_prog *)
      and BPF_PROG_RUN(struct bpf_prog *, ctx) to execute a program
      which is used by isdn, ppp, team, seccomp, ptp, xt_bpf, cls_bpf, test_bpf
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7ae457c1
  23. 02 6月, 2014 1 次提交
    • D
      net: filter: get rid of BPF_S_* enum · 34805931
      Daniel Borkmann 提交于
      This patch finally allows us to get rid of the BPF_S_* enum.
      Currently, the code performs unnecessary encode and decode
      workarounds in seccomp and filter migration itself when a filter
      is being attached in order to overcome BPF_S_* encoding which
      is not used anymore by the new interpreter resp. JIT compilers.
      
      Keeping it around would mean that also in future we would need
      to extend and maintain this enum and related encoders/decoders.
      We can get rid of all that and save us these operations during
      filter attaching. Naturally, also JIT compilers need to be updated
      by this.
      
      Before JIT conversion is being done, each compiler checks if A
      is being loaded at startup to obtain information if it needs to
      emit instructions to clear A first. Since BPF extensions are a
      subset of BPF_LD | BPF_{W,H,B} | BPF_ABS variants, case statements
      for extensions can be removed at that point. To ease and minimalize
      code changes in the classic JITs, we have introduced bpf_anc_helper().
      
      Tested with test_bpf on x86_64 (JIT, int), s390x (JIT, int),
      arm (JIT, int), i368 (int), ppc64 (JIT, int); for sparc we
      unfortunately didn't have access, but changes are analogous to
      the rest.
      
      Joint work with Alexei Starovoitov.
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Mircea Gherzan <mgherzan@gmail.com>
      Cc: Kees Cook <keescook@chromium.org>
      Acked-by: NChema Gonzalez <chemag@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      34805931
  24. 31 3月, 2014 1 次提交
    • D
      net: filter: add jited flag to indicate jit compiled filters · f8bbbfc3
      Daniel Borkmann 提交于
      This patch adds a jited flag into sk_filter struct in order to indicate
      whether a filter is currently jited or not. The size of sk_filter is
      not being expanded as the 32 bit 'len' member allows upper bits to be
      reused since a filter can currently only grow as large as BPF_MAXINSNS.
      
      Therefore, there's enough room also for other in future needed flags to
      reuse 'len' field if necessary. The jited flag also allows for having
      alternative interpreter functions running as currently, we can only
      detect jit compiled filters by testing fp->bpf_func to not equal the
      address of sk_run_filter().
      
      Joint work with Alexei Starovoitov.
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Cc: Pablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f8bbbfc3