From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65C4739A81E for ; Thu, 28 May 2026 10:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779964292; cv=none; b=SE3StUKzY7CIKe726jJ9sIKq5DL+YmLq+E1RppcyvvSb1Uhi/xHxOiMJQkosYHFjWFiB6eUK1RLT0VKQtarz710IRtSCKR2xYeAEi5savDWyRMeJ6Uq9RmpD+u3HGCdXk6fj+dzwRY/rDCdJNUHuISRk/zXqUEGE+Slyox557ZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779964292; c=relaxed/simple; bh=uMZInyhct2J6By9KxHA5ABF9l3RGFcif2+JpLTJpi2g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p/f2Qeru+XHuYLA1x5zIeLwk8Syv4NVqkODCobTGmla99PORDeVYXEoo5H0L4mMDL8wbcuDCoWiDndqdlY0V7i16TjZeMRWGeoakqxBs5kV+c6Y1uIy5D9WgvVmv6KuDwPRuuoAwo4H2YLzjybRTQN1fiKBCprNmyXUyOgZTcYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=djJ10qiv; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IBvpIKZW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="djJ10qiv"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IBvpIKZW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779964290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Aww6jC3I0Nj95YFehLzt5woPsMu1GhH9KVyzIE2qdSg=; b=djJ10qiv/uiXzM9u4KCytKWxBZ72HXS+oB9Z7bFbAYw19F6MS4xiO7IgOkJZvdS/q64p6k CvY50pCeAYEBNTJ+g9TL/Ysp3h7+zlMm6OmRCJmM4m9KTqt2l+DW8/MShcRHGb+Ss+xgPj 8veFYhx/I/xR3m+DSjTfgpCyiviZ+IA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-BN-C6OLKNIyvRouNbof4_Q-1; Thu, 28 May 2026 06:31:27 -0400 X-MC-Unique: BN-C6OLKNIyvRouNbof4_Q-1 X-Mimecast-MFC-AGG-ID: BN-C6OLKNIyvRouNbof4_Q_1779964286 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-45e80183514so8770510f8f.3 for ; Thu, 28 May 2026 03:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779964286; x=1780569086; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Aww6jC3I0Nj95YFehLzt5woPsMu1GhH9KVyzIE2qdSg=; b=IBvpIKZWXj0J0IVWvVuueUTaYy5x9zH3gB5XP7WNB2tVzcW3KkxIEPfSweb1jyvNu+ nIXyf5ryB5CZ9W+evXRfpsBT9UgV/sld8OUaIAFAeY3CDJqYViD6kAaoA2B/T8aei7f4 K6hWSZ1cR928VAKp+sBv6ShSj4oXlI/urufjJNJgkv9siJTY2otkPwadnktAxrdISDLh JdfA8dvAJuLYSQrmq+ReH50wZ1CSZicsmogV2xacCes8gJH6/ihwoYpVY4vp4CFAhvfc E6vLKfcpng/5bMx6io2mDtpoo3NHy0g8EXfAnLbAffI2wCVTGJVrePPRdWedp4InGwlM UhKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779964286; x=1780569086; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Aww6jC3I0Nj95YFehLzt5woPsMu1GhH9KVyzIE2qdSg=; b=K7CeuJYzZWKncGL0QQVBIIWlKhzv1RBnYardGK1ICre5lmFv77mjP5e5tmG8ez4SGK wW3Cyv3Tl9/DPynokwDKK7nuF1fGb+2meAYMcxfzNHHK6jaQo0APFXhtS0QkDhZLB4NV kCP4qTCsjsiYIvztNNhiaFG2jUBqXek6Lu9haeTB39dKlpVbXrRjaWI+ivruSppnu+AO pe+d9gtnkxOOmUlf6E5MeQDzON7VxAYktFPkX/r5N46vq6Tt5kpE1p42WYtj6OymQdwZ jKm7TNGvd1LOkhr8/08PRlMZmEn8jCvpvuxG//TFIHov5r1ACAxlX1ufrx/EfhLUlxdk 8hLQ== X-Forwarded-Encrypted: i=1; AFNElJ+JBWQt0r9eRl23j4MJK5I+zETFkTF5rQhZgNPcpAJbfRLdSLgp980QJP4iAOa8aJ4WcCRNbBOpElNxPIw=@vger.kernel.org X-Gm-Message-State: AOJu0YwifUzZgc9BXjnff+QZwZNfGwadsulMiOhgqWvyPFyGNDdweVFP 83jO1eLdPe14Gr6xnbTnhbYUYQXr7c21Nmy3T5o3LdPmRJS49eLuzJUUKCDa8x1BoGIrKUaTyIQ +D/u+E8ZOf8mgBx/BAjQSawnaSLE6GNtU8/Ix1H/68PxCad/iRMIKwlUou1HtLagyxg== X-Gm-Gg: Acq92OEa4YubDFjfetHLltn6UolNrfWnRupWzTYLXqmqGGfpoO6jKwHQiYJ1NwgBE/F N86VokJhjFFttf3VjXt1I43JA9pJ8rTnggKuNKprRp7Ovl5jB1lxE76eyJ9rv/XczoB/hHbKnoD VYy2+N2ZeKT0tlr2W4C0tF9U1gTz+y9ldrFn6fj8+pdAXdl8c40NjZSS8hTNs96shvTTdE59O5r hJtRxr65QVAwwr5QQhHcO16vUiEhQ+y8wHgIoQOpR+wE+aj7rejcGK3HJb8dSdkZesdBEP1m5cq VwOXrJKCKY8HzKJ1hHTcwJ2JYkmBuI4esGHx32ePUZdbuVyH9HD4V8uykeWshRbKvp6RFvdpnIh x+TqGdDPlHqrDnh6Up8wNJAa+yoYTj2XDz4y8JDWEt5kw7fhEvMkP8HwgIUlFR/hw7UC9Usv2Wf h+ENGTs/p/CyU= X-Received: by 2002:a05:600c:1992:b0:48a:76a3:2b9b with SMTP id 5b1f17b1804b1-490426c5416mr418407335e9.17.1779964286059; Thu, 28 May 2026 03:31:26 -0700 (PDT) X-Received: by 2002:a05:600c:1992:b0:48a:76a3:2b9b with SMTP id 5b1f17b1804b1-490426c5416mr418406935e9.17.1779964285634; Thu, 28 May 2026 03:31:25 -0700 (PDT) Received: from debian (2a01cb0580324c00f1205deb3ed928e2.ipv6.abo.wanadoo.fr. [2a01:cb05:8032:4c00:f120:5deb:3ed9:28e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49092a817d3sm38019705e9.10.2026.05.28.03.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 03:31:24 -0700 (PDT) Date: Thu, 28 May 2026 12:31:22 +0200 From: Guillaume Nault To: Wentao Liang Cc: James Chapman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] l2tp: fix tunnel refcount leak on register failure Message-ID: References: <20260528043418.1153320-1-vulab@iscas.ac.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260528043418.1153320-1-vulab@iscas.ac.cn> On Thu, May 28, 2026 at 04:34:18AM +0000, Wentao Liang wrote: > pppol2tp_tunnel_get() creates a new tunnel via l2tp_tunnel_create() > which initializes tunnel->ref_count to 1, then increments it to 2 via > refcount_inc(). If l2tp_tunnel_register() subsequently fails, the > error path calls kfree(tunnel) directly, bypassing the refcount > mechanism entirely. This is the expected behaviour. Since l2tp_tunnel_register() failed, the tunnel hasn't been exposed to the rest of the system and we're guaranteed that nothing depends on it. > This leaves the tunnel's ref_count at 2 with no > way to properly release it through l2tp_tunnel_put(). The tunnel is simply freed. The refcount doesn't matter here. > Replace kfree(tunnel) with l2tp_tunnel_put(tunnel) to properly release > the reference through the standard refcount cleanup path, which will > call l2tp_tunnel_free() when the counter reaches zero. This is buggy. At this point, the refcount is 2, and l2tp_tunnel_put() will decrement it by only one. So this patch just leaks the the tunnel forever. > Cc: stable@vger.kernel.org > Fixes: 6b9f34239b00 ("l2tp: fix races in tunnel creation") > Signed-off-by: Wentao Liang > --- > net/l2tp/l2tp_ppp.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c > index 99d6582f41de..16672e9df748 100644 > --- a/net/l2tp/l2tp_ppp.c > +++ b/net/l2tp/l2tp_ppp.c > @@ -661,7 +661,7 @@ static struct l2tp_tunnel *pppol2tp_tunnel_get(struct net *net, > refcount_inc(&tunnel->ref_count); > error = l2tp_tunnel_register(tunnel, net, &tcfg); > if (error < 0) { > - kfree(tunnel); > + l2tp_tunnel_put(tunnel); > return ERR_PTR(error); > } > > -- > 2.34.1 > >