From: Steffen Klassert <steffen.klassert@secunet.com>
To: YueHaibing <yuehaibing@huawei.com>
Cc: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
<kuba@kernel.org>, <timo.teras@iki.fi>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] xfrm: policy: Fix doulbe free in xfrm_policy_timer
Date: Wed, 25 Mar 2020 13:53:56 +0100 [thread overview]
Message-ID: <20200325125356.GV13121@gauss3.secunet.de> (raw)
In-Reply-To: <20200323073239.59000-1-yuehaibing@huawei.com>
On Mon, Mar 23, 2020 at 03:32:39PM +0800, YueHaibing wrote:
> After xfrm_add_policy add a policy, its ref is 2, then
>
> xfrm_policy_timer
> read_lock
> xp->walk.dead is 0
> ....
> mod_timer()
> xfrm_policy_kill
> policy->walk.dead = 1
> ....
> del_timer(&policy->timer)
> xfrm_pol_put //ref is 1
> xfrm_pol_put //ref is 0
> xfrm_policy_destroy
> call_rcu
> xfrm_pol_hold //ref is 1
> read_unlock
> xfrm_pol_put //ref is 0
> xfrm_policy_destroy
> call_rcu
>
> xfrm_policy_destroy is called twice, which may leads to
> double free.
>
> Call Trace:
> RIP: 0010:refcount_warn_saturate+0x161/0x210
> ...
> xfrm_policy_timer+0x522/0x600
> call_timer_fn+0x1b3/0x5e0
> ? __xfrm_decode_session+0x2990/0x2990
> ? msleep+0xb0/0xb0
> ? _raw_spin_unlock_irq+0x24/0x40
> ? __xfrm_decode_session+0x2990/0x2990
> ? __xfrm_decode_session+0x2990/0x2990
> run_timer_softirq+0x5c5/0x10e0
>
> Fix this by use write_lock_bh in xfrm_policy_kill.
>
> Fixes: ea2dea9dacc2 ("xfrm: remove policy lock when accessing policy->walk.dead")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> v3: Only lock 'policy->walk.dead'
> v2: Fix typo 'write_lock_bh'--> 'write_unlock_bh' while unlocking
> ---
Applied, thanks everyone!
prev parent reply other threads:[~2020-03-25 12:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-18 3:48 [PATCH] xfrm: policy: Fix doulbe free in xfrm_policy_timer YueHaibing
2020-03-23 1:41 ` [PATCH v2] " YueHaibing
2020-03-23 6:29 ` Herbert Xu
2020-03-23 7:04 ` Yuehaibing
2020-03-23 6:53 ` Timo Teras
2020-03-23 7:21 ` Yuehaibing
2020-03-23 7:56 ` Timo Teras
2020-03-23 7:32 ` [PATCH v3] " YueHaibing
2020-03-23 8:00 ` Timo Teras
2020-03-23 21:44 ` Herbert Xu
2020-03-25 12:53 ` Steffen Klassert [this message]
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=20200325125356.GV13121@gauss3.secunet.de \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=timo.teras@iki.fi \
--cc=yuehaibing@huawei.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