|
16 | 16 | #include <linux/pid_namespace.h>
|
17 | 17 | #include <linux/proc_ns.h>
|
18 | 18 | #include <linux/security.h>
|
| 19 | +#include <linux/btf_ids.h> |
19 | 20 |
|
20 | 21 | #include "../../lib/kstrtox.h"
|
21 | 22 |
|
@@ -671,6 +672,39 @@ const struct bpf_func_proto bpf_copy_from_user_proto = {
|
671 | 672 | .arg3_type = ARG_ANYTHING,
|
672 | 673 | };
|
673 | 674 |
|
| 675 | +BPF_CALL_5(bpf_copy_from_user_task, void *, dst, u32, size, |
| 676 | + const void __user *, user_ptr, struct task_struct *, tsk, u64, flags) |
| 677 | +{ |
| 678 | + int ret; |
| 679 | + |
| 680 | + /* flags is not used yet */ |
| 681 | + if (unlikely(flags)) |
| 682 | + return -EINVAL; |
| 683 | + |
| 684 | + if (unlikely(!size)) |
| 685 | + return 0; |
| 686 | + |
| 687 | + ret = access_process_vm(tsk, (unsigned long)user_ptr, dst, size, 0); |
| 688 | + if (ret == size) |
| 689 | + return 0; |
| 690 | + |
| 691 | + memset(dst, 0, size); |
| 692 | + /* Return -EFAULT for partial read */ |
| 693 | + return ret < 0 ? ret : -EFAULT; |
| 694 | +} |
| 695 | + |
| 696 | +const struct bpf_func_proto bpf_copy_from_user_task_proto = { |
| 697 | + .func = bpf_copy_from_user_task, |
| 698 | + .gpl_only = false, |
| 699 | + .ret_type = RET_INTEGER, |
| 700 | + .arg1_type = ARG_PTR_TO_UNINIT_MEM, |
| 701 | + .arg2_type = ARG_CONST_SIZE_OR_ZERO, |
| 702 | + .arg3_type = ARG_ANYTHING, |
| 703 | + .arg4_type = ARG_PTR_TO_BTF_ID, |
| 704 | + .arg4_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK], |
| 705 | + .arg5_type = ARG_ANYTHING |
| 706 | +}; |
| 707 | + |
674 | 708 | BPF_CALL_2(bpf_per_cpu_ptr, const void *, ptr, u32, cpu)
|
675 | 709 | {
|
676 | 710 | if (cpu >= nr_cpu_ids)
|
|
0 commit comments