selftests/bpf: Add test for bpf_verify_pkcs7_signature() kfunc
authorRoberto Sassu <roberto.sassu@huawei.com>
Tue, 20 Sep 2022 07:59:50 +0000 (09:59 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 22 Sep 2022 00:33:42 +0000 (17:33 -0700)
commitfc97590668ae60b94ad8bc4d9e85958f10cb3567
tree3dd6fed1cde30036a0d3926b13717c21b59c5068
parentecce368d6e6d76168be5d8d34b411c69ec367859
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>
tools/testing/selftests/bpf/DENYLIST.s390x
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/config
tools/testing/selftests/bpf/config.x86_64
tools/testing/selftests/bpf/prog_tests/verify_pkcs7_sig.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c [new file with mode: 0644]
tools/testing/selftests/bpf/verify_sig_setup.sh [new file with mode: 0755]