Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2367406pxb; Mon, 20 Sep 2021 20:18:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzh/Fzm5PSlcIROloyg0ZoIPoU/xseW70AczegqWU9uKbQcijehcx3BZKA4wR3aH+izlO1I X-Received: by 2002:a05:6e02:1522:: with SMTP id i2mr12536857ilu.187.1632194321780; Mon, 20 Sep 2021 20:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632194321; cv=none; d=google.com; s=arc-20160816; b=uhY01CwFIqXssiNkA/1RrFvMSKmaMgL8FJByKUwqeLPrc5HwkugTiB1SFAXBKK5R4x Wu4hCBTxv6sLfTceNsH0glE04/B8DlnzvCOT6ovogHml7+0chlWjyZbBsUbdF4K3BKTV VNPi6Goth3I8r6bvbofeFkqtR4vFRXFiqRt7o/QgWMOgQkRDD/yCsGSEAoxkvTsXc1sg 3bCivUbG0m1NbGASuH0z9e6T9G3aaI9Xgjg5VO2lEaK8N9VWWgTDrirZ0x3GkuDe7s8y yBpgxx0uNCJ3+k4cbBg3K5/6BjHd3TGRTlLOMHDSvUB8onopA7waGELgfTWDvg38xinp nffA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5FjRvzJ6BeCEc2GnDWJQC5GJ07pVAcQ9wOMXMM/ZY6A=; b=KAXjMCPTILkc+uQh7n6EknyGNqi/nhUkSMcaGLR3zu/sHXwaGf9dqXwyAUvbLaHHYG zq0yRt533T52/RvyxkIGfb6xzy+zNILnmsnju1w0KWl2/dBjQU2i/eebS1Dn6Pext5RK voJhh8oup+vODBfIisMugKm4HDXldPYDqV17GX4mFGxcN/iuRol/f3H+YCrknstYUO3p Jm/SxDzTRg/uCO9vZDFaXes1AMAxFB+bICKxAB56xVm3+iaQ6DpIFLqu+D8/dW9glRyU a3ennQ57KuReEDGc7NXWmN6FB55DNoRuL3qWr8cyfXZN+Hl6W555Drz4pnUVi+3qSElg ZFVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdQWuK1U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 67si8900871ioc.91.2021.09.20.20.18.30; Mon, 20 Sep 2021 20:18:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdQWuK1U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348194AbhITSZx (ORCPT + 99 others); Mon, 20 Sep 2021 14:25:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:38976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377311AbhITSSS (ORCPT ); Mon, 20 Sep 2021 14:18:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1972C6329C; Mon, 20 Sep 2021 17:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158562; bh=ZFyJ3uWk95sj7MYTu0DlobhvJ4N0rAzbNqrd2OmhwLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdQWuK1Us4o/m9yGAqbkN8brakxIelumo/NFSx8a177dEpchRPbeRa7Pt6oUsZpCk L83fc0lPqm6rsOw1BER/nAuIa5ch0mFRLkVkQUFzCdTwi7oxooGNXGRVTaikkOMaT1 65WH9bIOYOGTvP2I765sy+KVht0mNV8t23VkXbyw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Xiong , Xin Tan , "David S. Miller" Subject: [PATCH 5.4 213/260] net/l2tp: Fix reference count leak in l2tp_udp_recv_core Date: Mon, 20 Sep 2021 18:43:51 +0200 Message-Id: <20210920163938.352136995@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang commit 9b6ff7eb666415e1558f1ba8a742f5db6a9954de upstream. The reference count leak issue may take place in an error handling path. If both conditions of tunnel->version == L2TP_HDR_VER_3 and the return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function would directly jump to label invalid, without decrementing the reference count of the l2tp_session object session increased earlier by l2tp_tunnel_get_session(). This may result in refcount leaks. Fix this issue by decrease the reference count before jumping to the label invalid. Fixes: 4522a70db7aa ("l2tp: fix reading optional fields of L2TPv3") Signed-off-by: Xiyu Yang Signed-off-by: Xin Xiong Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/l2tp/l2tp_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -886,8 +886,10 @@ static int l2tp_udp_recv_core(struct l2t } if (tunnel->version == L2TP_HDR_VER_3 && - l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) + l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) { + l2tp_session_dec_refcount(session); goto error; + } l2tp_recv_common(session, skb, ptr, optr, hdrflags, length); l2tp_session_dec_refcount(session);