Merge branch 'current_pid_tgid-for-all-prog-types'
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 19 Mar 2024 21:21:55 +0000 (14:21 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 19 Mar 2024 21:27:01 +0000 (14:27 -0700)
commit437ffcb0bf97361e5c4062043309832f4724d1a8
tree334907acabeb9fe6a105708b078f8b54f68f9e6e
parent1a4a0cb7985f921548f1a7ac17686afbefe67f87
parent4c195ee4865d57786b3a63018d489b8a07877354
Merge branch 'current_pid_tgid-for-all-prog-types'

Yonghong Song says:

====================
current_pid_tgid() for all prog types

Currently bpf_get_current_pid_tgid() is allowed in tracing, cgroup
and sk_msg progs while bpf_get_ns_current_pid_tgid() is only allowed
in tracing progs.

We have an internal use case where for an application running
in a container (with pid namespace), user wants to get
the pid associated with the pid namespace in a cgroup bpf
program. Besides cgroup, the only prog type, supporting
bpf_get_current_pid_tgid() but not bpf_get_ns_current_pid_tgid(),
is sk_msg.

But actually both bpf_get_current_pid_tgid() and
bpf_get_ns_current_pid_tgid() helpers do not reveal kernel internal
data and there is no reason that they cannot be used in other
program types. This patch just did this and enabled these
two helpers for all program types.

Patch 1 added the kernel support and patches 2-5 added
the test for cgroup and sk_msg.

Change logs:
  v1 -> v2:
    - allow bpf_get_[ns_]current_pid_tgid() for all prog types.
    - for network related selftests, using netns.
====================

Link: https://lore.kernel.org/r/20240315184849.2974556-1-yonghong.song@linux.dev
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>