Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp109770iof; Sun, 5 Jun 2022 22:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQarq2x5b1Ij3soDhDBToaYXx+wd0uuIDka6+evEh+4H2f4oDgzHYTDioj+iUJvvb1mzOJ X-Received: by 2002:a63:1b5a:0:b0:3fb:92ec:6567 with SMTP id b26-20020a631b5a000000b003fb92ec6567mr19743153pgm.513.1654494038899; Sun, 05 Jun 2022 22:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654494038; cv=none; d=google.com; s=arc-20160816; b=ddnLo0vZzohGXSweN1jY//J8/zYscTHifu+peWnx8HPNoEtiz+1MI/kBzaeIiBOU3Z rTAJa5SFCIxgO0TFH7QjCJ1vZA7XuMcg2KiXQiGEz3rgVrRGcxxJJ0a5Fu3vydeW9VML 9F30NpMSihYGU6v+zc+Pea/feig285aVzngmgwCpqKq9UsUY16ysxQ32pZF4szjpm4d8 ryg1MBVm/gOZ/SUKuPEljdj+3DYjUer4ndGSI7sVtas8OjBDa2jhOD94vtPajodtqcjp 4UrK2P00X6+1ZyA0mlCGXKmtLfYCx3glK+ygD+NFW638aZYd9Eh/IbITcsyw2UMd2Bs7 AKcw== 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:dkim-signature; bh=eqpUkIQ0qCx1Qjo01BMjvUWJtIvSsdBr6NysCXODjYM=; b=DlEY1/+NnlXMdGihCZmjF+q3bD58GrumC8GwkrSDuqmqBtYPygNak+Ieox4U84K6Vp 2MSdVZj0Dxrd6uaybBvzmEkESGxMLLQIrGfm7321nGq+jwQ9Azi59PtN8uHZsiYr9cmg bvRp5kIrE0vC6DMR8TATelSMHB9DOwgOF/izNX7/ic5G76QEn30NPlZVD+AKvOEe7ft6 DqEeSdCsU+eyFNeFrwGC76zdlIZph8q7rIrdqMK4li3xOBn+MN4ICb1rKem7ayzIHw+P Xv0Di31DHBYxCholKnFd+Zmq5QHvmVJUBUIT2EsTG5RkSQfGy4pHqByQH1E/Nc0PVXyM uoCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=dxcKglql; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j14-20020a170903024e00b0015862deeb9dsi23173977plh.117.2022.06.05.22.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:40:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=dxcKglql; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B08092EABE4; Sun, 5 Jun 2022 21:46:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237302AbiFELfr (ORCPT + 99 others); Sun, 5 Jun 2022 07:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232695AbiFELfp (ORCPT ); Sun, 5 Jun 2022 07:35:45 -0400 Received: from m12-15.163.com (m12-15.163.com [220.181.12.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2019F18396 for ; Sun, 5 Jun 2022 04:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=eqpUkIQ0qCx1Qjo01B MjvUWJtIvSsdBr6NysCXODjYM=; b=dxcKglqlvEfsGpDeNQzMmAdDx95qrg8AAo LODKnqt+X/6CdvVCI2FzyH4dlrpvc/1dxSOcnzG8xzNN444gHPSLdxNaywhsebRC 6cSNIDMizlOvEHYdK1oTze9BxzslAkTzf+cXRsVw8dyOAdFvML50aGy+GnJKWFrp Tscrslvj4= Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp11 (Coremail) with SMTP id D8CowADn3_PqlJxiz7HLGA--.65442S4; Sun, 05 Jun 2022 19:35:14 +0800 (CST) From: Xiaohui Zhang To: Xiaohui Zhang , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.or, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] l2tp: fix possible use-after-free Date: Sun, 5 Jun 2022 19:35:03 +0800 Message-Id: <20220605113503.36153-1-ruc_zhangxiaohui@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: D8CowADn3_PqlJxiz7HLGA--.65442S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7JF1xKF18ZF1UWrWfAw1fWFg_yoWkXwc_Xr yxW3W8Wrn5Xa1xGr42va1YqFWvyrZIkrWrCw1xtrsFya4rtasakF97JFWvvw1Uu3yq9r9a grsYqw47Kw1DujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRiCzu7UUUUU== X-Originating-IP: [202.112.113.212] X-CM-SenderInfo: puxfs6pkdqw5xldrx3rl6rljoofrz/1tbiThIXMFUDPVwDMAAAs- X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 From: xiaohuizhang98 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: xiaohuizhang98 --- 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