21 Jun, 2018

1 commit

  • [ Upstream commit 815425567dea6c54494e85050631d6bdda907c5d ]

    Here the variable cont is used as the saved_pointer for a call to
    strtok_r(). It is safe to use the value uninitialized in this
    context however and the later reference is only ever used if
    the strtok_r is successful. But, 'gcc-5' at least doesn't have all
    this knowledge so initialize cont to NULL. Additionally, do the
    natural NULL check before accessing just for completness.

    The warning is the following:

    ./bpf/tools/bpf/bpf_dbg.c: In function ‘cmd_load’:
    ./bpf/tools/bpf/bpf_dbg.c:1077:13: warning: ‘cont’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    } else if (matches(subcmd, "pcap") == 0) {

    Fixes: fd981e3c321a "filter: bpf_dbg: add minimal bpf debugger"
    Signed-off-by: John Fastabend
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    John Fastabend
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

15 Jun, 2017

1 commit


14 Apr, 2017

1 commit

  • When debugging the JIT on an embedded platform or cross build
    environment, libbfd may not be available, making it impossible to run
    bpf_jit_disasm natively.

    Add an option to emit a binary image of the JIT code to a file. This
    file can then be disassembled off line. Typical usage in this case
    might be (pasting mips64 dmesg output to cat command):

    $ cat > jit.raw
    $ bpf_jit_disasm -f jit.raw -O jit.bin
    $ mips64-linux-gnu-objdump -D -b binary -m mips:isa64r2 -EB jit.bin

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

    David Daney
     

09 May, 2016

1 commit


23 Feb, 2016

1 commit


11 Feb, 2016

1 commit


16 Nov, 2015

1 commit

  • 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

    Kamal Mostafa
     

29 Sep, 2015

1 commit


01 Aug, 2015

1 commit


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