Skip to contentSkip to conversation

tests/Makefile: check if BPF library is installed

PATCH In review Ondrej Mosnacek 2 participants 3 messages Sep 20, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/Makefile: check if BPF library is installed

Check for the existence of the <bpf/bpf.h> header before enabling BPF testing. Otherwise building the tests fails in an environment where the kernel and policy support BPF, but the library is not installed.

Fixes 8f0f980a4ad5 ("selinux-testsuite: Add BPF tests")
---
 tests/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tests/Makefile +2 -0
index e5bdfff..e8cf008 100644
@@ -43,10 +43,12 @@ endif
 
 ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
 ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)
+ifneq (,$(wildcard $(INCLUDEDIR)/bpf/bpf.h))
 SUBDIRS += bpf
 export CFLAGS += -DHAVE_BPF
 endif
 endif
+endif
 
 ifeq ($(shell grep "^SELINUX_INFINIBAND_ENDPORT_TEST=" infiniband_endport/ibendport_test.conf | cut -d'=' -f 2),1)
 SUBDIRS += infiniband_endport
Signature · 1 line
2.21.0
#1 lore raw
Quoted 15 lines · Ondrej Mosnacek

Check for the existence of the <bpf/bpf.h> header before enabling BPF testing. Otherwise building the tests fails in an environment where the kernel and policy support BPF, but the library is not installed.

Fixes 8f0f980a4ad5 ("selinux-testsuite: Add BPF tests")
---
  tests/Makefile | 2 ++
  1 file changed, 2 insertions(+)
tests/Makefile +0 -0
index e5bdfff..e8cf008 100644

tests/Makefile endif · line 51

Quoted 9 lines
tests/Makefile +2 -0
@@ -43,10 +43,12 @@ endif
 
  ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
  ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)
+ifneq (,$(wildcard $(INCLUDEDIR)/bpf/bpf.h))
  SUBDIRS += bpf
  export CFLAGS += -DHAVE_BPF
  endif
  endif
+endif

I think Richard had something like this originally and I told him to take it out. The rationale was that he added libbpf-devel as a required dependency to the README and we don't want to silently skip tests because someone forgot to install some package; I'd rather it fail at build time.

Quoted 4 lines
tests/Makefile +0 -0
  ifeq ($(shell grep "^SELINUX_INFINIBAND_ENDPORT_TEST=" infiniband_endport/ibendport_test.conf | cut -d'=' -f 2),1)
  SUBDIRS += infiniband_endport
 
#2 lore raw
Quoted 17 lines · Stephen Smalley
Quoted 16 lines · Ondrej Mosnacek

Check for the existence of the <bpf/bpf.h> header before enabling BPF testing. Otherwise building the tests fails in an environment where the kernel and policy support BPF, but the library is not installed.

Fixes 8f0f980a4ad5 ("selinux-testsuite: Add BPF tests")
---
  tests/Makefile | 2 ++
  1 file changed, 2 insertions(+)
tests/Makefile +0 -0
index e5bdfff..e8cf008 100644
@@ -43,10 +43,12 @@ endif
 
Quoted 14 lines

tests/Makefile endif · line 51

Quoted 8 lines
tests/Makefile +2 -0
  ifeq ($(shell grep -q bpf $(POLDEV)/include/support/all_perms.spt && echo true),true)
  ifneq ($(shell ./kvercmp $$(uname -r) 4.15),-1)
+ifneq (,$(wildcard $(INCLUDEDIR)/bpf/bpf.h))
  SUBDIRS += bpf
  export CFLAGS += -DHAVE_BPF
  endif
  endif
+endif

I think Richard had something like this originally and I told him to take it out. The rationale was that he added libbpf-devel as a required dependency to the README and we don't want to silently skip tests because someone forgot to install some package; I'd rather it fail at build time.

OK, that makes sense. My motivation was the situation on RHEL-8, where the kernel and policy matches the existing checks, but there is no libbpf-devel available (not even in our internal repos or EPEL), but there really doesn't seem to be any better way to handle that other than excluding based on distro name/version. For now I'll just conditionally exclude the test in our wrapper script. (There is a lot of conditional tweaks already, I might try to upstream them one day so that they are not split awkwardly between upstream and downstream...)

Quoted 6 lines

tests/Makefile endif

Quoted 5 lines
tests/Makefile +0 -0
  ifeq ($(shell grep "^SELINUX_INFINIBAND_ENDPORT_TEST=" infiniband_endport/ibendport_test.conf | cut -d'=' -f 2),1)
  SUBDIRS += infiniband_endport
 

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.