1. 26 Oct, 2023 5 commits
    • Yafang Shao's avatar
      selftests/bpf: Fix selftests broken by mitigations=off · 399f6185
      Yafang Shao authored
      When we configure the kernel command line with 'mitigations=off' and set
      the sysctl knob 'kernel.unprivileged_bpf_disabled' to 0, the commit
      bc5bc309 ("bpf: Inherit system settings for CPU security mitigations")
      causes issues in the execution of `test_progs -t verifier`. This is
      because 'mitigations=off' bypasses Spectre v1 and Spectre v4 protections.
      
      Currently, when a program requests to run in unprivileged mode
      (kernel.unprivileged_bpf_disabled = 0), the BPF verifier may prevent
      it from running due to the following conditions not being enabled:
      
        - bypass_spec_v1
        - bypass_spec_v4
        - allow_ptr_leaks
        - allow_uninit_stack
      
      While 'mitigations=off' enables the first two conditions, it does not
      enable the latter two. As a result, some test cases in
      'test_progs -t verifier' that were expected to fail to run may run
      successfully, while others still fail but with different error messages.
      This makes it challenging to address them comprehensively.
      
      Moreover, in the future, we may introduce more fine-grained control over
      CPU mitigations, such as enabling only bypass_spec_v1 or bypass_spec_v4.
      
      Given the complexity of the situation, rather than fixing each broken test
      case individually, it's preferable to skip them when 'mitigations=off' is
      in effect and introduce specific test cases for the new 'mitigations=off'
      scenario. For instance, we can introduce new BTF declaration tags like
      '__failure__nospec', '__failure_nospecv1' and '__failure_nospecv4'.
      
      In this patch, the approach is to simply skip the broken test cases when
      'mitigations=off' is enabled. The result of `test_progs -t verifier` as
      follows after this commit,
      
      Before this commit
      ==================
      
      - without 'mitigations=off'
        - kernel.unprivileged_bpf_disabled = 2
          Summary: 74/948 PASSED, 388 SKIPPED, 0 FAILED
        - kernel.unprivileged_bpf_disabled = 0
          Summary: 74/1336 PASSED, 0 SKIPPED, 0 FAILED    <<<<
      - with 'mitigations=off'
        - kernel.unprivileged_bpf_disabled = 2
          Summary: 74/948 PASSED, 388 SKIPPED, 0 FAILED
        - kernel.unprivileged_bpf_disabled = 0
          Summary: 63/1276 PASSED, 0 SKIPPED, 11 FAILED   <<<< 11 FAILED
      
      After this commit
      =================
      
      - without 'mitigations=off'
        - kernel.unprivileged_bpf_disabled = 2
          Summary: 74/948 PASSED, 388 SKIPPED, 0 FAILED
        - kernel.unprivileged_bpf_disabled = 0
          Summary: 74/1336 PASSED, 0 SKIPPED, 0 FAILED    <<<<
      - with this patch, with 'mitigations=off'
        - kernel.unprivileged_bpf_disabled = 2
          Summary: 74/948 PASSED, 388 SKIPPED, 0 FAILED
        - kernel.unprivileged_bpf_disabled = 0
          Summary: 74/948 PASSED, 388 SKIPPED, 0 FAILED   <<<< SKIPPED
      
      Fixes: bc5bc309 ("bpf: Inherit system settings for CPU security mitigations")
      Reported-by: default avatarAlexei Starovoitov <alexei.starovoitov@gmail.com>
      Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Closes: https://lore.kernel.org/bpf/CAADnVQKUBJqg+hHtbLeeC2jhoJAWqnmRAzXW3hmUCNSV9kx4sQ@mail.gmail.com
      Link: https://lore.kernel.org/bpf/20231025031144.5508-1-laoar.shao@gmail.com
      399f6185
    • Viktor Malik's avatar
      samples/bpf: Allow building with custom bpftool · 37db10bc
      Viktor Malik authored
      samples/bpf build its own bpftool boostrap to generate vmlinux.h as well
      as some BPF objects. This is a redundant step if bpftool has been
      already built, so update samples/bpf/Makefile such that it accepts a
      path to bpftool passed via the BPFTOOL variable. The approach is
      practically the same as tools/testing/selftests/bpf/Makefile uses.
      Signed-off-by: default avatarViktor Malik <vmalik@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/bd746954ac271b02468d8d951ff9f11e655d485b.1698213811.git.vmalik@redhat.com
      37db10bc
    • Viktor Malik's avatar
      samples/bpf: Fix passing LDFLAGS to libbpf · f56bcfad
      Viktor Malik authored
      samples/bpf/Makefile passes LDFLAGS=$(TPROGS_LDFLAGS) to libbpf build
      without surrounding quotes, which may cause compilation errors when
      passing custom TPROGS_USER_LDFLAGS.
      
      For example:
      
          $ make -C samples/bpf/ TPROGS_USER_LDFLAGS="-Wl,--as-needed -specs=/usr/lib/gcc/x86_64-redhat-linux/13/libsanitizer.spec"
          make: Entering directory './samples/bpf'
          make -C ../../ M=./samples/bpf BPF_SAMPLES_PATH=./samples/bpf
          make[1]: Entering directory '.'
          make -C ./samples/bpf/../../tools/lib/bpf RM='rm -rf' EXTRA_CFLAGS="-Wall -O2 -Wmissing-prototypes -Wstrict-prototypes  -I./usr/include -I./tools/testing/selftests/bpf/ -I./samples/bpf/libbpf/include -I./tools/include -I./tools/perf -I./tools/lib -DHAVE_ATTR_TEST=0" \
                  LDFLAGS=-Wl,--as-needed -specs=/usr/lib/gcc/x86_64-redhat-linux/13/libsanitizer.spec srctree=./samples/bpf/../../ \
                  O= OUTPUT=./samples/bpf/libbpf/ DESTDIR=./samples/bpf/libbpf prefix= \
                  ./samples/bpf/libbpf/libbpf.a install_headers
          make: invalid option -- 'c'
          make: invalid option -- '='
          make: invalid option -- '/'
          make: invalid option -- 'u'
          make: invalid option -- '/'
          [...]
      
      Fix the error by properly quoting $(TPROGS_LDFLAGS).
      Suggested-by: default avatarDonald Zickus <dzickus@redhat.com>
      Signed-off-by: default avatarViktor Malik <vmalik@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/c690de6671cc6c983d32a566d33fd7eabd18b526.1698213811.git.vmalik@redhat.com
      f56bcfad
    • Viktor Malik's avatar
      samples/bpf: Allow building with custom CFLAGS/LDFLAGS · 870f09f1
      Viktor Malik authored
      Currently, it is not possible to specify custom flags when building
      samples/bpf. The flags are defined in TPROGS_CFLAGS/TPROGS_LDFLAGS
      variables, however, when trying to override those from the make command,
      compilation fails.
      
      For example, when trying to build with PIE:
      
          $ make -C samples/bpf TPROGS_CFLAGS="-fpie" TPROGS_LDFLAGS="-pie"
      
      This is because samples/bpf/Makefile updates these variables, especially
      appends include paths to TPROGS_CFLAGS and these updates are overridden
      by setting the variables from the make command.
      
      This patch introduces variables TPROGS_USER_CFLAGS/TPROGS_USER_LDFLAGS
      for this purpose, which can be set from the make command and their
      values are propagated to TPROGS_CFLAGS/TPROGS_LDFLAGS.
      Signed-off-by: default avatarViktor Malik <vmalik@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/2d81100b830a71f0e72329cc7781edaefab75f62.1698213811.git.vmalik@redhat.com
      870f09f1
    • Hou Tao's avatar
      bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free · c421c125
      Hou Tao authored
      There are two possible mismatched alloc and free cases in BPF memory
      allocator:
      
      1) allocate from cache X but free by cache Y with a different unit_size
      2) allocate from per-cpu cache but free by kmalloc cache or vice versa
      
      So add more WARN_ON_ONCE checks in free_bulk() and __free_by_rcu() to
      spot these mismatched alloc and free early.
      Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20231021014959.3563841-1-houtao@huaweicloud.com
      c421c125
  2. 24 Oct, 2023 20 commits
  3. 23 Oct, 2023 2 commits
  4. 20 Oct, 2023 13 commits