From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [PATCH net] net/packet: fix a race in packet_bind() and packet_notifier() Date: Tue, 28 Nov 2017 07:13:01 -0800 Message-ID: <1511881981.16595.13.camel@gmail.com> References: <1511841652.16595.11.camel@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Cc: David Miller , netdev , Francesco Ruggeri , Willem de Bruijn To: Francesco Ruggeri Return-path: Received: from mail-pl0-f67.google.com ([209.85.160.67]:45427 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752050AbdK1PNE (ORCPT ); Tue, 28 Nov 2017 10:13:04 -0500 Received: by mail-pl0-f67.google.com with SMTP id f6so69509pln.12 for ; Tue, 28 Nov 2017 07:13:04 -0800 (PST) In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: On Tue, 2017-11-28 at 02:23 -0800, Francesco Ruggeri wrote: > On Mon, Nov 27, 2017 at 8:00 PM, Eric Dumazet > wrote: > > From: Eric Dumazet > > > > ... > > +++ b/net/packet/af_packet.c > > @@ -336,7 +336,7 @@ static void register_prot_hook(struct sock *sk) > >  { > >         struct packet_sock *po = pkt_sk(sk); > > > > -       if (!po->running) { > > +       if (!po->running && !po->frozen) { > > Would it make sense to move the check for po->frozen to > packet_notifier(NETDEV_UP)? > As far as I can tell that is the only case today that can cause this > race condition, and if new cases come up in the future an error code > may be required rather than silently turning register_prot_hook() > into > a noop. > Otherwise it looks fine to me. > Whatever works for me is fine, I have no strong opinion on this. Note that frozen is only set in the case we know that register_prot_hook() is going to be called by us.