Skip to content

Commit 079e5c5

Browse files
mykyta5anakryiko
authored andcommitted
bpf: Fix error return value in bpf_copy_from_user_dynptr
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: a498ee7 ("bpf: Implement dynptr copy kfuncs") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Mykyta Yatsenko <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bfccacd commit 079e5c5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,8 +3555,12 @@ static __always_inline int copy_user_data_sleepable(void *dst, const void *unsaf
35553555
{
35563556
int ret;
35573557

3558-
if (!tsk) /* Read from the current task */
3559-
return copy_from_user(dst, (const void __user *)unsafe_src, size);
3558+
if (!tsk) { /* Read from the current task */
3559+
ret = copy_from_user(dst, (const void __user *)unsafe_src, size);
3560+
if (ret)
3561+
return -EFAULT;
3562+
return 0;
3563+
}
35603564

35613565
ret = access_process_vm(tsk, (unsigned long)unsafe_src, dst, size, 0);
35623566
if (ret != size)

0 commit comments

Comments
 (0)