Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4155339ybb; Mon, 23 Mar 2020 14:47:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvf8k7GVXFzVbSaTPFYusqYZY4qjlCktuAjYAMpLDX6oCPmRDxm1/wXnUIgZ24LfTa6MXNz X-Received: by 2002:a9d:12ce:: with SMTP id g72mr4342109otg.350.1585000027078; Mon, 23 Mar 2020 14:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585000027; cv=none; d=google.com; s=arc-20160816; b=ysHrkEV7UXYPORclqlPjO/rUIY89RsPNnwUF/woogsVk8eW8Kyw3jlT9jgEB4DIrUe m6TriiefvTSDkAupR62s683JkSC7qVSvU07pM26oj3zEAjzbm/9BQGrY8LPsd1H7Qji9 LdvCdeMhs3Ca15cUNtvjN5+uVYwvQpnmzPzIMiSas0Gys90oTZ+gdnzJmUtJmi8MZrUf 33J+PRxtsl6P3UeOS+N2+V4y4LFhsedzw6bc7OZZDa7Zh3U1OZoFjPgXt5nPoVswKWCE IsjSLSoA90B4zWy1B/CG2+oxlaZUMac4XLGNWraFF1uM+MAPcZLkciBVNszBF9oI8hdD TB7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=RmiQFqf1WCu3WKwdn3uCCK+rDG2GhdC2N9S9V0krKhk=; b=syfMLBQvjyPPvQNsDjgSJVOCJDE98itbwNs2pcX/fQeHVVkN4aODqPPQQIjrF2g9Rz Xp3ZAvcaV7CTtS10dgq6zaW60PbtrYcIT0zlmhX53EBIFwY0yFtJsaIighvHpDFexz0l tGNJYWs7w78YSpOS6laMrBnFYKT+lPPwuXEFwt84q15lbXOhuqw2cxe6GuY3O0jqYj2Q v7V7SmCxNKExlgJaTDkU+0gsllh/gwrD3siWhTyLc7kLoUTn1Egx8Y+yVUXRhMnouq5i D+lxl7WDoI8d2nnbyWzIVWgoKTHbmW5Oh1u8ASyp/pliYaaiyfriPBqRZm/yihnTSNAt 0YRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si8058826oig.212.2020.03.23.14.46.54; Mon, 23 Mar 2020 14:47:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727054AbgCWVpb (ORCPT + 99 others); Mon, 23 Mar 2020 17:45:31 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:32922 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgCWVpb (ORCPT ); Mon, 23 Mar 2020 17:45:31 -0400 Received: from gwarestrin.me.apana.org.au ([192.168.0.7] helo=gwarestrin.arnor.me.apana.org.au) by fornost.hmeau.com with smtp (Exim 4.89 #2 (Debian)) id 1jGUsV-00061D-Eg; Tue, 24 Mar 2020 08:45:00 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Tue, 24 Mar 2020 08:44:59 +1100 Date: Tue, 24 Mar 2020 08:44:59 +1100 From: Herbert Xu To: YueHaibing Cc: steffen.klassert@secunet.com, 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 Message-ID: <20200323214459.GA9720@gondor.apana.org.au> References: <20200318034839.57996-1-yuehaibing@huawei.com> <20200323073239.59000-1-yuehaibing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323073239.59000-1-yuehaibing@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > v3: Only lock 'policy->walk.dead' > v2: Fix typo 'write_lock_bh'--> 'write_unlock_bh' while unlocking > --- > net/xfrm/xfrm_policy.c | 2 ++ > 1 file changed, 2 insertions(+) Acked-by: Herbert Xu Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt