1. 10 Feb, 2021 5 commits
    • Alexei Starovoitov's avatar
      Merge branch 'allow variable-offset stack acces' · cf2d0a5e
      Alexei Starovoitov authored
      Andrei Matei says:
      
      ====================
      
      Before this patch, variable offset access to the stack was dissalowed
      for regular instructions, but was allowed for "indirect" accesses (i.e.
      helpers). This patch removes the restriction, allowing reading and
      writing to the stack through stack pointers with variable offsets. This
      makes stack-allocated buffers more usable in programs, and brings stack
      pointers closer to other types of pointers.
      
      The motivation is being able to use stack-allocated buffers for data
      manipulation. When the stack size limit is sufficient, allocating
      buffers on the stack is simpler than per-cpu arrays, or other
      alternatives.
      
      V2 -> V3
      
      - var-offset writes mark all the stack slots in range as initialized, so
        that future reads are not rejected.
      - rewrote the C test to not use uprobes, as per Andrii's suggestion.
      - addressed other review comments from Alexei.
      
      V1 -> V2
      
      - add support for var-offset stack writes, in addition to reads
      - add a C test
      - made variable offset direct reads no longer destroy spilled registers
        in the access range
      - address review nits
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      cf2d0a5e
    • Andrei Matei's avatar
      selftest/bpf: Add test for var-offset stack access · 0fd7562a
      Andrei Matei authored
      Add a higher-level test (C BPF program) for the new functionality -
      variable access stack reads and writes.
      Signed-off-by: default avatarAndrei Matei <andreimatei1@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210207011027.676572-5-andreimatei1@gmail.com
      0fd7562a
    • Andrei Matei's avatar
      selftest/bpf: Verifier tests for var-off access · 7a22930c
      Andrei Matei authored
      Add tests for the new functionality - reading and writing to the stack
      through a variable-offset pointer.
      Signed-off-by: default avatarAndrei Matei <andreimatei1@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210207011027.676572-4-andreimatei1@gmail.com
      7a22930c
    • Andrei Matei's avatar
      selftest/bpf: Adjust expected verifier errors · a680cb3d
      Andrei Matei authored
      The verifier errors around stack accesses have changed slightly in the
      previous commit (generally for the better).
      Signed-off-by: default avatarAndrei Matei <andreimatei1@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210207011027.676572-3-andreimatei1@gmail.com
      a680cb3d
    • Andrei Matei's avatar
      bpf: Allow variable-offset stack access · 01f810ac
      Andrei Matei authored
      Before this patch, variable offset access to the stack was dissalowed
      for regular instructions, but was allowed for "indirect" accesses (i.e.
      helpers). This patch removes the restriction, allowing reading and
      writing to the stack through stack pointers with variable offsets. This
      makes stack-allocated buffers more usable in programs, and brings stack
      pointers closer to other types of pointers.
      
      The motivation is being able to use stack-allocated buffers for data
      manipulation. When the stack size limit is sufficient, allocating
      buffers on the stack is simpler than per-cpu arrays, or other
      alternatives.
      
      In unpriviledged programs, variable-offset reads and writes are
      disallowed (they were already disallowed for the indirect access case)
      because the speculative execution checking code doesn't support them.
      Additionally, when writing through a variable-offset stack pointer, if
      any pointers are in the accessible range, there's possilibities of later
      leaking pointers because the write cannot be tracked precisely.
      
      Writes with variable offset mark the whole range as initialized, even
      though we don't know which stack slots are actually written. This is in
      order to not reject future reads to these slots. Note that this doesn't
      affect writes done through helpers; like before, helpers need the whole
      stack range to be initialized to begin with.
      All the stack slots are in range are considered scalars after the write;
      variable-offset register spills are not tracked.
      
      For reads, all the stack slots in the variable range needs to be
      initialized (but see above about what writes do), otherwise the read is
      rejected. All register spilled in stack slots that might be read are
      marked as having been read, however reads through such pointers don't do
      register filling; the target register will always be either a scalar or
      a constant zero.
      Signed-off-by: default avatarAndrei Matei <andreimatei1@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210207011027.676572-2-andreimatei1@gmail.com
      01f810ac
  2. 09 Feb, 2021 8 commits
  3. 08 Feb, 2021 1 commit
  4. 05 Feb, 2021 7 commits
  5. 04 Feb, 2021 3 commits
  6. 03 Feb, 2021 4 commits
  7. 02 Feb, 2021 1 commit
    • Tiezhu Yang's avatar
      samples/bpf: Add include dir for MIPS Loongson64 to fix build errors · 058107ab
      Tiezhu Yang authored
      There exists many build errors when make M=samples/bpf on the Loongson
      platform. This issue is MIPS related, x86 compiles just fine.
      
      Here are some errors:
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:19:
      In file included from ./arch/mips/include/asm/barrier.h:11:
      ./arch/mips/include/asm/addrspace.h:13:10: fatal error: 'spaces.h' file not found
               ^~~~~~~~~~
      1 error generated.
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:22:
      In file included from ./arch/mips/include/asm/cpu-features.h:13:
      In file included from ./arch/mips/include/asm/cpu-info.h:15:
      In file included from ./include/linux/cache.h:6:
      ./arch/mips/include/asm/cache.h:12:10: fatal error: 'kmalloc.h' file not found
               ^~~~~~~~~~~
      1 error generated.
      
        CLANG-bpf  samples/bpf/sockex2_kern.o
      In file included from samples/bpf/sockex2_kern.c:2:
      In file included from ./include/uapi/linux/in.h:24:
      In file included from ./include/linux/socket.h:8:
      In file included from ./include/linux/uio.h:8:
      In file included from ./include/linux/kernel.h:11:
      In file included from ./include/linux/bitops.h:32:
      In file included from ./arch/mips/include/asm/bitops.h:22:
      ./arch/mips/include/asm/cpu-features.h:15:10: fatal error: 'cpu-feature-overrides.h' file not found
               ^~~~~~~~~~~~~~~~~~~~~~~~~
      1 error generated.
      
      $ find arch/mips/include/asm -name spaces.h | sort
      arch/mips/include/asm/mach-ar7/spaces.h
      ...
      arch/mips/include/asm/mach-generic/spaces.h
      ...
      arch/mips/include/asm/mach-loongson64/spaces.h
      ...
      arch/mips/include/asm/mach-tx49xx/spaces.h
      
      $ find arch/mips/include/asm -name kmalloc.h | sort
      arch/mips/include/asm/mach-generic/kmalloc.h
      arch/mips/include/asm/mach-ip32/kmalloc.h
      arch/mips/include/asm/mach-tx49xx/kmalloc.h
      
      $ find arch/mips/include/asm -name cpu-feature-overrides.h | sort
      arch/mips/include/asm/mach-ath25/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-generic/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-loongson64/cpu-feature-overrides.h
      ...
      arch/mips/include/asm/mach-tx49xx/cpu-feature-overrides.h
      
      In the arch/mips/Makefile, there exists the following board-dependent
      options:
      
      include arch/mips/Kbuild.platforms
      cflags-y += -I$(srctree)/arch/mips/include/asm/mach-generic
      
      So we can do the similar things in samples/bpf/Makefile, just add
      platform specific and generic include dir for MIPS Loongson64 to
      fix the build errors.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/1611669925-25315-1-git-send-email-yangtiezhu@loongson.cn
      058107ab
  8. 29 Jan, 2021 6 commits
  9. 28 Jan, 2021 2 commits
  10. 27 Jan, 2021 2 commits
  11. 26 Jan, 2021 1 commit