Skip to content

Commit 3413bc0

Browse files
Tao ChenAlexei Starovoitov
authored andcommitted
bpf: Clean code with bpf_copy_to_user()
No logic change, use bpf_copy_to_user() to clean code. Signed-off-by: Tao Chen <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 192e3aa commit 3413bc0

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

kernel/bpf/syscall.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,21 +5344,10 @@ static int bpf_task_fd_query_copy(const union bpf_attr *attr,
53445344

53455345
if (put_user(zero, ubuf))
53465346
return -EFAULT;
5347-
} else if (input_len >= len + 1) {
5348-
/* ubuf can hold the string with NULL terminator */
5349-
if (copy_to_user(ubuf, buf, len + 1))
5350-
return -EFAULT;
53515347
} else {
5352-
/* ubuf cannot hold the string with NULL terminator,
5353-
* do a partial copy with NULL terminator.
5354-
*/
5355-
char zero = '\0';
5356-
5357-
err = -ENOSPC;
5358-
if (copy_to_user(ubuf, buf, input_len - 1))
5359-
return -EFAULT;
5360-
if (put_user(zero, ubuf + input_len - 1))
5361-
return -EFAULT;
5348+
err = bpf_copy_to_user(ubuf, buf, input_len, len);
5349+
if (err == -EFAULT)
5350+
return err;
53625351
}
53635352
}
53645353

0 commit comments

Comments
 (0)