Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2067400iof; Tue, 7 Jun 2022 18:39:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBmBTNm9mtj/u+s/SBUBFg5LwlNkOxt+bCAoHnwPeYzveoGKpIG0DaSwcCtcA4kYSE7iik X-Received: by 2002:a17:90a:31cf:b0:1c9:f9b8:68c7 with SMTP id j15-20020a17090a31cf00b001c9f9b868c7mr70688566pjf.34.1654652393579; Tue, 07 Jun 2022 18:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654652393; cv=none; d=google.com; s=arc-20160816; b=lZ2md4BZsqIHLrpJn8Mjw1E9/ABzu1YQsWB5+pSy/ltZ/1GCIQhilzvEYY9OBNBp4c mMdFJvwkFsAds8HSLTNHJZH17mzyMGA1LRmanD43l4xJylx74ih6tI0uGgg31lfO5e5r kuPSGZlgReYwRTOP6nXDstw72caZAUHdvHnIaRvPVeUZKWQT5jdT/8WuhHyBNE7fx3bL wVD14ax8Aq6KhK8e59IdxK2P5umrEmGVbm1GNIwLqu4MJf6rr5kZgSGjzHTAKpeXdqUG 3eQxlgDI5gP48a0ng99AQrgixCwJk1pTEfIUx9eCi81BI9cQ5WjVAsByOzNdVwE4gps2 ocgQ== 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=ttEjqFvON39b1ppbXoEuMl9bb0bfz26RWo94ylqirQU=; b=tSvgXgGCfF0F3hxeZ1+GES93F4HHeD/X7bYtk8F7HeGE28i5nHObnOUYyEC9UPdWi3 4x3PIBZlneIHqlGaeshzbQXD6rlyxcCkkOL444gueaoIAhQMCz3QNMi9CfopxYaFf7OK OKkmSLbkksAB8iMRjfQ7l5DMy8u4VR1TfJJolINvnm5dRJdbrgx0kAITf48VW7NFzxXC /p1sg94pSpINCjwsM3hw388cKS1GdgZklm14K9iXVqoPKrrPkUpSnr2f/rCOPnWFwr0J kNRuvT9PIIJSxBwWVsX0r318dXSYhKdN8NexNErlFexnbdE0QAMZ9PJiSn6po3mtHtyx 3mRA== 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 o19-20020a656a53000000b003fc5a7d389fsi11827525pgu.582.2022.06.07.18.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 18:39:53 -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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5D3C260CCA; Tue, 7 Jun 2022 18:25:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344826AbiFGQQl (ORCPT + 99 others); Tue, 7 Jun 2022 12:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344928AbiFGQQg (ORCPT ); Tue, 7 Jun 2022 12:16:36 -0400 Received: from smtp.ruc.edu.cn (m177126.mail.qiye.163.com [123.58.177.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A333101738; Tue, 7 Jun 2022 09:16:23 -0700 (PDT) Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp.ruc.edu.cn (Hmail) with ESMTPSA id 334D280053; Wed, 8 Jun 2022 00:16:19 +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 1/2] l2tp: fix possible use-after-free Date: Wed, 8 Jun 2022 00:16:13 +0800 Message-Id: <20220607161613.24988-1-xiaohuizhang@ruc.edu.cn> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUhPN1dZLVlBSVdZDwkaFQgSH1lBWUMYThpWHhgeHUNMGB8fQk MYVRMBExYaEhckFA4PWVdZFhoPEhUdFFlBWU9LSFVKSktITUpVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OEk6OAw4Mj0#MRdRFTJIDTUJ DiMaFBxVSlVKTU5PTUpDTkNLTUhLVTMWGhIXVQMSGhQTDhIBExoVHDsJDhhVHh8OVRgVRVlXWRIL WUFZSUtJVUpKSVVKSkhVSUpJWVdZCAFZQUlJTUk3Bg++ X-HM-Tid: 0a813ef3e4782c20kusn334d280053 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 7499c51b1850..b759fbd09b65 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -252,8 +252,8 @@ struct l2tp_session *l2tp_tunnel_get_session(struct l2tp_tunnel *tunnel, rcu_read_lock_bh(); hlist_for_each_entry_rcu(session, session_list, 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