Re: [PATCH bpf-next v4 1/4] bpf: add BPF_CGROUP_INET_SOCK_RELEASE hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/7/20 1:42 AM, Andrii Nakryiko wrote:
On Mon, Jul 6, 2020 at 4:02 PM Stanislav Fomichev <sdf@xxxxxxxxxx> wrote:

Implement BPF_CGROUP_INET_SOCK_RELEASE hook that triggers
on inet socket release. It triggers only for userspace
sockets, the same semantics as existing BPF_CGROUP_INET_SOCK_CREATE.

The only questionable part here is the sock->sk check
in the inet_release. Looking at the places where we
do 'sock->sk = NULL', I don't understand how it can race
with inet_release and why the check is there (it's been
there since the initial git import). Otherwise, the
change itself is pretty simple, we add a BPF hook
to the inet_release and avoid calling it for kernel
sockets.

Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
---
  include/linux/bpf-cgroup.h | 4 ++++
  include/uapi/linux/bpf.h   | 1 +
  kernel/bpf/syscall.c       | 3 +++
  net/core/filter.c          | 1 +
  net/ipv4/af_inet.c         | 3 +++
  5 files changed, 12 insertions(+)


Looks good overall, but I have no idea about sock->sk NULL case.

+1, looks good & very useful hook. For the sock->sk NULL case here's a related
discussion on why it's needed [0].

  [0] https://lore.kernel.org/netdev/20190221221356.173485-1-ebiggers@xxxxxxxxxx/

Acked-by: Andrii Nakryiko <andriin@xxxxxx>

diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index c66c545e161a..2c6f26670acc 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h

[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux