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

* Re: [PATCH bpf-next] bpf: fix error return value in bpf_copy_from_user_dynptr
  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
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-23 20:30 UTC (permalink / raw)
  To: Mykyta Yatsenko
  Cc: bpf, ast, andrii, daniel, kafai, kernel-team, dan.carpenter,
	yatsenko

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Fri, 23 May 2025 19:17:05 +0100 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] bpf: fix error return value in bpf_copy_from_user_dynptr
    https://git.kernel.org/bpf/bpf-next/c/079e5c56a5c4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[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