From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A3CC433E0 for ; Tue, 7 Jul 2020 23:56:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 241A92073E for ; Tue, 7 Jul 2020 23:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729325AbgGGX4m (ORCPT ); Tue, 7 Jul 2020 19:56:42 -0400 Received: from www62.your-server.de ([213.133.104.62]:44540 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729316AbgGGX4m (ORCPT ); Tue, 7 Jul 2020 19:56:42 -0400 Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jsxRs-0008LV-4Z; Wed, 08 Jul 2020 01:56:28 +0200 Received: from [178.196.57.75] (helo=pc-9.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jsxRr-000HTb-V0; Wed, 08 Jul 2020 01:56:27 +0200 Subject: Re: [PATCH bpf-next v4 1/4] bpf: add BPF_CGROUP_INET_SOCK_RELEASE hook To: Stanislav Fomichev Cc: Andrii Nakryiko , Networking , bpf , "David S. Miller" , Alexei Starovoitov References: <20200706230128.4073544-1-sdf@google.com> <20200706230128.4073544-2-sdf@google.com> <073ac0af-5de7-0a61-4e11-e4ca292f6456@iogearbox.net> From: Daniel Borkmann Message-ID: <0f640b14-907a-7e44-9499-6c0e7f92358c@iogearbox.net> Date: Wed, 8 Jul 2020 01:56:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.3/25866/Tue Jul 7 15:47:52 2020) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 7/8/20 1:43 AM, Stanislav Fomichev wrote: > On Tue, Jul 7, 2020 at 2:42 PM Daniel Borkmann wrote: >> >> On 7/7/20 1:42 AM, Andrii Nakryiko wrote: >>> On Mon, Jul 6, 2020 at 4:02 PM Stanislav Fomichev 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 >>>> --- >>>> 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]. > Thanks for the pointer! I'll resend a v5 with s/sock/sock_create/ you > mentioned and will clean up the commit description a bit. Already fixed up the selftest and a typo in the commit desc there & applied it. Let me know if you prefer a respin though and I can toss it taking the respin which would work just as well. :) Thanks, Daniel