The currently available bpf_get_current_task returns an unsigned integer which can be used along with BPF_CORE_READ to read data from the task_struct but still cannot be used as an input argument to a helper that accepts an ARG_PTR_TO_BTF_ID of type task_struct. In order to implement this helper a new return type, RET_PTR_TO_BTF_ID, is added. This is similar to RET_PTR_TO_BTF_ID_OR_NULL but does not require checking the nullness of returned pointer.
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -3779,6 +3779,14 @@ union bpf_attr { · 3778 unmodified lines | |||
| 3779 | * 0 on success. | 3779 | * 0 on success. |
| 3780 | * | 3780 | * |
| 3781 | * **-ENOENT** if the bpf_local_storage cannot be found. | 3781 | * **-ENOENT** if the bpf_local_storage cannot be found. |
| 3782 | * | ||
| 3783 | * struct task_struct *bpf_get_current_task_btf(void) | ||
| 3784 | * Description | ||
| 3785 | * Return a BTF pointer to the "current" task. | ||
| 3786 | * This pointer can also be used in helpers that accept an | ||
| 3787 | * *ARG_PTR_TO_BTF_ID* of type *task_struct*. | ||
| 3788 | * Return | ||
| 3789 | * Pointer to the current task. | ||
| 3782 | */ | 3790 | */ |
| 3783 | #define __BPF_FUNC_MAPPER(FN) \ | 3791 | #define __BPF_FUNC_MAPPER(FN) \ |
| 3784 | FN(unspec), \ | 3792 | FN(unspec), \ |
| @@ -3939,6 +3947,7 @@ union bpf_attr { · 154 unmodified lines | |||
| 3939 | FN(redirect_peer), \ | 3947 | FN(redirect_peer), \ |
| 3940 | FN(task_storage_get), \ | 3948 | FN(task_storage_get), \ |
| 3941 | FN(task_storage_delete), \ | 3949 | FN(task_storage_delete), \ |
| 3950 | FN(get_current_task_btf), \ | ||
| 3942 | /* */ | 3951 | /* */ |
| 3943 | 3952 | ||
| 3944 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper | 3953 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |