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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 5647AC43603 for ; Fri, 13 Dec 2019 10:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E3312077B for ; Fri, 13 Dec 2019 10:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725980AbfLMKZX (ORCPT ); Fri, 13 Dec 2019 05:25:23 -0500 Received: from Chamillionaire.breakpoint.cc ([193.142.43.52]:39274 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbfLMKZW (ORCPT ); Fri, 13 Dec 2019 05:25:22 -0500 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1ifi8G-0002dj-1t; Fri, 13 Dec 2019 11:25:12 +0100 Date: Fri, 13 Dec 2019 11:25:12 +0100 From: Florian Westphal To: Steffen Klassert Cc: Josh Hunt , herbert@gondor.apana.org.au, David Miller , netdev , Florian Westphal Subject: Re: crash in __xfrm_state_lookup on 4.19 LTS Message-ID: <20191213102512.GP795@breakpoint.cc> References: <0b3ab776-2b8b-1725-d36e-70af66c138da@akamai.com> <20191212132132.GL8621@gauss3.secunet.de> <20191213072144.GC26283@gauss3.secunet.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191213072144.GC26283@gauss3.secunet.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Steffen Klassert wrote: > > index f3423562d933..c3d7df1387c8 100644 > > --- a/net/xfrm/xfrm_state.c > > +++ b/net/xfrm/xfrm_state.c > > @@ -1730,9 +1730,9 @@ xfrm_state_lookup(struct net *net, u32 mark, const > > xfrm_address_t *daddr, __be32 > > { > > struct xfrm_state *x; > > > > - rcu_read_lock(); > > + spin_lock_bh(&net->xfrm.xfrm_state_lock); > > x = __xfrm_state_lookup(net, mark, daddr, spi, proto, family); > > - rcu_read_unlock(); > > + spin_unlock_bh(&net->xfrm.xfrm_state_lock); > > return x; > > } > > While that could fix it, it adds a global list lock > to the packet path and reverts: > > commit c2f672fc94642bae96821a393f342edcfa9794a6 > xfrm: state lookup can be lockless > > I've Cced Florian who did that change. > > I thought to do a rcu_read_lock_bh(), but in between I think > it would make the problem just less likely to occur. > > We destroy the states with a workqueue by doing schedule_work(). > I think we should better use call_rcu to make sure that a > rcu grace period has elapsed before the states are destroyed. xfrm_state_gc_task calls synchronize_rcu after stealing the gc list and before destroying those states, so I don't think this is a problem.