Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3449311ybb; Mon, 23 Mar 2020 01:01:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvcumqUaG8tE85oCg7+u83BbvXryLKGJ4NLRQOVteJOab4F7UyXGNjDYHlI6V4B1CPbW5+U X-Received: by 2002:a05:6830:4b1:: with SMTP id l17mr16960985otd.275.1584950460801; Mon, 23 Mar 2020 01:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584950460; cv=none; d=google.com; s=arc-20160816; b=NfG4Nju3Ok7fryoKgwvZF3bzMynuIdAvNu2JL8b9mpx8bThoSGLwKnYn5lunJevllQ 1/7yplSRb0o4tojslCPsIMiHFVVADjJocgirBrscmjxDf5eYTbmRicmO5/asXG8UDGFG Fl9DJEwmZW57Q0MvoJQI9aY9hUAjJsvpA/YM6BfhoNA8/+qz9Lh0JtYdqPxWxjeIBzMN 8OlipMVkSD138oLvEqPemYWWhxR+QKuDE9+OaoRlpxytkC0Tqf55M/eWsqbHKCIVfQqp wBrjuKIi/Z9KlEVb23KbXV5T4h8lmmqKkYICUKG0rFKwIH0b1+6VC+QGY9CCs5FrlvY9 ATKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=mdGjoyR5bD1yA+4QjjCAbTMg9SfKd/DSOBrkZhbd7N8=; b=ao3DdlsVx4yU3dMRvRanff/1Tusn38+cDi5OVF4xa0OLQQ0mCy5KRL6WXYp6S9bODA LaUjaDAPO0sJG5GLv3L+Huq3KLYBIr8TI1CGJkqqOji8g9rFTVflf/9nBtszO/rMbrr9 UeWiWvMEdk1NZ/0/3GHgfGTtnuecFnOG3gG9vawfNFgB62ULrXgh1pbqV8vWBfelqnpA MEROkzi4kSt1/2zjZNyCoIYjTs1xbnzPYbQPQ218r2PScK9FDwAPcOT1+FfTcxopp7VS 41WM3vNdGr3kuDTH+omnpkFrZAwDv9vjqXIaqvuHX2jqlo0ZlCjz02zibJxDA0dAx8YX gb0Q== 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 l21si7091119otd.20.2020.03.23.01.00.47; Mon, 23 Mar 2020 01:01:00 -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 S1727497AbgCWIA3 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 23 Mar 2020 04:00:29 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43161 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727422AbgCWIA2 (ORCPT ); Mon, 23 Mar 2020 04:00:28 -0400 Received: by mail-lj1-f193.google.com with SMTP id g27so4611510ljn.10; Mon, 23 Mar 2020 01:00:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nn3jGhr8uNWeITwAtUjp7FuShYd1eeyyePwVyNZWbwQ=; b=KdyhA4LxbptrlfkY5fB6ViEDVaVfexWZnz01pi3THkzPXjPW5Cghfav7lJhH02d8zj HMDODST5Zj6gNL87ZlJivpxzHHn1SCnx7G2iv1zggZeHgXL7L4ypgzfU0Lt4jxUuxnbl 5TankKqQtyHL3QrEIrYWYvwg1UfO6OQuuo3eYxhqBWOifsciMPrtRFuXVSIeVC8NquLx J1w9jilWO+O0fXqw9wdR2PKRVeuH72ljendUI53LMi5fU40x3GXfqRW9z98vxQC7r3bo HaBTDMQFyrr9vOVj3+yG+Gfnl/ImR8oydjtfD+wwjpHmuFJxRPYDuly2txuD54W3MR5/ oxFg== X-Gm-Message-State: ANhLgQ3S0aMEmitY/3xVJpehW3d64oMzq+Up6Ui0pEZhw6jgrbEp65Xb zBAyvwkDlsZ+XhjEKzoSfgA= X-Received: by 2002:a2e:9852:: with SMTP id e18mr12883378ljj.249.1584950425030; Mon, 23 Mar 2020 01:00:25 -0700 (PDT) Received: from vostro.wlan (dty2hzyyyyyyyyyyyyx9y-3.rev.dnainternet.fi. [2001:14ba:802c:6a00::4fa]) by smtp.gmail.com with ESMTPSA id 15sm7799287lfr.17.2020.03.23.01.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 01:00:24 -0700 (PDT) Date: Mon, 23 Mar 2020 10:00:21 +0200 From: Timo Teras To: YueHaibing Cc: , , , , , Subject: Re: [PATCH v3] xfrm: policy: Fix doulbe free in xfrm_policy_timer Message-ID: <20200323100021.05d68204@vostro.wlan> In-Reply-To: <20200323073239.59000-1-yuehaibing@huawei.com> References: <20200318034839.57996-1-yuehaibing@huawei.com> <20200323073239.59000-1-yuehaibing@huawei.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-alpine-linux-musl) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Mar 2020 15:32:39 +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 Acked-by: Timo Teräs > --- > 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(+) > > diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c > index dbda08ec566e..8a4af86a285e 100644 > --- a/net/xfrm/xfrm_policy.c > +++ b/net/xfrm/xfrm_policy.c > @@ -434,7 +434,9 @@ EXPORT_SYMBOL(xfrm_policy_destroy); > > static void xfrm_policy_kill(struct xfrm_policy *policy) > { > + write_lock_bh(&policy->lock); > policy->walk.dead = 1; > + write_unlock_bh(&policy->lock); > > atomic_inc(&policy->genid); > > -- > 2.17.1 > >