selftests/bpf: Fix IMA test
authorRoberto Sassu <roberto.sassu@huawei.com>
Wed, 8 Mar 2023 10:37:13 +0000 (11:37 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 8 Mar 2023 19:15:39 +0000 (11:15 -0800)
commit12fabae03ca6474fd571bf6ddb37d009533305d6
treed8204b0c6c5cd2a6d675777bc0f7f1349124adfe
parentd1d51a62d060d02f99ee407959e24ad10a40e053
selftests/bpf: Fix IMA test

Commit 62622dab0a28 ("ima: return IMA digest value only when IMA_COLLECTED
flag is set") caused bpf_ima_inode_hash() to refuse to give non-fresh
digests. IMA test #3 assumed the old behavior, that bpf_ima_inode_hash()
still returned also non-fresh digests.

Correct the test by accepting both cases. If the samples returned are 1,
assume that the commit above is applied and that the returned digest is
fresh. If the samples returned are 2, assume that the commit above is not
applied, and check both the non-fresh and fresh digest.

Fixes: 62622dab0a28 ("ima: return IMA digest value only when IMA_COLLECTED flag is set")
Reported-by: David Vernet <void@manifault.com>
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Matt Bobrowski <mattbobrowski@google.com>
Link: https://lore.kernel.org/bpf/20230308103713.1681200-1-roberto.sassu@huaweicloud.com
tools/testing/selftests/bpf/prog_tests/test_ima.c