diff mbox series

[net-next,2/4] bpf: Use bpfptr_is_kernel() instead of checking the is_kernel member.

Message ID 96098101c3904e3d94c756fa9af392b4@AcuMS.aculab.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series sockptr: Change sockptr_t to be a struct | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1132 this patch: 1132
netdev/cc_maintainers warning 8 maintainers not CCed: sdf@google.com haoluo@google.com bpf@vger.kernel.org jolsa@kernel.org kpsingh@kernel.org yonghong.song@linux.dev song@kernel.org john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 1141 this patch: 1141
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1159 this patch: 1159
netdev/checkpatch warning CHECK: From:/Signed-off-by: email comments mismatch: 'From: David Laight <David.Laight@ACULAB.COM>' != 'Signed-off-by: David Laight <david.laight@aculab.com>' WARNING: line length of 83 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

David Laight Dec. 25, 2023, 9:55 a.m. UTC
In some places the bpf code directly access the is_kernel member of bpfptr_t.
Change to use the bpfptr_is_kernel() helper.

No functional change.

Signed-off-by: David Laight <david.laight@aculab.com>
---

I'm not at all sure that the pattern:
	urecord = make_bpfptr(attr->func_info, bpfptr_is_kernel(uattr));
isn't bending the rules somewhat - but that is a different issue.

 kernel/bpf/bpf_iter.c |  2 +-
 kernel/bpf/btf.c      |  2 +-
 kernel/bpf/syscall.c  | 12 ++++++------
 kernel/bpf/verifier.c | 10 +++++-----
 4 files changed, 13 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index 0fae79164187..eb2c858dbf81 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -520,7 +520,7 @@  int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
 
 	memset(&linfo, 0, sizeof(union bpf_iter_link_info));
 
-	ulinfo = make_bpfptr(attr->link_create.iter_info, uattr.is_kernel);
+	ulinfo = make_bpfptr(attr->link_create.iter_info, bpfptr_is_kernel(uattr));
 	linfo_len = attr->link_create.iter_info_len;
 	if (bpfptr_is_null(ulinfo) ^ !linfo_len)
 		return -EINVAL;
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 15d71d2986d3..34720a1f586e 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5483,7 +5483,7 @@  static int finalize_log(struct bpf_verifier_log *log, bpfptr_t uattr, u32 uattr_
 
 static struct btf *btf_parse(const union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
 {
-	bpfptr_t btf_data = make_bpfptr(attr->btf, uattr.is_kernel);
+	bpfptr_t btf_data = make_bpfptr(attr->btf, bpfptr_is_kernel(uattr));
 	char __user *log_ubuf = u64_to_user_ptr(attr->btf_log_buf);
 	struct btf_struct_metas *struct_meta_tab;
 	struct btf_verifier_env *env = NULL;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0ed286b8a0f0..ba59fa8d02db 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -93,7 +93,7 @@  int bpf_check_uarg_tail_zero(bpfptr_t uaddr,
 	if (actual_size <= expected_size)
 		return 0;
 
-	if (uaddr.is_kernel)
+	if (bpfptr_is_kernel(uaddr))
 		res = memchr_inv(uaddr.kernel + expected_size, 0,
 				 actual_size - expected_size) == NULL;
 	else
@@ -1482,8 +1482,8 @@  static int map_lookup_elem(union bpf_attr *attr)
 
 static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
 {
-	bpfptr_t ukey = make_bpfptr(attr->key, uattr.is_kernel);
-	bpfptr_t uvalue = make_bpfptr(attr->value, uattr.is_kernel);
+	bpfptr_t ukey = make_bpfptr(attr->key, bpfptr_is_kernel(uattr));
+	bpfptr_t uvalue = make_bpfptr(attr->value, bpfptr_is_kernel(uattr));
 	int ufd = attr->map_fd;
 	struct bpf_map *map;
 	void *key, *value;
@@ -1538,7 +1538,7 @@  static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
 
 static int map_delete_elem(union bpf_attr *attr, bpfptr_t uattr)
 {
-	bpfptr_t ukey = make_bpfptr(attr->key, uattr.is_kernel);
+	bpfptr_t ukey = make_bpfptr(attr->key, bpfptr_is_kernel(uattr));
 	int ufd = attr->map_fd;
 	struct bpf_map *map;
 	struct fd f;
@@ -2670,12 +2670,12 @@  static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
 
 	err = -EFAULT;
 	if (copy_from_bpfptr(prog->insns,
-			     make_bpfptr(attr->insns, uattr.is_kernel),
+			     make_bpfptr(attr->insns, bpfptr_is_kernel(uattr)),
 			     bpf_prog_insn_size(prog)) != 0)
 		goto free_prog_sec;
 	/* copy eBPF program license from user space */
 	if (strncpy_from_bpfptr(license,
-				make_bpfptr(attr->license, uattr.is_kernel),
+				make_bpfptr(attr->license, bpfptr_is_kernel(uattr)),
 				sizeof(license) - 1) < 0)
 		goto free_prog_sec;
 	license[sizeof(license) - 1] = 0;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index af2819d5c8ee..42fea4966175 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15838,7 +15838,7 @@  static int check_btf_func_early(struct bpf_verifier_env *env,
 	prog = env->prog;
 	btf = prog->aux->btf;
 
-	urecord = make_bpfptr(attr->func_info, uattr.is_kernel);
+	urecord = make_bpfptr(attr->func_info, bpfptr_is_kernel(uattr));
 	min_size = min_t(u32, krec_size, urec_size);
 
 	krecord = kvcalloc(nfuncs, krec_size, GFP_KERNEL | __GFP_NOWARN);
@@ -15938,7 +15938,7 @@  static int check_btf_func(struct bpf_verifier_env *env,
 	prog = env->prog;
 	btf = prog->aux->btf;
 
-	urecord = make_bpfptr(attr->func_info, uattr.is_kernel);
+	urecord = make_bpfptr(attr->func_info, bpfptr_is_kernel(uattr));
 
 	krecord = prog->aux->func_info;
 	info_aux = kcalloc(nfuncs, sizeof(*info_aux), GFP_KERNEL | __GFP_NOWARN);
@@ -16036,7 +16036,7 @@  static int check_btf_line(struct bpf_verifier_env *env,
 
 	s = 0;
 	sub = env->subprog_info;
-	ulinfo = make_bpfptr(attr->line_info, uattr.is_kernel);
+	ulinfo = make_bpfptr(attr->line_info, bpfptr_is_kernel(uattr));
 	expected_size = sizeof(struct bpf_line_info);
 	ncopy = min_t(u32, expected_size, rec_size);
 	for (i = 0; i < nr_linfo; i++) {
@@ -16154,7 +16154,7 @@  static int check_core_relo(struct bpf_verifier_env *env,
 	    rec_size % sizeof(u32))
 		return -EINVAL;
 
-	u_core_relo = make_bpfptr(attr->core_relos, uattr.is_kernel);
+	u_core_relo = make_bpfptr(attr->core_relos, bpfptr_is_kernel(uattr));
 	expected_size = sizeof(struct bpf_core_relo);
 	ncopy = min_t(u32, expected_size, rec_size);
 
@@ -20790,7 +20790,7 @@  int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
 		env->insn_aux_data[i].orig_idx = i;
 	env->prog = *prog;
 	env->ops = bpf_verifier_ops[env->prog->type];
-	env->fd_array = make_bpfptr(attr->fd_array, uattr.is_kernel);
+	env->fd_array = make_bpfptr(attr->fd_array, bpfptr_is_kernel(uattr));
 	is_priv = bpf_capable();
 
 	bpf_get_btf_vmlinux();