Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2175000iof; Tue, 7 Jun 2022 22:12:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIWiFqu+LUs7APDeXaSgrZlP+RI5wkiwVY7IhLS5FnEjVr/MU8wNfkEpLswlRxCM3uE+hk X-Received: by 2002:a05:6a00:23c4:b0:51c:5e8:e8a9 with SMTP id g4-20020a056a0023c400b0051c05e8e8a9mr17370328pfc.62.1654665153062; Tue, 07 Jun 2022 22:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654665153; cv=none; d=google.com; s=arc-20160816; b=MKqg9AaYtXqDneZhQrzMpmwdzMew+sDzUgkV7+R6UMTMrdO+SuDW/MgczpsadwhX/C k6ctHV/Hx3LVyEzHuiqQy9YfbBl7quN8Dum0YTLmqtKonlt/pAvAWo48FeJzuzfgCJFX SveU1w6Z2o1u2BdAa3CbktUQcsqXk4fMcKKHlxVGSmoRPzZ0dKP0prTyXBPNm8BGLcnW 30mVC2WgxpAT4qCHorZlAqXZU9jL2t7a+aPFQO/m91I2eqSzi58n9sspncIw9rYR2Ogl z5aCUHkFBkS5kFtyjRrJMFs0bnOvo0qM65I5BKwjsAb/DKXXjWM2tDy4GpknvTf9MJV4 wnNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=h02JHix15unc9BetQPnLtcjzv0m4U4uAih2JlakU1UU=; b=TIJGu3w5NXqw8Lw+XLZWJw7lvgH6NCKUb1PJDATYlwgs/I7RvriUhg91yRNVCJ4KDu nCJ5G001H356/UC7/OGUNmxffo6yhkBlOsqpsmAjuMh0K1MKgUOjof6elyYTeiDve485 2rF3mG62sQBLYRUbVFf76FA0wg/jUgb6GV/XOSesRY+lSSMYqXz6yhLPP820qQl/F4tQ ipmtY9+mWKsYPPoM5RVcBXQaB9eicH+gFFLC5RyFlJnxnY7xFRUcgzxa5wb/ewPHbVtz 3eLqSnCNGWi0ZAGgw5RWYGJJYI2bycs4uFrxrRme4ptDv8xHpikLxKL6Jrx7+b5FiJc0 seLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ruc.edu.cn Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r30-20020a63515e000000b003c1f456f0fcsi27551772pgl.879.2022.06.07.22.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:12:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ruc.edu.cn Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 782A840CDCA; Tue, 7 Jun 2022 21:42:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236694AbiFGQQs (ORCPT + 99 others); Tue, 7 Jun 2022 12:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344806AbiFGQQi (ORCPT ); Tue, 7 Jun 2022 12:16:38 -0400 Received: from smtp.ruc.edu.cn (m177126.mail.qiye.163.com [123.58.177.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D923A101708; Tue, 7 Jun 2022 09:16:37 -0700 (PDT) Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp.ruc.edu.cn (Hmail) with ESMTPSA id 470C1800A4; Wed, 8 Jun 2022 00:16:34 +0800 (CST) From: Xiaohui Zhang To: Xiaohui Zhang , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Xiyu Yang , Xin Tan , Xin Xiong , Tom Parkin , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] l2tp: fix possible use-after-free Date: Wed, 8 Jun 2022 00:16:27 +0800 Message-Id: <20220607161627.25035-1-xiaohuizhang@ruc.edu.cn> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUhPN1dZLVlBSVdZDwkaFQgSH1lBWRpNTR5WGUsYSx1KTBgfHU NNVRMBExYaEhckFA4PWVdZFhoPEhUdFFlBWU9LSFVKSktITUpVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Pxg6MDo4Ej0xORceMzcpDTUJ DCwwCTFVSlVKTU5PTUpDTkJOSUNPVTMWGhIXVQMSGhQTDhIBExoVHDsJDhhVHh8OVRgVRVlXWRIL WUFZSUtJVUpKSVVKSkhVSUpJWVdZCAFZQUlJTEg3Bg++ X-HM-Tid: 0a813ef41e4c2c20kusn470c1800a4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We detected a suspected bug with our code clone detection tool. Similar to the handling of l2tp_tunnel_get in commit a622b40035d1 ("l2ip: fix possible use-after-free"), we thought a patch might be needed here as well. Before taking a refcount on a rcu protected structure, we need to make sure the refcount is not zero. Signed-off-by: Xiaohui Zhang --- net/l2tp/l2tp_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index b759fbd09b65..c5de6d4e0818 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -273,8 +273,8 @@ struct l2tp_session *l2tp_session_get(const struct net *net, u32 session_id) rcu_read_lock_bh(); hlist_for_each_entry_rcu(session, session_list, global_hlist) - if (session->session_id == session_id) { - l2tp_session_inc_refcount(session); + if (session->session_id == session_id && + refcount_inc_not_zero(&session->ref_count)) { rcu_read_unlock_bh(); return session; -- 2.17.1