Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: zhuoliang.zhang <zhuoliang.zhang@mediatek.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	wsd_upstream@mediatek.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] net: xfrm: fix a race condition during allocing spi
Date: Thu, 22 Oct 2020 13:53:15 +0800	[thread overview]
Message-ID: <1603345995.13237.2.camel@mbjsdccf07> (raw)
In-Reply-To: <20201021071222.GA11474@gondor.apana.org.au>

hi maintainer:

there are 2 related hash lists : net->xfrm.state_bydst and
net->xfrm.state_byspi:

1. a new state x is alloced in xfrm_state_alloc() and added into the
bydst hlist in  __find_acq_core() on the LHS;
2. on the RHS, state_hash_work thread travels the old bydst and tranfers
every xfrm_state (include x) to the new bydst hlist and new byspi hlist;
3. user thread on the LHS gets the lock and adds x to the new byspi
hlist again.

thanks




On Wed, 2020-10-21 at 18:12 +1100, Herbert Xu wrote:
> On Tue, Oct 20, 2020 at 04:18:00PM +0800, Zhuoliang Zhang wrote:
> > From: zhuoliang zhang <zhuoliang.zhang@mediatek.com>
> > 
> > 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,

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-10-22  6:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20  8:18 [PATCH] net: xfrm: fix a race condition during allocing spi Zhuoliang Zhang
2020-10-21  7:12 ` Herbert Xu
2020-10-22  5:53   ` zhuoliang.zhang [this message]
2020-10-22  6:48     ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1603345995.13237.2.camel@mbjsdccf07 \
    --to=zhuoliang.zhang@mediatek.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox