15 Dec, 2015

1 commit

  • [ Upstream commit d7475de58575c904818efa369c82e88c6648ce2e ]

    Use the local uapi headers to keep in sync with "recently" added #define's
    (e.g. SKF_AD_VLAN_TPID). Refactored CFLAGS, and bpf_asm doesn't need -I.

    Fixes: 3f356385e8a4 ("filter: bpf_asm: add minimal bpf asm tool")
    Signed-off-by: Kamal Mostafa
    Acked-by: Daniel Borkmann
    Signed-off-by: David S. Miller
    Signed-off-by: Greg Kroah-Hartman

    Kamal Mostafa
     

27 May, 2015

1 commit

  • With recent debugging, I noticed that bpf_jit_disasm segfaults when
    there's no debugging output from the JIT compiler to the kernel log.

    Reason is that when regexec(3) doesn't match on anything, start/end
    offsets are not being filled out and contain some uninitialized garbage
    from stack. Thus, we need zero out offsets first.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

25 Mar, 2015

2 commits

  • We now have K_VLANT, K_VLANP and K_VLANTPID. Clean them up into more
    descriptive token, namely K_VLAN_TCI, K_VLAN_AVAIL and K_VLAN_TPID.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • If vlan offloading takes place then vlan header is removed from frame
    and its contents, both vlan_tci and vlan_proto, is available to user
    space via TPACKET interface. However, only vlan_tci can be used in BPF
    filters.

    This commit introduces a new BPF extension. It makes possible to load
    the value of vlan_proto (vlan TPID) to register A. Support for classic
    BPF and eBPF is being added, analogous to skb->protocol.

    Cc: Daniel Borkmann
    Cc: Alexei Starovoitov
    Cc: Jiri Pirko

    Signed-off-by: Michal Sekletar
    Acked-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Reviewed-by: Jiri Pirko
    Signed-off-by: David S. Miller

    Michal Sekletar
     

17 May, 2014

2 commits


13 May, 2014

1 commit

  • Conflicts:
    drivers/net/ethernet/altera/altera_sgdma.c
    net/netlink/af_netlink.c
    net/sched/cls_api.c
    net/sched/sch_api.c

    The netlink conflict dealt with moving to netlink_capable() and
    netlink_ns_capable() in the 'net' tree vs. supporting 'tc' operations
    in non-init namespaces. These were simple transformations from
    netlink_capable to netlink_ns_capable.

    The Altera driver conflict was simply code removal overlapping some
    void pointer cast cleanups in net-next.

    Signed-off-by: David S. Miller

    David S. Miller
     

01 May, 2014

1 commit


23 Apr, 2014

1 commit

  • Added a new ancillary load (bpf call in eBPF parlance) that produces
    a 32-bit random number. We are implementing it as an ancillary load
    (instead of an ISA opcode) because (a) it is simpler, (b) allows easy
    JITing, and (c) seems more in line with generic ISAs that do not have
    "get a random number" as a instruction, but as an OS call.

    The main use for this ancillary load is to perform random packet sampling.

    Signed-off-by: Chema Gonzalez
    Acked-by: Alexei Starovoitov
    Acked-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Chema Gonzalez
     

15 Mar, 2014

1 commit


12 Mar, 2014

1 commit

  • Fixes the following build problem with binutils-2.24

    gcc -Wall -O2 -c -o bpf_jit_disasm.o bpf_jit_disasm.c
    In file included from bpf_jit_disasm.c:25:0:
    /usr/include/bfd.h:35:2: error: #error config.h must be included
    before this header
    #error config.h must be included before this header

    This is similar to commit 3ce711a6abc27abce1554e1d671a8762b7187690
    "perf tools: bfd.h/libbfd detection fails with recent binutils"

    See: https://sourceware.org/bugzilla/show_bug.cgi?id=14243

    CC: David S. Miller
    CC: Daniel Borkmann
    CC: netdev@vger.kernel.org
    Acked-by: Daniel Borkmann
    Signed-off-by: Markos Chandras
    Signed-off-by: David S. Miller

    Markos Chandras
     

25 Feb, 2014

1 commit

  • Lets clean up bpf_dbg a bit and improve its code slightly
    in various areas: i) Get rid of some macros as there's no
    good reason for keeping them, ii) remove one unused variable
    and reduce scope of various variables found by cppcheck,
    iii) Close non-default file descriptors when exiting the shell.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

18 Dec, 2013

2 commits

  • Valgrind found that extracted labels that are passed from the lexer
    weren't freed upon exit. Therefore, add a small helper function that
    walks label tables and frees them. Since also NULL can be passed to
    free(3), we do not need to take care of that here. While at it, fix
    up a spacing error in bpf_set_curr_label().

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • We must not leave the socket intact in bpf_runnable(). The socket
    is used to test if the filter code is being accepted by the kernel
    or not. So right after we do the setsockopt(2), we need to close
    it again.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

12 Dec, 2013

2 commits

  • There are a couple of valid use cases for a minimal low-level bpf asm
    like tool, for example, using/linking to libpcap is not an option, the
    required BPF filters use Linux extensions that are not supported by
    libpcap's compiler, a filter might be more complex and not cleanly
    implementable with libpcap's compiler, particular filter codes should
    be optimized differently than libpcap's internal BPF compiler does,
    or for security audits of emitted BPF JIT code for prepared set of BPF
    instructions resp. BPF JIT compiler development in general.

    Then, in such cases writing such a filter in low-level syntax can be
    an good alternative, for example, xt_bpf and cls_bpf users might have
    requirements that could result in more complex filter code, or one that
    cannot be expressed with libpcap (e.g. different return codes in
    cls_bpf for flowids on various BPF code paths).

    Moreover, BPF JIT implementors may wish to manually write test cases
    in order to verify the resulting JIT image, and thus need low-level
    access to BPF code generation as well. Therefore, complete the available
    toolchain for BPF with this small bpf_asm helper tool for the tools/net/
    directory. These 3 complementary minimal helper tools round up and
    facilitate BPF development.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • This patch adds a minimal BPF debugger that "emulates" the kernel's
    BPF engine (w/o extensions) and allows for single stepping (forwards
    and backwards through BPF code) or running with >=1 breakpoints through
    selected or all packets from a pcap file with a provided user filter
    in order to facilitate verification of a BPF program. When a breakpoint
    is being hit, it dumps all register contents, decoded instructions and
    in case of branches both decoded branch targets as well as other useful
    information.

    Having this facility is in particular useful to verify BPF programs
    against given test traffic *before* attaching to a live system.

    With the general availability of cls_bpf, xt_bpf, socket filters,
    team driver and e.g. PTP code, all BPF users, quite often a single
    more complex BPF program is being used. Reasons for a more complex
    BPF program are primarily to optimize execution time for making a
    verdict when multiple simple BPF programs are combined into one in
    order to prevent parsing same headers multiple times. In particular,
    for cls_bpf that can have various return paths for encoding flowids,
    and xt_bpf to come to a fw verdict this can be the case.

    Therefore, as this can result in more complex and harder to debug
    code, it would be very useful to have this minimal tool for testing
    purposes. It can also be of help for BPF JIT developers as filters
    are "test attached" to the kernel on a temporary socket thus
    triggering a JIT image dump when enabled. The tool uses an interactive
    libreadline shell with auto-completion and history support.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

21 Mar, 2013

1 commit

  • This is a minimal stand-alone user space helper, that allows for debugging or
    verification of emitted BPF JIT images. This is in particular useful for
    emitted opcode debugging, since minor bugs in the JIT compiler can be fatal.
    The disassembler is architecture generic and uses libopcodes and libbfd.

    How to get to the disassembly, example:

    1) `echo 2 > /proc/sys/net/core/bpf_jit_enable`
    2) Load a BPF filter (e.g. `tcpdump -p -n -s 0 -i eth1 host 192.168.20.0/24`)
    3) Run e.g. `bpf_jit_disasm -o` to disassemble the most recent JIT code output

    `bpf_jit_disasm -o` will display the related opcodes to a particular instruction
    as well. Example for x86_64:

    $ ./bpf_jit_disasm
    94 bytes emitted from JIT compiler (pass:3, flen:9)
    ffffffffa0356000 + :
    0: push %rbp
    1: mov %rsp,%rbp
    4: sub $0x60,%rsp
    8: mov %rbx,-0x8(%rbp)
    c: mov 0x68(%rdi),%r9d
    10: sub 0x6c(%rdi),%r9d
    14: mov 0xe0(%rdi),%r8
    1b: mov $0xc,%esi
    20: callq 0xffffffffe0d01b71
    25: cmp $0x86dd,%eax
    2a: jne 0x000000000000003d
    2c: mov $0x14,%esi
    31: callq 0xffffffffe0d01b8d
    36: cmp $0x6,%eax
    [...]
    5c: leaveq
    5d: retq

    $ ./bpf_jit_disasm -o
    94 bytes emitted from JIT compiler (pass:3, flen:9)
    ffffffffa0356000 + :
    0: push %rbp
    55
    1: mov %rsp,%rbp
    48 89 e5
    4: sub $0x60,%rsp
    48 83 ec 60
    8: mov %rbx,-0x8(%rbp)
    48 89 5d f8
    c: mov 0x68(%rdi),%r9d
    44 8b 4f 68
    10: sub 0x6c(%rdi),%r9d
    44 2b 4f 6c
    [...]
    5c: leaveq
    c9
    5d: retq
    c3

    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann