Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2041497iof; Tue, 7 Jun 2022 17:54:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH1BxQXCaDlUag9reLY5n6R5D6jJy3SWl2Ok3ft4Mi2/HbBz48DB6Krl/w4Z/LMH33lmUT X-Received: by 2002:a63:2c01:0:b0:3fe:d7f:24c8 with SMTP id s1-20020a632c01000000b003fe0d7f24c8mr4302045pgs.365.1654649642993; Tue, 07 Jun 2022 17:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654649642; cv=none; d=google.com; s=arc-20160816; b=u1hr020ufJnovBn6MQIR+jecARlQlLw8R1GymSiarNglj8B0VPf4fVlsF7ikSDipTh 10+oKDakBWavhMDs070sgHSJuJtBs2iYxIGvwPGZB67bS4sBPYU2+4YpuIhqiivm5CuZ YBPSTRuE7cP9TFmJO1KJgxgPkT1rnsPR24vQfj8YwLdr7BaFX4hzC+gNQL5XpCya1euI uCur53gA7l3dy2J+8W7nJ28EifSHs1TFfBBbVa8e0FtoZlJVGYzUHgCqx0letgFBuwb3 XXincUuZHsCWBhwe5H/6d58DOTacNT0fknpYebLfYFBW5vxKFeu1gPVPnpj/ja7zFg0R BIeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7rYLYDe80leH68JeXvH0gMR/2Fmm2d87F6uzTt2pDIM=; b=QBQuP1xKGikgwFvPTA8sP3VtzHxnxoTjzIAQah58vho7a4Lp/xrlaTjU2Sn8xIywBD XhkysfC96kjcFOyXfGUV/VjSfArxa6TAnYMP2uwoLbvMBdgWS8/liQS7tW07Lss0fLbM /z+1ROnqL5UZWia1n9tXSsxeXLk2nwTxbbRu/W6K1HqmOnciYaPrWhGCTqIpN0s9uT9C +Kw1/5Y6h68Mc7w0m+tL/qzcRE5uE+dDb4He2RkRa+QUpFFDMwzIF0sYEJcoyKNLJNyc lZgw6/ujSmZfcyGQeKwNGIVqY5TW/nQfShVXMlHKovXqo3bZDnrJ7ZuHD0BBJpvlVGu+ gljA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HYlFKKTC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y71-20020a638a4a000000b003fccd1c49easi25445269pgd.158.2022.06.07.17.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 17:54:02 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=HYlFKKTC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C063F226CDB; Tue, 7 Jun 2022 17:50:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348240AbiFGRtg (ORCPT + 99 others); Tue, 7 Jun 2022 13:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347875AbiFGRbU (ORCPT ); Tue, 7 Jun 2022 13:31:20 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B95A11469E for ; Tue, 7 Jun 2022 10:28:40 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-31332df12a6so35579037b3.4 for ; Tue, 07 Jun 2022 10:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7rYLYDe80leH68JeXvH0gMR/2Fmm2d87F6uzTt2pDIM=; b=HYlFKKTCVa93BZYhT6TxJ+x/USTpqJ/7Br94kTb9fWRan1dSpVoztuo1fRWt1T2KCH 1nU2eNJzrBr2D5nnRP28LbTPlSCUw9H6nzMwsDGoQALupB1swupdNFxFltBegYWSVQrC qlOJ+aUvtGgyT7oz2n+nfdLhkcbWCfI0X7G4ib83LbaRm+figmlx8wymkW1JkBDFSxMJ 4afp6SCGn/O69V2UEoPnZoh98FXuOhYb658C/8ZWF4HMnO2aOt0YvDW4flgHbW3m2vyR Zzyf8lCPIof03dKksgOZadwpduhXQWXQ1gcLQkHofbMIrkFytzc7+/mjhel3KMJdnds3 ZexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7rYLYDe80leH68JeXvH0gMR/2Fmm2d87F6uzTt2pDIM=; b=jeulMvdOlEp6eaYkxvXJxRCRHkfGUJT+zY3UhhQhFdpGbSYVYcZETBkJ2GMEOTF26R 8Vl0JJQeW+Hjj/n1kwBxLTnOUSRlhBDhmGsP8zAewKO+SYnXBzrkONIqlNw9l5B3fDyX 6y1X6HHWWGdxssZdMSe+xKE73oB8brSN5BqSH+quWn2qhUXGND0MCFTZyckjdxwFn2Ec Wvp4ZOjYt+SFz+JezIDBBsWOLVMi/VRsmwD+gW7G6L2UprJNSKuzQLpOZ5jvTN3pVQla l6AxIEgxVTn6Ue7bfS7+7GC4iKrCknhq7ZzvPlxVaBEDbHKZJMUuwuo6RKLLhHrjAgFj 7J2Q== X-Gm-Message-State: AOAM532mDpLRxVB3jLj7ZQsGSRe6bKJhYAoBr7DrnN8cS7vO19Dni9oY E3y+irI6hyv55cJe64GtXaIEvG2+C/Cx4ZVssYPpYg== X-Received: by 2002:a81:b401:0:b0:300:2e86:e7e5 with SMTP id h1-20020a81b401000000b003002e86e7e5mr31623346ywi.467.1654622919171; Tue, 07 Jun 2022 10:28:39 -0700 (PDT) MIME-Version: 1.0 References: <20220607161627.25035-1-xiaohuizhang@ruc.edu.cn> In-Reply-To: <20220607161627.25035-1-xiaohuizhang@ruc.edu.cn> From: Eric Dumazet Date: Tue, 7 Jun 2022 10:28:27 -0700 Message-ID: Subject: Re: [PATCH 2/2] l2tp: fix possible use-after-free To: Xiaohui Zhang Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Xiyu Yang , Xin Tan , Xin Xiong , Tom Parkin , netdev , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 On Tue, Jun 7, 2022 at 9:16 AM Xiaohui Zhang wrote: > > 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 > Please fix all bugs in a single patch. net/l2tp/l2tp_core.c contains four suspect calls to l2tp_session_inc_refcount()