Received: by 10.223.185.116 with SMTP id b49csp829954wrg; Sat, 10 Feb 2018 21:25:49 -0800 (PST) X-Google-Smtp-Source: AH8x225jlSCWA0Iw85UsY8P0EevMPq1XFTMnpOKY+gI+NBeEHaGU0330p89jYCTcooWLCuEL899x X-Received: by 10.98.141.208 with SMTP id p77mr7776886pfk.5.1518326748968; Sat, 10 Feb 2018 21:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326748; cv=none; d=google.com; s=arc-20160816; b=lfQ9qAjWZKtHZQvE+opaw995FTNGY3M7nHgkFuOphEGjZpd0P6uH4W/FesQSnJwRy6 wJMd54g/E/MEttGIQIMSAsVZ09wa/HWv8mH1P0mRUBUzdGfM980w45++oJo/19iQJ3w7 s74OdxUEjN82eYSF/D4NcSg8Ect44pi2A9QnHsCzkiceKt1YuvDUP5wZ0+rpEJlETfP6 hFPp8cXZQcnuu9XQbkXnOWFzxMcCIUjc5w7bKBkEdIE0vRptuNKUTSpDfP2FnuLPmYkB EQ2nn+oM4tly+srWglDVxaIPrHXX107UtBwKXnnvUu5UO76jKro+i5YD4dnHWqQVo27b kOKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=ImHWs9ZxibUB76TVmc3SkD6fjJdqyPUDbmODTYCa9rA=; b=mA+Sjkhq2lITUB+txuivz2mADXmQY/9tilNbmsA6MXhErXoPubZ0a5YwrX4x3OSr5D /u0vwxpK48JCDtPAE07EDsmi2dPfAfl0qLjkgtnRxdn+rcM5tEG7fueLASC5YyLKCLvI Ah++4E0Pb8YydZrsJ+/K5YZ4xUXNO7rD5u7kOklI/y7gT1WZOQkGYJqmevfVUscPt9PC MAC7Z97HZ8QflxhqA+UOkgmNG3IXXwxXdIVe1SC02kZAlsM7EeRQ3MEf3gYG4eVsw6Qb XMZNtLppzLVPnejVepLOpJwvSxMJ+18ph1DTiEHTkQrFyuQhnMBxn28HFmMF0FFIL20C vPlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s84si2162606pfi.366.2018.02.10.21.25.35; Sat, 10 Feb 2018 21:25:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753540AbeBKFXT (ORCPT + 99 others); Sun, 11 Feb 2018 00:23:19 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41345 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752539AbeBKEdk (ORCPT ); Sat, 10 Feb 2018 23:33:40 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKc-0002hR-Sw; Sun, 11 Feb 2018 04:33:39 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004So-ET; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Guillaume Nault" , "David S. Miller" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 17/79] l2tp: ensure sessions are freed after their PPPOL2TP socket In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Guillaume Nault commit cdd10c9627496ad25c87ce6394e29752253c69d3 upstream. If l2tp_tunnel_delete() or l2tp_tunnel_closeall() deletes a session right after pppol2tp_release() orphaned its socket, then the 'sock' variable of the pppol2tp_session_close() callback is NULL. Yet the session is still used by pppol2tp_release(). Therefore we need to take an extra reference in any case, to prevent l2tp_tunnel_delete() or l2tp_tunnel_closeall() from freeing the session. Since the pppol2tp_session_close() callback is only set if the session is associated to a PPPOL2TP socket and that both l2tp_tunnel_delete() and l2tp_tunnel_closeall() hold the PPPOL2TP socket before calling pppol2tp_session_close(), we're sure that pppol2tp_session_close() and pppol2tp_session_destruct() are paired and called in the right order. So the reference taken by the former will be released by the later. Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller [bwh: Backported to 3.2: adjust context] Signed-off-by: Ben Hutchings --- net/l2tp/l2tp_ppp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -466,11 +466,11 @@ static void pppol2tp_session_close(struc BUG_ON(session->magic != L2TP_SESSION_MAGIC); - if (sock) { + if (sock) inet_shutdown(sock, 2); - /* Don't let the session go away before our socket does */ - l2tp_session_inc_refcount(session); - } + + /* Don't let the session go away before our socket does */ + l2tp_session_inc_refcount(session); return; }