Commit 132895bc authored by Xu Kuohai's avatar Xu Kuohai Committed by Tengda Wu
Browse files

selftests/bpf: Add return value checks for failed tests

mainline inclusion
from mainline-v6.12-rc1
commit 2b23b6c0f03c94dbacff2abdfd45490eca9d7f6e
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IAYPJF

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2b23b6c0f03c94dbacff2abdfd45490eca9d7f6e



--------------------------------

The return ranges of some bpf lsm test progs can not be deduced by
the verifier accurately. To avoid erroneous rejections, add explicit
return value checks for these progs.

Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20240719110059.797546-8-xukuohai@huaweicloud.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>

Conflicts:
	tools/testing/selftests/bpf/progs/test_sig_in_xattr.c
	tools/testing/selftests/bpf/progs/verifier_global_subprogs.c
	tools/testing/selftests/bpf/progs/test_verify_pkcs7_sig.c
[Skip backporting 1030e9154258 and e8a339b5235e2 since they depend
on those patch series with introducing new features]
Signed-off-by: default avatarTengda Wu <wutengda2@huawei.com>
parent c3e09d62
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -5,6 +5,16 @@
#define MAX_ERRNO 4095
#define IS_ERR_VALUE(x) (unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO

#define __STR(x) #x

#define set_if_not_errno_or_zero(x, y)			\
({							\
	asm volatile ("if %0 s< -4095 goto +1\n"	\
		      "if %0 s<= 0 goto +1\n"		\
		      "%0 = " __STR(y) "\n"		\
		      : "+r"(x));			\
})

static inline int IS_ERR_OR_NULL(const void *ptr)
{
	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+6 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <errno.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "err.h"

#define MAX_DATA_SIZE (1024 * 1024)
#define MAX_SIG_SIZE 1024
@@ -61,12 +62,12 @@ int BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size)

	ret = bpf_probe_read_kernel(&value, sizeof(value), &attr->value);
	if (ret)
		return ret;
		goto out;

	ret = bpf_copy_from_user(data_val, sizeof(struct data),
				 (void *)(unsigned long)value);
	if (ret)
		return ret;
		goto out;

	if (data_val->data_len > sizeof(data_val->data))
		return -EINVAL;
@@ -90,5 +91,8 @@ int BPF_PROG(bpf, int cmd, union bpf_attr *attr, unsigned int size)

	bpf_key_put(trusted_keyring);

out:
	set_if_not_errno_or_zero(ret, -EFAULT);

	return ret;
}