netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Eric Biggers <ebiggers@google.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 20/59] llc: fix sk_buff refcounting in llc_conn_state_process()
Date: Sat, 26 Oct 2019 09:18:31 -0400	[thread overview]
Message-ID: <20191026131910.3435-20-sashal@kernel.org> (raw)
In-Reply-To: <20191026131910.3435-1-sashal@kernel.org>

From: Eric Biggers <ebiggers@google.com>

[ Upstream commit 36453c852816f19947ca482a595dffdd2efa4965 ]

If llc_conn_state_process() sees that llc_conn_service() put the skb on
a list, it will drop one fewer references to it.  This is wrong because
the current behavior is that llc_conn_service() never consumes a
reference to the skb.

The code also makes the number of skb references being dropped
conditional on which of ind_prim and cfm_prim are nonzero, yet neither
of these affects how many references are *acquired*.  So there is extra
code that tries to fix this up by sometimes taking another reference.

Remove the unnecessary/broken refcounting logic and instead just add an
skb_get() before the only two places where an extra reference is
actually consumed.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/llc/llc_conn.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index 0b0c6f12153b0..a79b739eb2236 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -64,12 +64,6 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 	struct llc_sock *llc = llc_sk(skb->sk);
 	struct llc_conn_state_ev *ev = llc_conn_ev(skb);
 
-	/*
-	 * We have to hold the skb, because llc_conn_service will kfree it in
-	 * the sending path and we need to look at the skb->cb, where we encode
-	 * llc_conn_state_ev.
-	 */
-	skb_get(skb);
 	ev->ind_prim = ev->cfm_prim = 0;
 	/*
 	 * Send event to state machine
@@ -77,21 +71,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 	rc = llc_conn_service(skb->sk, skb);
 	if (unlikely(rc != 0)) {
 		printk(KERN_ERR "%s: llc_conn_service failed\n", __func__);
-		goto out_kfree_skb;
-	}
-
-	if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
-		/* indicate or confirm not required */
-		if (!skb->next)
-			goto out_kfree_skb;
 		goto out_skb_put;
 	}
 
-	if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
-		skb_get(skb);
-
 	switch (ev->ind_prim) {
 	case LLC_DATA_PRIM:
+		skb_get(skb);
 		llc_save_primitive(sk, skb, LLC_DATA_PRIM);
 		if (unlikely(sock_queue_rcv_skb(sk, skb))) {
 			/*
@@ -108,6 +93,7 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 		 * skb->sk pointing to the newly created struct sock in
 		 * llc_conn_handler. -acme
 		 */
+		skb_get(skb);
 		skb_queue_tail(&sk->sk_receive_queue, skb);
 		sk->sk_state_change(sk);
 		break;
@@ -123,7 +109,6 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 				sk->sk_state_change(sk);
 			}
 		}
-		kfree_skb(skb);
 		sock_put(sk);
 		break;
 	case LLC_RESET_PRIM:
@@ -132,14 +117,11 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 		 * RESET is not being notified to upper layers for now
 		 */
 		printk(KERN_INFO "%s: received a reset ind!\n", __func__);
-		kfree_skb(skb);
 		break;
 	default:
-		if (ev->ind_prim) {
+		if (ev->ind_prim)
 			printk(KERN_INFO "%s: received unknown %d prim!\n",
 				__func__, ev->ind_prim);
-			kfree_skb(skb);
-		}
 		/* No indication */
 		break;
 	}
@@ -181,15 +163,12 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
 		printk(KERN_INFO "%s: received a reset conf!\n", __func__);
 		break;
 	default:
-		if (ev->cfm_prim) {
+		if (ev->cfm_prim)
 			printk(KERN_INFO "%s: received unknown %d prim!\n",
 					__func__, ev->cfm_prim);
-			break;
-		}
-		goto out_skb_put; /* No confirmation */
+		/* No confirmation */
+		break;
 	}
-out_kfree_skb:
-	kfree_skb(skb);
 out_skb_put:
 	kfree_skb(skb);
 	return rc;
-- 
2.20.1


  parent reply	other threads:[~2019-10-26 13:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-26 13:18 [PATCH AUTOSEL 4.19 01/59] tools: bpf: Use !building_out_of_srctree to determine srctree Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 03/59] mac80211_hwsim: fix incorrect dev_alloc_name failure goto Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 06/59] net: dsa: b53: Do not clear existing mirrored port mask Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 07/59] net: stmmac: gmac4+: Not all Unicast addresses may be available Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 10/59] rxrpc: Fix call ref leak Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 11/59] rxrpc: Fix trace-after-put looking at the put peer record Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 12/59] rxrpc: Fix trace-after-put looking at the put connection record Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 13/59] rxrpc: Fix trace-after-put looking at the put call record Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 14/59] rxrpc: rxrpc_peer needs to hold a ref on the rxrpc_local record Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 15/59] mac80211: accept deauth frames in IBSS mode Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 16/59] mac80211: fix scan when operating on DFS channels in ETSI domains Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 17/59] llc: fix sk_buff leak in llc_sap_state_process() Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 18/59] llc: fix sk_buff leak in llc_conn_service() Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 19/59] llc: fix another potential sk_buff leak in llc_ui_sendmsg() Sasha Levin
2019-10-26 13:18 ` Sasha Levin [this message]
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 21/59] NFC: pn533: fix use-after-free and memleaks Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 22/59] ip6erspan: remove the incorrect mtu limit for ip6erspan Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 23/59] iwlwifi: dbg_ini: fix memory leak in alloc_sgtable Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 24/59] iwlwifi: pcie: fix memory leaks in iwl_pcie_ctxt_info_gen3_init Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 25/59] iwlwifi: exclude GEO SAR support for 3168 Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 27/59] net: stmmac: fix length of PTP clock's name string Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 28/59] net: stmmac: fix disabling flexible PPS output Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 29/59] bonding: fix potential NULL deref in bond_update_slave_arr Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 32/59] act_mirred: Fix mirred_init_module error handling Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 33/59] net: usb: qmi_wwan: add Telit 0x1050 composition Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 34/59] net: avoid possible false sharing in sk_leave_memory_pressure() Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 35/59] net: add {READ|WRITE}_ONCE() annotations on ->rskq_accept_head Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 36/59] net/smc: receive returns without data Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 37/59] net/smc: receive pending data after RCV_SHUTDOWN Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 39/59] vhost/test: stop device before reset Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 40/59] net/ibmvnic: Fix EOI when running in XIVE mode Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 47/59] net: i82596: fix dma_alloc_attr for sni_82596 Sasha Levin
2019-10-26 13:18 ` [PATCH AUTOSEL 4.19 48/59] net: bcmgenet: Fix RGMII_MODE_EN value for GENET v1/2/3 Sasha Levin
2019-10-26 13:19 ` [PATCH AUTOSEL 4.19 49/59] net: usb: sr9800: fix uninitialized local variable Sasha Levin
2019-10-26 13:19 ` [PATCH AUTOSEL 4.19 51/59] net: stmmac: disable/enable ptp_ref_clk in suspend/resume flow Sasha Levin
2019-10-26 13:19 ` [PATCH AUTOSEL 4.19 52/59] usb: hso: obey DMA rules in tiocmget Sasha Levin
2019-10-26 13:19 ` [PATCH AUTOSEL 4.19 54/59] net: stmmac: fix argument to stmmac_pcs_ctrl_ane() Sasha Levin
2019-10-26 13:19 ` [PATCH AUTOSEL 4.19 56/59] net: usb: lan78xx: Connect PHY before registering MAC Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191026131910.3435-20-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ebiggers@google.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).