Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp181399ybh; Tue, 17 Mar 2020 20:52:31 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsx1Jds/ASk7g38gbzDd9HZqWYETAoU37gTmVKHnB8Ob0S8r/0H/ucSMzgmjuGT5MWL2Vqx X-Received: by 2002:aca:496:: with SMTP id 144mr1741652oie.121.1584503549769; Tue, 17 Mar 2020 20:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584503549; cv=none; d=google.com; s=arc-20160816; b=IlTvwW4nQmnUUA8HoZ60d+DERZYUPS3dVoIrTFj5EGZvF8JtIAJRE/iRAUGDF7ImGT EG8FH46VZzvsi048lFPQU13AHGkgTnYDiQxmpF38GIUZ9Zat4CxT8LonemKJtvR5dT7l 0R6RjEcy1dY3NhjmBTMXoZ1uq93xOIht1pIynUpx5tzpdT8SHdbnVxXIlv1wEqdg2dI5 cbgroUgmIzI9kxWCeUMhUnPvcaMkESuoECgoLq1fneAIa4+hvVjinF9R36J9IF4Qg46o TFrDY0PfsyGWP9U211yiMdAtXn6VEk7X9BTSBUqN+l0NDFabMZLqkrsd5Pkh4QO3w1Jp VMWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=MqdD3Zusp0VOkxdXIDqyaYHQb8lh5z+Ul2MIMftRTxE=; b=yYUeY8xDK3qPJT+jPzJxEw7fWJIFlZD0nHM5tHGDJWAXYpZoulDFJQuQ+jJhkps/c7 unC14rvKmyBJKI1BMnXLrcCF0grWm6Y2Mayoj47TwviHUzJdVPgax2disGyVdzD79cPx FW6lSaFKymD7g0hLCSaJSxxfaWolH/kza2f7bItVJmj6+RKAIoVzGjNYWPBU2lSeDodJ 9PK0dfr9SNkr/6l7EqfY9MwgwUkVmZ7/r23tdM1cnJXm0rB1WqJY8kLgdePIMhZtrcaj B5gOO+1+zDWNlWFpGDyFlbad6IStOQIp/E4XFx2OsnN5WwomApQP1b6YDt2nkYV9t2Qp YV1Q== 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 w15si3032008otl.282.2020.03.17.20.52.17; Tue, 17 Mar 2020 20:52:29 -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 S1726871AbgCRDuX (ORCPT + 99 others); Tue, 17 Mar 2020 23:50:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:11657 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726229AbgCRDuX (ORCPT ); Tue, 17 Mar 2020 23:50:23 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0C22517E85C3098C7E5D; Wed, 18 Mar 2020 11:50:21 +0800 (CST) Received: from localhost (10.173.223.234) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 18 Mar 2020 11:50:11 +0800 From: YueHaibing To: , , , , CC: , , YueHaibing Subject: [PATCH] xfrm: policy: Fix doulbe free in xfrm_policy_timer Date: Wed, 18 Mar 2020 11:48:39 +0800 Message-ID: <20200318034839.57996-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.173.223.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 add write_lock_bh in xfrm_policy_kill. Fixes: ea2dea9dacc2 ("xfrm: remove policy lock when accessing policy->walk.dead") Signed-off-by: YueHaibing --- 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..ae0689174bbf 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -434,6 +434,7 @@ EXPORT_SYMBOL(xfrm_policy_destroy); static void xfrm_policy_kill(struct xfrm_policy *policy) { + write_lock_bh(&policy->lock); policy->walk.dead = 1; atomic_inc(&policy->genid); @@ -445,6 +446,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy) if (del_timer(&policy->timer)) xfrm_pol_put(policy); + write_lock_bh(&policy->lock); xfrm_pol_put(policy); } -- 2.17.1