1. 27 2月, 2018 4 次提交
  2. 25 2月, 2018 1 次提交
  3. 24 2月, 2018 12 次提交
  4. 23 2月, 2018 1 次提交
    • D
      bpf, arm64: fix out of bounds access in tail call · 16338a9b
      Daniel Borkmann 提交于
      I recently noticed a crash on arm64 when feeding a bogus index
      into BPF tail call helper. The crash would not occur when the
      interpreter is used, but only in case of JIT. Output looks as
      follows:
      
        [  347.007486] Unable to handle kernel paging request at virtual address fffb850e96492510
        [...]
        [  347.043065] [fffb850e96492510] address between user and kernel address ranges
        [  347.050205] Internal error: Oops: 96000004 [#1] SMP
        [...]
        [  347.190829] x13: 0000000000000000 x12: 0000000000000000
        [  347.196128] x11: fffc047ebe782800 x10: ffff808fd7d0fd10
        [  347.201427] x9 : 0000000000000000 x8 : 0000000000000000
        [  347.206726] x7 : 0000000000000000 x6 : 001c991738000000
        [  347.212025] x5 : 0000000000000018 x4 : 000000000000ba5a
        [  347.217325] x3 : 00000000000329c4 x2 : ffff808fd7cf0500
        [  347.222625] x1 : ffff808fd7d0fc00 x0 : ffff808fd7cf0500
        [  347.227926] Process test_verifier (pid: 4548, stack limit = 0x000000007467fa61)
        [  347.235221] Call trace:
        [  347.237656]  0xffff000002f3a4fc
        [  347.240784]  bpf_test_run+0x78/0xf8
        [  347.244260]  bpf_prog_test_run_skb+0x148/0x230
        [  347.248694]  SyS_bpf+0x77c/0x1110
        [  347.251999]  el0_svc_naked+0x30/0x34
        [  347.255564] Code: 9100075a d280220a 8b0a002a d37df04b (f86b694b)
        [...]
      
      In this case the index used in BPF r3 is the same as in r1
      at the time of the call, meaning we fed a pointer as index;
      here, it had the value 0xffff808fd7cf0500 which sits in x2.
      
      While I found tail calls to be working in general (also for
      hitting the error cases), I noticed the following in the code
      emission:
      
        # bpftool p d j i 988
        [...]
        38:   ldr     w10, [x1,x10]
        3c:   cmp     w2, w10
        40:   b.ge    0x000000000000007c              <-- signed cmp
        44:   mov     x10, #0x20                      // #32
        48:   cmp     x26, x10
        4c:   b.gt    0x000000000000007c
        50:   add     x26, x26, #0x1
        54:   mov     x10, #0x110                     // #272
        58:   add     x10, x1, x10
        5c:   lsl     x11, x2, #3
        60:   ldr     x11, [x10,x11]                  <-- faulting insn (f86b694b)
        64:   cbz     x11, 0x000000000000007c
        [...]
      
      Meaning, the tests passed because commit ddb55992 ("arm64:
      bpf: implement bpf_tail_call() helper") was using signed compares
      instead of unsigned which as a result had the test wrongly passing.
      
      Change this but also the tail call count test both into unsigned
      and cap the index as u32. Latter we did as well in 90caccdd
      ("bpf: fix bpf_tail_call() x64 JIT") and is needed in addition here,
      too. Tested on HiSilicon Hi1616.
      
      Result after patch:
      
        # bpftool p d j i 268
        [...]
        38:	ldr	w10, [x1,x10]
        3c:	add	w2, w2, #0x0
        40:	cmp	w2, w10
        44:	b.cs	0x0000000000000080
        48:	mov	x10, #0x20                  	// #32
        4c:	cmp	x26, x10
        50:	b.hi	0x0000000000000080
        54:	add	x26, x26, #0x1
        58:	mov	x10, #0x110                 	// #272
        5c:	add	x10, x1, x10
        60:	lsl	x11, x2, #3
        64:	ldr	x11, [x10,x11]
        68:	cbz	x11, 0x0000000000000080
        [...]
      
      Fixes: ddb55992 ("arm64: bpf: implement bpf_tail_call() helper")
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      16338a9b
  5. 22 2月, 2018 6 次提交
    • L
      selftests/bpf/test_maps: exit child process without error in ENOMEM case · 80475c48
      Li Zhijian 提交于
      test_maps contains a series of stress tests, and previously it will break the
      rest tests when it failed to alloc memory.
      -----------------------
      Failed to create hashmap key=8 value=262144 'Cannot allocate memory'
      Failed to create hashmap key=16 value=262144 'Cannot allocate memory'
      Failed to create hashmap key=8 value=262144 'Cannot allocate memory'
      Failed to create hashmap key=8 value=262144 'Cannot allocate memory'
      test_maps: test_maps.c:955: run_parallel: Assertion `status == 0' failed.
      Aborted
      not ok 1..3 selftests:  test_maps [FAIL]
      -----------------------
      after this patch, the rest tests will be continue when it occurs an ENOMEM failure
      
      CC: Alexei Starovoitov <alexei.starovoitov@gmail.com>
      CC: Philip Li <philip.li@intel.com>
      Suggested-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NLi Zhijian <zhijianx.li@intel.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      80475c48
    • T
      seccomp: add a selftest for get_metadata · d057dc4e
      Tycho Andersen 提交于
      Let's test that we get the flags correctly, and that we preserve the filter
      index across the ptrace(PTRACE_SECCOMP_GET_METADATA) correctly.
      Signed-off-by: NTycho Andersen <tycho@tycho.ws>
      CC: Kees Cook <keescook@chromium.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      d057dc4e
    • A
      selftests/bpf: update gitignore with test_libbpf_open · 31a8260d
      Anders Roxell 提交于
      bpf builds a test program for loading BPF ELF files. Add the executable
      to the .gitignore list.
      Signed-off-by: NAnders Roxell <anders.roxell@linaro.org>
      Tested-by: NDaniel Díaz <daniel.diaz@linaro.org>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Acked-by: NShuah Khan <shuahkh@osg.samsung.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      31a8260d
    • A
      selftests/bpf: tcpbpf_kern: use in6_* macros from glibc · b52db43a
      Anders Roxell 提交于
      Both glibc and the kernel have in6_* macros definitions. Build fails
      because it picks up wrong in6_* macro from the kernel header and not the
      header from glibc.
      
      Fixes build error below:
      clang -I. -I./include/uapi -I../../../include/uapi
           -Wno-compare-distinct-pointer-types \
               -O2 -target bpf -emit-llvm -c test_tcpbpf_kern.c -o - |      \
      llc -march=bpf -mcpu=generic -filetype=obj
           -o .../tools/testing/selftests/bpf/test_tcpbpf_kern.o
      In file included from test_tcpbpf_kern.c:12:
      .../netinet/in.h:101:5: error: expected identifier
          IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
          ^
      .../linux/in6.h:131:26: note: expanded from macro 'IPPROTO_HOPOPTS'
                                      ^
      In file included from test_tcpbpf_kern.c:12:
      /usr/include/netinet/in.h:103:5: error: expected identifier
          IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
          ^
      .../linux/in6.h:132:26: note: expanded from macro 'IPPROTO_ROUTING'
                                      ^
      In file included from test_tcpbpf_kern.c:12:
      .../netinet/in.h:105:5: error: expected identifier
          IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
          ^
      
      Since both glibc and the kernel have in6_* macros definitions, use the
      one from glibc.  Kernel headers will check for previous libc definitions
      by including include/linux/libc-compat.h.
      Reported-by: NDaniel Díaz <daniel.diaz@linaro.org>
      Signed-off-by: NAnders Roxell <anders.roxell@linaro.org>
      Tested-by: NDaniel Díaz <daniel.diaz@linaro.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      b52db43a
    • A
      selftests/memfd: add run_fuse_test.sh to TEST_FILES · bdefe01a
      Anders Roxell 提交于
      While testing memfd tests, there is a missing script, as reported by
      kselftest:
      
        ./run_tests.sh: line 7: ./run_fuse_test.sh: No such file or directory
      
      Link: http://lkml.kernel.org/r/1517955779-11386-1-git-send-email-daniel.diaz@linaro.orgSigned-off-by: NAnders Roxell <anders.roxell@linaro.org>
      Signed-off-by: NDaniel Díaz <daniel.diaz@linaro.org>
      Cc: Shuah Khan <shuah@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      bdefe01a
    • M
      tools: fix cross-compile var clobbering · 7ed1c190
      Martin Kelly 提交于
      Currently a number of Makefiles break when used with toolchains that
      pass extra flags in CC and other cross-compile related variables (such
      as --sysroot).
      
      Thus we get this error when we use a toolchain that puts --sysroot in
      the CC var:
      
        ~/src/linux/tools$ make iio
        [snip]
        iio_event_monitor.c:18:10: fatal error: unistd.h: No such file or directory
          #include <unistd.h>
                   ^~~~~~~~~~
      
      This occurs because we clobber several env vars related to
      cross-compiling with lines like this:
      
        CC = $(CROSS_COMPILE)gcc
      
      Although this will point to a valid cross-compiler, we lose any extra
      flags that might exist in the CC variable, which can break toolchains
      that rely on them (for example, those that use --sysroot).
      
      This easily shows up using a Yocto SDK:
      
        $ . [snip]/sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi
      
        $ echo $CC
        arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard
        -mcpu=cortex-a8
        --sysroot=[snip]/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi
      
        $ echo $CROSS_COMPILE
        arm-poky-linux-gnueabi-
      
        $ echo ${CROSS_COMPILE}gcc
        krm-poky-linux-gnueabi-gcc
      
      Although arm-poky-linux-gnueabi-gcc is a cross-compiler, we've lost the
      --sysroot and other flags that enable us to find the right libraries to
      link against, so we can't find unistd.h and other libraries and headers.
      Normally with the --sysroot flag we would find unistd.h in the sdk
      directory in the sysroot:
      
        $ find [snip]/sdk/sysroots -path '*/usr/include/unistd.h'
        [snip]/sdk/sysroots/cortexa8hf-neon-poky-linux-gnueabi/usr/include/unistd.h
      
      The perf Makefile adds CC = $(CROSS_COMPILE)gcc if and only if CC is not
      already set, and it compiles correctly with the above toolchain.
      
      So, generalize the logic that perf uses in the common Makefile and
      remove the manual CC = $(CROSS_COMPILE)gcc lines from each Makefile.
      
      Note that this patch does not fix cross-compile for all the tools (some
      have other bugs), but it does fix it for all except usb and acpi, which
      still have other unrelated issues.
      
      I tested both with and without the patch on native and cross-build and
      there appear to be no regressions.
      
      Link: http://lkml.kernel.org/r/20180107214028.23771-1-martin@martingkelly.comSigned-off-by: NMartin Kelly <martin@martingkelly.com>
      Acked-by: NMark Brown <broonie@kernel.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: "K. Y. Srinivasan" <kys@microsoft.com>
      Cc: Haiyang Zhang <haiyangz@microsoft.com>
      Cc: Stephen Hemminger <sthemmin@microsoft.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Pali Rohar <pali.rohar@gmail.com>
      Cc: Richard Purdie <rpurdie@rpsys.net>
      Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Robert Moore <robert.moore@intel.com>
      Cc: Lv Zheng <lv.zheng@intel.com>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Valentina Manea <valentina.manea.m@gmail.com>
      Cc: Shuah Khan <shuah@kernel.org>
      Cc: Mario Limonciello <mario.limonciello@dell.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7ed1c190
  6. 21 2月, 2018 4 次提交
  7. 15 2月, 2018 12 次提交