Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5048168pxu; Wed, 21 Oct 2020 11:51:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfXR/DDTYlc7/DaTKSp29jDLJKys6D2ogNCYC2iDr7yS6M+I4vq1O071mfxbkWMtLAlrAt X-Received: by 2002:a05:6402:1684:: with SMTP id a4mr4603835edv.319.1603306259978; Wed, 21 Oct 2020 11:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603306259; cv=none; d=google.com; s=arc-20160816; b=qR3xkuAuavKQFrjyj1zDuRQUPQDqtg3ncqI7dpdK+IUKj6CSwy1ZRQXRK4JjGEEQuM UJH9A3JkLxt0ED0D5kUaqa9uOEvKbY+alFjxcjZJXWA2klsSR/ybCwF0U+WReninWX7Q hoNbKTuzN6+lK06fUOY5wfVZwsGw0trbZHjSptZS8tSgNO+fVz3FI81c/pvccu0DBJ3t mWsQJ2e3BSOXfBuSetWfNsopKa9egOIVXxe8Zn8/h19xA9MrGjc3/pdX4u255vi5nLK3 Jik6S75RI+zNAOSgJomxPerbVhExHDGSVBZCqZPuBB41KTwg5UyRKH0GorvuLrMZ67oU Bn7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=5T5Mek9nL4Qm76UNkNsEsb8fDlglSZIN350OQFrvF5U=; b=uJB8i0aRX+nu9HCYL8Crr0hHUKRRpNlpybHlBAm3JWLOz1TcwiskqAmYfXqetMyu/c mpzNPZeVGpJofBynd6yFbj4WBuN3Db1FJtz8xCYX+dQkDhTrGNoJOwSR0revX2x7XY/M zevZqD93BX0TAdct0L7smOy/pVcVtJxg3BDRDiX0gxBVUWPzY3Phxc/ymiJzLg4i6SrH UTvQVtKPa1LzKSTcmCxB93ooEdqzcooJTIur4kLH+iAh+0suaBRI4KIcW9w/5dH6tL6+ 6tpNL0k5j96vme1+/YWGJIx0llIXsghExbooohqfsLHLW7uhoI9fwONeWNZXRsPW61Rc HhMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c9si1966782edl.424.2020.10.21.11.50.37; Wed, 21 Oct 2020 11:50:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437128AbgJUHMd (ORCPT + 99 others); Wed, 21 Oct 2020 03:12:33 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:35086 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391498AbgJUHMd (ORCPT ); Wed, 21 Oct 2020 03:12:33 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1kV8II-0002e1-Es; Wed, 21 Oct 2020 18:12:23 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Wed, 21 Oct 2020 18:12:22 +1100 Date: Wed, 21 Oct 2020 18:12:22 +1100 From: Herbert Xu To: Zhuoliang Zhang Cc: Steffen Klassert , "David S . Miller" , Jakub Kicinski , Matthias Brugger , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Subject: Re: [PATCH] net: xfrm: fix a race condition during allocing spi Message-ID: <20201021071222.GA11474@gondor.apana.org.au> References: <20201020081800.29454-1-zhuoliang.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201020081800.29454-1-zhuoliang.zhang@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 20, 2020 at 04:18:00PM +0800, Zhuoliang Zhang wrote: > From: zhuoliang zhang > > we found that the following race condition exists in > xfrm_alloc_userspi flow: > > user thread state_hash_work thread > ---- ---- > xfrm_alloc_userspi() > __find_acq_core() > /*alloc new xfrm_state:x*/ > xfrm_state_alloc() > /*schedule state_hash_work thread*/ > xfrm_hash_grow_check() xfrm_hash_resize() > xfrm_alloc_spi /*hold lock*/ > x->id.spi = htonl(spi) spin_lock_bh(&net->xfrm.xfrm_state_lock) > /*waiting lock release*/ xfrm_hash_transfer() > spin_lock_bh(&net->xfrm.xfrm_state_lock) /*add x into hlist:net->xfrm.state_byspi*/ > hlist_add_head_rcu(&x->byspi) > spin_unlock_bh(&net->xfrm.xfrm_state_lock) > > /*add x into hlist:net->xfrm.state_byspi 2 times*/ > hlist_add_head_rcu(&x->byspi) > > So the same xfrm_stame (x) is added into the same list_hash > (net->xfrm.state_byspi)2 times that makes the list_hash become > a inifite loop. Your explanation makes no sense. Prior to obtaining the spin lock on the LHS, the state x hasn't been added to thte table yet. So how can the RHS be transferring it? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt