public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: fix error return value in bpf_copy_from_user_dynptr
@ 2025-05-23 18:17 Mykyta Yatsenko
  2025-05-23 20:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Mykyta Yatsenko @ 2025-05-23 18:17 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, dan.carpenter
  Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

On error, copy_from_user returns number of bytes not copied to
destination, but current implementation of copy_user_data_sleepable does
not handle that correctly and returns it as error value, which may
confuse user, expecting meaningful negative error value.

Fixes: a498ee7576de ("bpf: Implement dynptr copy kfuncs")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/aDCbQq99EfNDI8xr@stanley.mountain/
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
 kernel/trace/bpf_trace.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b0eb721fcfb5..6876985ba527 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3553,8 +3553,12 @@ static __always_inline int copy_user_data_sleepable(void *dst, const void *unsaf
 {
 	int ret;
 
-	if (!tsk) /* Read from the current task */
-		return copy_from_user(dst, (const void __user *)unsafe_src, size);
+	if (!tsk) {/* Read from the current task */
+		ret = copy_from_user(dst, (const void __user *)unsafe_src, size);
+		if (ret)
+			return -EFAULT;
+		return 0;
+	}
 
 	ret = access_process_vm(tsk, (unsigned long)unsafe_src, dst, size, 0);
 	if (ret != size)
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-23 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23 18:17 [PATCH bpf-next] bpf: fix error return value in bpf_copy_from_user_dynptr Mykyta Yatsenko
2025-05-23 20:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox