[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250703163700.677628-1-chen.dylane@linux.dev>
Date: Fri, 4 Jul 2025 00:37:00 +0800
From: Tao Chen <chen.dylane@...ux.dev>
To: ast@...nel.org,
daniel@...earbox.net,
john.fastabend@...il.com,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org
Cc: bpf@...r.kernel.org,
linux-kernel@...r.kernel.org,
Tao Chen <chen.dylane@...ux.dev>
Subject: [PATCH bpf-next v2] bpf: Clean code with bpf_copy_to_user
No logic change, just use bpf_copy_to_user to clean code.
Signed-off-by: Tao Chen <chen.dylane@...ux.dev>
---
kernel/bpf/syscall.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
Change list:
v1 -> v2:
- do not directly return when handle err ENOSPC.(Yonghong)
v1:
https://lore.kernel.org/bpf/20250703124336.672416-1-chen.dylane@linux.dev
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e6eea594f1c..6ea3a8e3f7e 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5208,21 +5208,10 @@ static int bpf_task_fd_query_copy(const union bpf_attr *attr,
if (put_user(zero, ubuf))
return -EFAULT;
- } else if (input_len >= len + 1) {
- /* ubuf can hold the string with NULL terminator */
- if (copy_to_user(ubuf, buf, len + 1))
- return -EFAULT;
} else {
- /* ubuf cannot hold the string with NULL terminator,
- * do a partial copy with NULL terminator.
- */
- char zero = '\0';
-
- err = -ENOSPC;
- if (copy_to_user(ubuf, buf, input_len - 1))
- return -EFAULT;
- if (put_user(zero, ubuf + input_len - 1))
- return -EFAULT;
+ err = bpf_copy_to_user(ubuf, buf, input_len, len);
+ if (err == -EFAULT)
+ return err;
}
}
--
2.48.1
Powered by blists - more mailing lists