Skip to content

Commit fc97590

Browse files
robertosassuAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test for bpf_verify_pkcs7_signature() kfunc
Perform several tests to ensure the correct implementation of the bpf_verify_pkcs7_signature() kfunc. Do the tests with data signed with a generated testing key (by using sign-file from scripts/) and with the tcp_bic.ko kernel module if it is found in the system. The test does not fail if tcp_bic.ko is not found. First, perform an unsuccessful signature verification without data. Second, perform a successful signature verification with the session keyring and a new one created for testing. Then, ensure that permission and validation checks are done properly on the keyring provided to bpf_verify_pkcs7_signature(), despite those checks were deferred at the time the keyring was retrieved with bpf_lookup_user_key(). The tests expect to encounter an error if the Search permission is removed from the keyring, or the keyring is expired. Finally, perform a successful and unsuccessful signature verification with the keyrings with pre-determined IDs (the last test fails because the key is not in the platform keyring). The test is currently in the deny list for s390x (JIT does not support calling kernel function). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Link: https://lore.kernel.org/r/20220920075951.929132-13-roberto.sassu@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ecce368 commit fc97590

File tree

7 files changed

+610
-8
lines changed

7 files changed

+610
-8
lines changed

tools/testing/selftests/bpf/DENYLIST.s390x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ htab_update # failed to attach: ERROR: strerror_r(-
7373
tracing_struct # failed to auto-attach: -524 (trampoline)
7474
user_ringbuf # failed to find kernel BTF type ID of '__s390x_sys_prctl': -3 (?)
7575
lookup_key # JIT does not support calling kernel function (kfunc)
76+
verify_pkcs7_sig # JIT does not support calling kernel function (kfunc)

tools/testing/selftests/bpf/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
1414
APIDIR := $(TOOLSINCDIR)/uapi
1515
GENDIR := $(abspath ../../../../include/generated)
1616
GENHDR := $(GENDIR)/autoconf.h
17+
HOSTPKG_CONFIG := pkg-config
1718

1819
ifneq ($(wildcard $(GENHDR)),)
1920
GENFLAGS := -DHAVE_GENHDR
@@ -75,7 +76,7 @@ TEST_PROGS := test_kmod.sh \
7576
test_xsk.sh
7677

7778
TEST_PROGS_EXTENDED := with_addr.sh \
78-
with_tunnels.sh ima_setup.sh \
79+
with_tunnels.sh ima_setup.sh verify_sig_setup.sh \
7980
test_xdp_vlan.sh test_bpftool.py
8081

8182
# Compile but not part of 'make run_tests'
@@ -84,7 +85,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
8485
test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
8586
xskxceiver xdp_redirect_multi xdp_synproxy veristat
8687

87-
TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read
88+
TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read $(OUTPUT)/sign-file
8889

8990
# Emit succinct information message describing current building step
9091
# $1 - generic step name (e.g., CC, LINK, etc);
@@ -189,6 +190,12 @@ $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_r
189190
-fuse-ld=$(LLD) -Wl,-znoseparate-code \
190191
-Wl,-rpath=. -Wl,--build-id=sha1 -o $@
191192

193+
$(OUTPUT)/sign-file: ../../../../scripts/sign-file.c
194+
$(call msg,SIGN-FILE,,$@)
195+
$(Q)$(CC) $(shell $(HOSTPKG_CONFIG)--cflags libcrypto 2> /dev/null) \
196+
$< -o $@ \
197+
$(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
198+
192199
$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
193200
$(call msg,MOD,,$@)
194201
$(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
@@ -516,7 +523,8 @@ TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
516523
TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
517524
$(OUTPUT)/liburandom_read.so \
518525
$(OUTPUT)/xdp_synproxy \
519-
ima_setup.sh \
526+
$(OUTPUT)/sign-file \
527+
ima_setup.sh verify_sig_setup.sh \
520528
$(wildcard progs/btf_dump_test_case_*.c)
521529
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
522530
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS

tools/testing/selftests/bpf/config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ CONFIG_IPV6_TUNNEL=y
3333
CONFIG_KEYS=y
3434
CONFIG_LIRC=y
3535
CONFIG_LWTUNNEL=y
36+
CONFIG_MODULE_SIG=y
37+
CONFIG_MODULE_SRCVERSION_ALL=y
38+
CONFIG_MODULE_UNLOAD=y
39+
CONFIG_MODULES=y
40+
CONFIG_MODVERSIONS=y
3641
CONFIG_MPLS=y
3742
CONFIG_MPLS_IPTUNNEL=y
3843
CONFIG_MPLS_ROUTING=y

tools/testing/selftests/bpf/config.x86_64

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ CONFIG_MCORE2=y
145145
CONFIG_MEMCG=y
146146
CONFIG_MEMORY_FAILURE=y
147147
CONFIG_MINIX_SUBPARTITION=y
148-
CONFIG_MODULE_SIG=y
149-
CONFIG_MODULE_SRCVERSION_ALL=y
150-
CONFIG_MODULE_UNLOAD=y
151-
CONFIG_MODULES=y
152-
CONFIG_MODVERSIONS=y
153148
CONFIG_NAMESPACES=y
154149
CONFIG_NET=y
155150
CONFIG_NET_9P=y

0 commit comments

Comments
 (0)