From patchwork Fri Jul 24 15:31:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335804 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=P47bgQU7; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVY52Fdz9sPB for ; Sat, 25 Jul 2020 01:32:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726783AbgGXPcH (ORCPT ); Fri, 24 Jul 2020 11:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from mail.katalix.com (mail.katalix.com [IPv6:2a05:d01c:827:b342:16d0:7237:f32a:8096]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D33C7C0619D3 for ; Fri, 24 Jul 2020 08:32:05 -0700 (PDT) Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id DFFD98AD92; Fri, 24 Jul 2020 16:32:04 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=n4ErZG1al9W3VkTjlBOk+Fzuxshktb2qVg0TxsmzzZ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=201/9]=20l2tp:=20avoid=20multipl e=20assignments|Date:=20Fri,=2024=20Jul=202020=2016:31:49=20+0100| Message-Id:=20<20200724153157.9366-2-tparkin@katalix.com>|In-Reply -To:=20<20200724153157.9366-1-tparkin@katalix.com>|References:=20< 20200724153157.9366-1-tparkin@katalix.com>; b=P47bgQU7r7qyUztJW+AdUBCR+DLhGCnu31yn3xb/gxC25huMa5eHz7lz6FFp3Ai3m 0XFmKLCH4ipBVfbngZBHqzxixtRPKPxGqs7iSjx6uvoBKWdC1l29jWlMbe8M5VW6qS aWqJd/Fp20kQ3D6r9wniTyF46FW0xSaoAd8PzFw/jeCMVzmbXGsoYBTFJRF28BRC4r bIfjB5ppcULjYmF0vIa/Uq4WuLo263/TZNqcnNMsWCthSRT8drIz3JcL5y47oqYPhq Kc4zo3c5QtIlYcNLFeUy4qg/VssNVRotz79kPWslu05yGP7GKNpi/nRN43sB9IjqlT BfU1/amZb8WdQ== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 1/9] l2tp: avoid multiple assignments Date: Fri, 24 Jul 2020 16:31:49 +0100 Message-Id: <20200724153157.9366-2-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org checkpatch warns about multiple assignments. Update l2tp accordingly. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 6 +++--- net/l2tp/l2tp_ip.c | 12 ++++++++---- net/l2tp/l2tp_ip6.c | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 7e3523015d6f..b871cceeff7c 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -621,8 +621,8 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, int length) { struct l2tp_tunnel *tunnel = session->tunnel; + u32 ns = 0, nr = 0; int offset; - u32 ns, nr; /* Parse and check optional cookie */ if (session->peer_cookie_len > 0) { @@ -644,7 +644,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, * the control of the LNS. If no sequence numbers present but * we were expecting them, discard frame. */ - ns = nr = 0; L2TP_SKB_CB(skb)->has_seq = 0; if (tunnel->version == L2TP_HDR_VER_2) { if (hdrflags & L2TP_HDRFLAG_S) { @@ -826,7 +825,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) } /* Point to L2TP header */ - optr = ptr = skb->data; + optr = skb->data; + ptr = skb->data; /* Get L2TP header flags */ hdrflags = ntohs(*(__be16 *)ptr); diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c index d81564cf1e7f..a159cb2bf0f4 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c @@ -124,7 +124,8 @@ static int l2tp_ip_recv(struct sk_buff *skb) goto discard; /* Point to L2TP header */ - optr = ptr = skb->data; + optr = skb->data; + ptr = skb->data; session_id = ntohl(*((__be32 *)ptr)); ptr += 4; @@ -153,7 +154,8 @@ static int l2tp_ip_recv(struct sk_buff *skb) goto discard_sess; /* Point to L2TP header */ - optr = ptr = skb->data; + optr = skb->data; + ptr = skb->data; ptr += 4; pr_debug("%s: ip recv\n", tunnel->name); print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length); @@ -284,8 +286,10 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) goto out; - if (addr->l2tp_addr.s_addr) - inet->inet_rcv_saddr = inet->inet_saddr = addr->l2tp_addr.s_addr; + if (addr->l2tp_addr.s_addr) { + inet->inet_rcv_saddr = addr->l2tp_addr.s_addr; + inet->inet_saddr = addr->l2tp_addr.s_addr; + } if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) inet->inet_saddr = 0; /* Use device */ diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index 614febf8dd0d..bc757bc7e264 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c @@ -137,7 +137,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb) goto discard; /* Point to L2TP header */ - optr = ptr = skb->data; + optr = skb->data; + ptr = skb->data; session_id = ntohl(*((__be32 *)ptr)); ptr += 4; @@ -166,7 +167,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb) goto discard_sess; /* Point to L2TP header */ - optr = ptr = skb->data; + optr = skb->data; + ptr = skb->data; ptr += 4; pr_debug("%s: ip recv\n", tunnel->name); print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length); From patchwork Fri Jul 24 15:31:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335808 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=UwVKtIA4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVj3c4Mz9sSn for ; Sat, 25 Jul 2020 01:32:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgGXPc1 (ORCPT ); Fri, 24 Jul 2020 11:32:27 -0400 Received: from mail.katalix.com ([3.9.82.81]:56766 "EHLO mail.katalix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 0C3468AD98; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=4stRypcCnZUsQgOv6yYjGt2325QE5elmiA+15tBpuwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=202/9]=20l2tp:=20WARN_ON=20rathe r=20than=20BUG_ON=20in=20l2tp_dfs_seq_start|Date:=20Fri,=2024=20Ju l=202020=2016:31:50=20+0100|Message-Id:=20<20200724153157.9366-3-t parkin@katalix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@ katalix.com>|References:=20<20200724153157.9366-1-tparkin@katalix. com>; b=UwVKtIA4GjIFOk2ZCHHfwhoVPb4Y6ABZ4zvMAoWBI8gsEkiSnM9AUpLPY+9ZQ/Uj0 3c5R6dZ+gCmFaRYZjcHyWs72BFAFy3tGHqVswHsMD66ACApDObT1Xfn9gqTvh8O8Z3 WXBxmjn3UmzGHAckpg5uU7DnWc0m02n0a0Lm6IjSZtENqRuIdOYqceE5V1y1XCE9Xj FPzLnMB6o9/bt8O5LcULEkxJ3xRszOV0B9JO13khHab5dYimPLS714rLQmzgte6J10 YNhxH4Mr6t7roZg3IF5iTRdXH2JaHIXKCVHY+OhJZp/VFbSI+VWMGhKKVxwKE+ecY6 yweAXPNFHWypg== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 2/9] l2tp: WARN_ON rather than BUG_ON in l2tp_dfs_seq_start Date: Fri, 24 Jul 2020 16:31:50 +0100 Message-Id: <20200724153157.9366-3-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_dfs_seq_start had a BUG_ON to catch a possible programming error in l2tp_dfs_seq_open. Since we can easily bail out of l2tp_dfs_seq_start, prefer to do that and flag the error with a WARN_ON rather than crashing the kernel. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_debugfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c index 72ba83aa0eaf..96cb9601c21b 100644 --- a/net/l2tp/l2tp_debugfs.c +++ b/net/l2tp/l2tp_debugfs.c @@ -72,7 +72,10 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) if (!pos) goto out; - BUG_ON(!m->private); + if (WARN_ON(!m->private)) { + pd = NULL; + goto out; + } pd = m->private; if (!pd->tunnel) From patchwork Fri Jul 24 15:31:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335799 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=M/M3dPsx; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVJ4d6Tz9sR4 for ; Sat, 25 Jul 2020 01:32:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbgGXPcH (ORCPT ); Fri, 24 Jul 2020 11:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from mail.katalix.com (mail.katalix.com [IPv6:2a05:d01c:827:b342:16d0:7237:f32a:8096]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6217C0619E4 for ; Fri, 24 Jul 2020 08:32:05 -0700 (PDT) Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 2CB5E8AD9E; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=ue9mOAv1pdlNVez+dhAaSTApDx9q/qLQ4c9l0kwiYAM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=203/9]=20l2tp:=20remove=20BUG_ON =20in=20l2tp_session_queue_purge|Date:=20Fri,=2024=20Jul=202020=20 16:31:51=20+0100|Message-Id:=20<20200724153157.9366-4-tparkin@kata lix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@katalix.com >|References:=20<20200724153157.9366-1-tparkin@katalix.com>; b=M/M3dPsxl3GrgPJ3FljbeQNqueI1dV7Paw8vKs+VfU5pw3in8P5fUTn17bpg0G+oD vI0IdqRB6EHNCCdXILWV3+lxYaA1utWEecDtPRPaGqx0SmucsPUGGx4Y/HkQCUB7+k lsojU434tNddR+qymXK0T/Y6GezJDEjeAnyQ1UbTvug+9hQGhm8F8m46FQJQ4GOnR4 Ooy/5LVpDIm7FJBk8Sd8ejMME0TRMyklCd2CzhmL+FiXgMMDTmVC7vYVCnF8JZhWTa d4taDUKsyGiUTBYczRtMW+XgwZT1hU4m+W9rWQKS4kymP7pzApMiHnIPS2KC9BtCw/ 4sWRpIvgs2+DQ== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 3/9] l2tp: remove BUG_ON in l2tp_session_queue_purge Date: Fri, 24 Jul 2020 16:31:51 +0100 Message-Id: <20200724153157.9366-4-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_session_queue_purge is only called from l2tp_core.c, and it's easy to statically analyse the code paths calling it to validate that it should never be passed a NULL session pointer. Having a BUG_ON checking the session pointer triggers a checkpatch warning. Since the BUG_ON is of no value, remove it to avoid the warning. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index b871cceeff7c..a1ed8baa5aaa 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -777,7 +777,6 @@ static int l2tp_session_queue_purge(struct l2tp_session *session) { struct sk_buff *skb = NULL; - BUG_ON(!session); BUG_ON(session->magic != L2TP_SESSION_MAGIC); while ((skb = skb_dequeue(&session->reorder_q))) { atomic_long_inc(&session->stats.rx_errors); From patchwork Fri Jul 24 15:31:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335806 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=TPqMv1K1; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVc4qQlz9sPB for ; Sat, 25 Jul 2020 01:32:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgGXPcX (ORCPT ); Fri, 24 Jul 2020 11:32:23 -0400 Received: from mail.katalix.com ([3.9.82.81]:56770 "EHLO mail.katalix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726583AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 4DC788ADAB; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=7zOz5sbhMR8gJL2wm5U97mY91i9sULUPVYbVPEMgJzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=204/9]=20l2tp:=20remove=20BUG_ON =20in=20l2tp_tunnel_closeall|Date:=20Fri,=2024=20Jul=202020=2016:3 1:52=20+0100|Message-Id:=20<20200724153157.9366-5-tparkin@katalix. com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@katalix.com>|Re ferences:=20<20200724153157.9366-1-tparkin@katalix.com>; b=TPqMv1K1b8JVx/XzowZn3K0N87P4/ntKvr/it8zTNNNdMrPqC3wX3Gfu4Fs83JQoP um703gnNouxelAQPhA69HqEd/0GYTqRWJRcjjuwbKeqQLgPcKVWacvKE7uFNTbe2MW 7NIXTRxNZug7iyRVUQeqndO+HWiCu1Sjx3KiRAGWlNjvHLnpXaznuPLt4YtrNWfcr/ XheA++Fu5aaVErD2kH42FkYXZoj8zh4eqG4Eo8F9wHzA5M50kFzWVY3pf9j+6C8QxO zLy6T+0Pehc80lV9NKe5wIpAiNkIPeV+UdFnbXybJ8eE0PUGLEV9bgLXoLe1DC7Bd4 EU4BbDRXVZMVQ== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 4/9] l2tp: remove BUG_ON in l2tp_tunnel_closeall Date: Fri, 24 Jul 2020 16:31:52 +0100 Message-Id: <20200724153157.9366-5-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_tunnel_closeall is only called from l2tp_core.c, and it's easy to statically analyse the code path calling it to validate that it should never be passed a NULL tunnel pointer. Having a BUG_ON checking the tunnel pointer triggers a checkpatch warning. Since the BUG_ON is of no value, remove it to avoid the warning. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index a1ed8baa5aaa..6be3f2e69efd 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1188,8 +1188,6 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) struct hlist_node *tmp; struct l2tp_session *session; - BUG_ON(!tunnel); - l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n", tunnel->name); From patchwork Fri Jul 24 15:31:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335800 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=xG2FjMTN; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVK3D1sz9sRN for ; Sat, 25 Jul 2020 01:32:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726838AbgGXPcH (ORCPT ); Fri, 24 Jul 2020 11:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from mail.katalix.com (mail.katalix.com [IPv6:2a05:d01c:827:b342:16d0:7237:f32a:8096]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 939E7C0619D3 for ; Fri, 24 Jul 2020 08:32:06 -0700 (PDT) Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 6DC528ADAC; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=jhuDh8WrnW9oxZDGB4SAf6xPABJ8SsnCRkB6Npip0a4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=205/9]=20l2tp:=20don't=20BUG_ON= 20session=20magic=20checks=20in=20l2tp_ppp|Date:=20Fri,=2024=20Jul =202020=2016:31:53=20+0100|Message-Id:=20<20200724153157.9366-6-tp arkin@katalix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@k atalix.com>|References:=20<20200724153157.9366-1-tparkin@katalix.c om>; b=xG2FjMTN7pT3PFgt2trzdmyBD4nl9tWkOEd2Fj/pJvsXz0IAyuuHAI7QgWfAuThyG dVDLfzP1z2mpBUEFOnm3cAU8s1lcCMwe4RofKKC39Xue3Pr+vYw+82MRLoLubLo6DT cBa+U0ypIlRy8x4v6YZ0UYA9t+DPfZQpehBEH54NF4GjtM1deyAiKVL9Rp7+jKioDf oykuAw58Zi2m0WeR0CA0ywBcGUl/TuB1Xv3aY1ih15Md4gfaB5uSg8TNaBvMVOTosx qAR4g9lyEIhvhXkMm1clzkrerthwS/befveqQxnoofd469EAeVmlnVCBKv2Brn9A94 Q1lBr1wRsCDKw== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 5/9] l2tp: don't BUG_ON session magic checks in l2tp_ppp Date: Fri, 24 Jul 2020 16:31:53 +0100 Message-Id: <20200724153157.9366-6-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org checkpatch advises that WARN_ON and recovery code are preferred over BUG_ON which crashes the kernel. l2tp_ppp.c's BUG_ON checks of the l2tp session structure's "magic" field occur in code paths where it's reasonably easy to recover: * In the case of pppol2tp_sock_to_session, we can return NULL and the caller will bail out appropriately. There is no change required to any of the callsites of this function since they already handle pppol2tp_sock_to_session returning NULL. * In the case of pppol2tp_session_destruct we can just avoid decrementing the reference count on the suspect session structure. In the worst case scenario this results in a memory leak, which is preferable to a crash. Convert these uses of BUG_ON to WARN_ON accordingly. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_ppp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index e58fe7e3b884..3b6613cfef48 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk) sock_put(sk); goto out; } - - BUG_ON(session->magic != L2TP_SESSION_MAGIC); + if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) { + session = NULL; + sock_put(sk); + goto out; + } out: return session; @@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk) if (session) { sk->sk_user_data = NULL; - BUG_ON(session->magic != L2TP_SESSION_MAGIC); + if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) + return; l2tp_session_dec_refcount(session); } } From patchwork Fri Jul 24 15:31:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335807 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=ZI+r/O+i; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVh2lF4z9sRN for ; Sat, 25 Jul 2020 01:32:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726326AbgGXPcZ (ORCPT ); Fri, 24 Jul 2020 11:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726726AbgGXPcG (ORCPT ); Fri, 24 Jul 2020 11:32:06 -0400 Received: from mail.katalix.com (mail.katalix.com [IPv6:2a05:d01c:827:b342:16d0:7237:f32a:8096]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 98F74C0619E4 for ; Fri, 24 Jul 2020 08:32:06 -0700 (PDT) Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 8E1808ADAD; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=kUiqyrJBnTTcKz3WKWE5+ihZm1VtcYbkrlnfi5v+ZsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=206/9]=20l2tp:=20don't=20BUG_ON= 20seqfile=20checks=20in=20l2tp_ppp|Date:=20Fri,=2024=20Jul=202020= 2016:31:54=20+0100|Message-Id:=20<20200724153157.9366-7-tparkin@ka talix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@katalix.c om>|References:=20<20200724153157.9366-1-tparkin@katalix.com>; b=ZI+r/O+iFum29bb5SsIbIjNYXv6CJw10Pz6wGxabkj8EbdgKZhZS0r+i/X9gPJr4B Xz9OSLbZ3WmM8n/4RF+gFFoqOxloODMgHYjGZ7adFerNmemAYmEZImmsEakPivPIPC Yf8DqOhUJmtxAoYQ4LnjKJnn5lXah53Qqx4ixkufifOAUO/AK3kk74CcTiOEcP1nl3 /l2AjstYYLH0NInRXFYIwLTXMsztV0je0g4pBgvqfo9zpMmDuAltQI0PE1g/cRxp48 0hM3bzsLjo1d3hoN9yNuGdZBay4Z3fQVl3iiurAQ8o1UmRGCdDWxHZhoXhBPmKog+C R1QAlr1TQRtvw== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 6/9] l2tp: don't BUG_ON seqfile checks in l2tp_ppp Date: Fri, 24 Jul 2020 16:31:54 +0100 Message-Id: <20200724153157.9366-7-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org checkpatch advises that WARN_ON and recovery code are preferred over BUG_ON which crashes the kernel. l2tp_ppp has a BUG_ON check of struct seq_file's private pointer in pppol2tp_seq_start prior to accessing data through that pointer. Rather than crashing, we can simply bail out early and return NULL in order to terminate the seq file processing in much the same way as we do when reaching the end of tunnel/session instances to render. Retain a WARN_ON to help trace possible bugs in this area. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_ppp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 3b6613cfef48..c2d14cecbecf 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -1478,7 +1478,11 @@ static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs) if (!pos) goto out; - BUG_ON(!m->private); + if (WARN_ON(!m->private)) { + pd = NULL; + goto out; + } + pd = m->private; net = seq_file_net(m); From patchwork Fri Jul 24 15:31:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335803 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=sSk8/qBR; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVS3k9sz9sRN for ; Sat, 25 Jul 2020 01:32:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726824AbgGXPcO (ORCPT ); Fri, 24 Jul 2020 11:32:14 -0400 Received: from mail.katalix.com ([3.9.82.81]:56776 "EHLO mail.katalix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726702AbgGXPcH (ORCPT ); Fri, 24 Jul 2020 11:32:07 -0400 Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id AE3198ADAE; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604725; bh=SflVZU7cgcDGkMu7ECuW7o3uatEUr22DOwT9l2VSVKw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=207/9]=20l2tp:=20WARN_ON=20rathe r=20than=20BUG_ON=20in=20l2tp_session_queue_purge|Date:=20Fri,=202 4=20Jul=202020=2016:31:55=20+0100|Message-Id:=20<20200724153157.93 66-8-tparkin@katalix.com>|In-Reply-To:=20<20200724153157.9366-1-tp arkin@katalix.com>|References:=20<20200724153157.9366-1-tparkin@ka talix.com>; b=sSk8/qBRpFW1oOPuT2i2OktT/Au3DJPwDAfAWnSC1D23Y1/poJUdjm1wzmVQmcNEW cR+qn1bnYPm5rVTyIciwvk0EDDB4Jk/Go/oYFPkw39WrkUAGxal2hUcW5B6rpBKBup V5yxvIfeTPU2mD2zxoRb34bqsSNh7FLB6OUWGcrl4wxH0DW/4nUgAT98btelFXYJyX OxfsT2CNfVZTx9RsnFdRZ7i+2Auqu3id13FwnW6Hqerah2Q7ITGor5/Sxdvaqgm1an EClv4yuECf9smLGeg9FEXEpXTW5rOGZfU2nmscIWI5iDAg8NHZdGeljGhMD8+PNb1G +UEDy7eZl+1Sw== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 7/9] l2tp: WARN_ON rather than BUG_ON in l2tp_session_queue_purge Date: Fri, 24 Jul 2020 16:31:55 +0100 Message-Id: <20200724153157.9366-8-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_session_queue_purge is used during session shutdown to drop any skbs queued for reordering purposes according to L2TP dataplane rules. The BUG_ON in this function checks the session magic feather in an attempt to catch lifetime bugs. Rather than crashing the kernel with a BUG_ON, we can simply WARN_ON and refuse to do anything more -- in the worst case this could result in a leak. However this is highly unlikely given that the session purge only occurs from codepaths which have obtained the session by means of a lookup via. the parent tunnel and which check the session "dead" flag to protect against shutdown races. While we're here, have l2tp_session_queue_purge return void rather than an integer, since neither of the callsites checked the return value. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 6be3f2e69efd..e228480fa529 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -773,16 +773,17 @@ EXPORT_SYMBOL(l2tp_recv_common); /* Drop skbs from the session's reorder_q */ -static int l2tp_session_queue_purge(struct l2tp_session *session) +static void l2tp_session_queue_purge(struct l2tp_session *session) { struct sk_buff *skb = NULL; - BUG_ON(session->magic != L2TP_SESSION_MAGIC); + if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) + return; + while ((skb = skb_dequeue(&session->reorder_q))) { atomic_long_inc(&session->stats.rx_errors); kfree_skb(skb); } - return 0; } /* Internal UDP receive frame. Do the real work of receiving an L2TP data frame From patchwork Fri Jul 24 15:31:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335802 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=LPA/dXGI; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVP3w1Xz9sR4 for ; Sat, 25 Jul 2020 01:32:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726854AbgGXPcJ (ORCPT ); Fri, 24 Jul 2020 11:32:09 -0400 Received: from mail.katalix.com ([3.9.82.81]:56778 "EHLO mail.katalix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgGXPcI (ORCPT ); Fri, 24 Jul 2020 11:32:08 -0400 Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id D05B78ADAF; Fri, 24 Jul 2020 16:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604726; bh=UgSb0iFXmTqnJKlU4S8N/MUH/Vhb8QabiqMjW0CzHEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=208/9]=20l2tp:=20remove=20BUG_ON =20refcount=20value=20in=20l2tp_session_free|Date:=20Fri,=2024=20J ul=202020=2016:31:56=20+0100|Message-Id:=20<20200724153157.9366-9- tparkin@katalix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin @katalix.com>|References:=20<20200724153157.9366-1-tparkin@katalix .com>; b=LPA/dXGIJJAlLbxC9Lv/LgnRuTDzQ5oCxrIFeC/7SId7YpwqzoVyyHsKLSv+NFDpH ASU/5Oa4mrYB6U1QngrmUy6SEq6fRo/DWq2qa0Auq6Jt16RNrkUA8mg1fdm2pkSRVR MKSpt1RfLMofg9khH9Ob3L5Wevc7rFB72VMl31OLuLMNviqx/CoPRHSegdwhTlmaPB 9OgDSdsQT9wgGdZ7W0ofcYM7ykEL5hSMmvujc1HiaDdlBAdWy3jqbOagPzQvkqq0T4 GqZhsqb7SB5jzXjd+2eDWglPnkjWg1plfeC9ylASeKAU61QaQ6qnz2jztS49Ku4DJU QqRBFpq7Lc8tw== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 8/9] l2tp: remove BUG_ON refcount value in l2tp_session_free Date: Fri, 24 Jul 2020 16:31:56 +0100 Message-Id: <20200724153157.9366-9-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_session_free is only called by l2tp_session_dec_refcount when the reference count reaches zero, so it's of limited value to validate the reference count value in l2tp_session_free itself. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index e228480fa529..50548c61b91e 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1563,8 +1563,6 @@ void l2tp_session_free(struct l2tp_session *session) { struct l2tp_tunnel *tunnel = session->tunnel; - BUG_ON(refcount_read(&session->ref_count) != 0); - if (tunnel) { BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); l2tp_tunnel_dec_refcount(tunnel); From patchwork Fri Jul 24 15:31:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Parkin X-Patchwork-Id: 1335801 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=katalix.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=katalix.com header.i=@katalix.com header.a=rsa-sha256 header.s=mail header.b=UBmw4oid; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BCtVN1y6dz9sR4 for ; Sat, 25 Jul 2020 01:32:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbgGXPcK (ORCPT ); Fri, 24 Jul 2020 11:32:10 -0400 Received: from mail.katalix.com ([3.9.82.81]:56780 "EHLO mail.katalix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726731AbgGXPcI (ORCPT ); Fri, 24 Jul 2020 11:32:08 -0400 Received: from localhost.localdomain (82-69-49-219.dsl.in-addr.zen.co.uk [82.69.49.219]) (Authenticated sender: tom) by mail.katalix.com (Postfix) with ESMTPSA id 3B7638AD91; Fri, 24 Jul 2020 16:32:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=katalix.com; s=mail; t=1595604726; bh=UGdcFcBcExYebN3wgku6Bb9sSHP4xnNyokr++4TslJs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:From; z=From:=20Tom=20Parkin=20|To:=20netdev@vger.ke rnel.org|Cc:=20jchapman@katalix.com,=0D=0A=09Tom=20Parkin=20|Subject:=20[PATCH=209/9]=20l2tp:=20WARN_ON=20rathe r=20than=20BUG_ON=20in=20l2tp_session_free|Date:=20Fri,=2024=20Jul =202020=2016:31:57=20+0100|Message-Id:=20<20200724153157.9366-10-t parkin@katalix.com>|In-Reply-To:=20<20200724153157.9366-1-tparkin@ katalix.com>|References:=20<20200724153157.9366-1-tparkin@katalix. com>; b=UBmw4oidZcilTRIxl9b3BRBGqyeWwSxnHq4Xd/kmZCxXKtHbDvrPifRw+p6qYM96J pl+e2bVR53o/jbdn9YFuf+UJxysEK+mnKvRFFl+9fElNpc7/858f/JzKVtpMRBoQrD RXL7+jJJGpyhyA2meYdljG7yrWDDpmjpd0c18m3XRsOyL0KMI4YMMIliP1/qFLvSBl sw29l4IePTxgBIq70ND/ccZMMM5LnP7RwWAotMkuew49kc4ZVVt9pI3D4FDRHNGXkt SJgxSGK3FWQWnLypgvKAFGLUqp7sCX4wsFrfTOqurC99jOutueLd1dYw5qUWAzlAfo exzJpn9EjwAAw== From: Tom Parkin To: netdev@vger.kernel.org Cc: jchapman@katalix.com, Tom Parkin Subject: [PATCH 9/9] l2tp: WARN_ON rather than BUG_ON in l2tp_session_free Date: Fri, 24 Jul 2020 16:31:57 +0100 Message-Id: <20200724153157.9366-10-tparkin@katalix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724153157.9366-1-tparkin@katalix.com> References: <20200724153157.9366-1-tparkin@katalix.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org l2tp_session_free called BUG_ON if the tunnel magic feather value wasn't correct. The intent of this was to catch lifetime bugs; for example early tunnel free due to incorrect use of reference counts. Since the tunnel magic feather being wrong indicates either early free or structure corruption, we can avoid doing more damage by simply leaving the tunnel structure alone. If the tunnel refcount isn't dropped when it should be, the tunnel instance will remain in the kernel, resulting in the tunnel structure and socket leaking. Signed-off-by: Tom Parkin --- net/l2tp/l2tp_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 50548c61b91e..e723828e458b 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1564,10 +1564,12 @@ void l2tp_session_free(struct l2tp_session *session) struct l2tp_tunnel *tunnel = session->tunnel; if (tunnel) { - BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); + if (WARN_ON(tunnel->magic != L2TP_TUNNEL_MAGIC)) + goto out; l2tp_tunnel_dec_refcount(tunnel); } +out: kfree(session); } EXPORT_SYMBOL_GPL(l2tp_session_free);