From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Tuong Lien <tuong.t.lien@dektech.com.au>,
Ying Xue <ying.xue@windriver.com>,
Jon Maloy <jon.maloy@ericsson.com>,
"David S . Miller" <davem@davemloft.net>,
Sasha Levin <sashal@kernel.org>,
netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net
Subject: [PATCH AUTOSEL 5.4 078/330] tipc: fix link overflow issue at socket shutdown
Date: Thu, 17 Sep 2020 21:56:58 -0400 [thread overview]
Message-ID: <20200918020110.2063155-78-sashal@kernel.org> (raw)
In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org>
From: Tuong Lien <tuong.t.lien@dektech.com.au>
[ Upstream commit 49afb806cb650dd1f06f191994f3aa657d264009 ]
When a socket is suddenly shutdown or released, it will reject all the
unreceived messages in its receive queue. This applies to a connected
socket too, whereas there is only one 'FIN' message required to be sent
back to its peer in this case.
In case there are many messages in the queue and/or some connections
with such messages are shutdown at the same time, the link layer will
easily get overflowed at the 'TIPC_SYSTEM_IMPORTANCE' backlog level
because of the message rejections. As a result, the link will be taken
down. Moreover, immediately when the link is re-established, the socket
layer can continue to reject the messages and the same issue happens...
The commit refactors the '__tipc_shutdown()' function to only send one
'FIN' in the situation mentioned above. For the connectionless case, it
is unavoidable but usually there is no rejections for such socket
messages because they are 'dest-droppable' by default.
In addition, the new code makes the other socket states clear
(e.g.'TIPC_LISTEN') and treats as a separate case to avoid misbehaving.
Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/tipc/socket.c | 53 ++++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 21 deletions(-)
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 5318bb6611abc..592c6b19aca72 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -260,12 +260,12 @@ static void tipc_sk_respond(struct sock *sk, struct sk_buff *skb, int err)
*
* Caller must hold socket lock
*/
-static void tsk_rej_rx_queue(struct sock *sk)
+static void tsk_rej_rx_queue(struct sock *sk, int error)
{
struct sk_buff *skb;
while ((skb = __skb_dequeue(&sk->sk_receive_queue)))
- tipc_sk_respond(sk, skb, TIPC_ERR_NO_PORT);
+ tipc_sk_respond(sk, skb, error);
}
static bool tipc_sk_connected(struct sock *sk)
@@ -515,34 +515,45 @@ static void __tipc_shutdown(struct socket *sock, int error)
/* Remove any pending SYN message */
__skb_queue_purge(&sk->sk_write_queue);
- /* Reject all unreceived messages, except on an active connection
- * (which disconnects locally & sends a 'FIN+' to peer).
- */
- while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) {
- if (TIPC_SKB_CB(skb)->bytes_read) {
- kfree_skb(skb);
- continue;
- }
- if (!tipc_sk_type_connectionless(sk) &&
- sk->sk_state != TIPC_DISCONNECTING) {
- tipc_set_sk_state(sk, TIPC_DISCONNECTING);
- tipc_node_remove_conn(net, dnode, tsk->portid);
- }
- tipc_sk_respond(sk, skb, error);
+ /* Remove partially received buffer if any */
+ skb = skb_peek(&sk->sk_receive_queue);
+ if (skb && TIPC_SKB_CB(skb)->bytes_read) {
+ __skb_unlink(skb, &sk->sk_receive_queue);
+ kfree_skb(skb);
}
- if (tipc_sk_type_connectionless(sk))
+ /* Reject all unreceived messages if connectionless */
+ if (tipc_sk_type_connectionless(sk)) {
+ tsk_rej_rx_queue(sk, error);
return;
+ }
- if (sk->sk_state != TIPC_DISCONNECTING) {
+ switch (sk->sk_state) {
+ case TIPC_CONNECTING:
+ case TIPC_ESTABLISHED:
+ tipc_set_sk_state(sk, TIPC_DISCONNECTING);
+ tipc_node_remove_conn(net, dnode, tsk->portid);
+ /* Send a FIN+/- to its peer */
+ skb = __skb_dequeue(&sk->sk_receive_queue);
+ if (skb) {
+ __skb_queue_purge(&sk->sk_receive_queue);
+ tipc_sk_respond(sk, skb, error);
+ break;
+ }
skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode,
tsk_own_node(tsk), tsk_peer_port(tsk),
tsk->portid, error);
if (skb)
tipc_node_xmit_skb(net, skb, dnode, tsk->portid);
- tipc_node_remove_conn(net, dnode, tsk->portid);
- tipc_set_sk_state(sk, TIPC_DISCONNECTING);
+ break;
+ case TIPC_LISTEN:
+ /* Reject all SYN messages */
+ tsk_rej_rx_queue(sk, error);
+ break;
+ default:
+ __skb_queue_purge(&sk->sk_receive_queue);
+ break;
}
}
@@ -2564,7 +2575,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
* Reject any stray messages received by new socket
* before the socket lock was taken (very, very unlikely)
*/
- tsk_rej_rx_queue(new_sk);
+ tsk_rej_rx_queue(new_sk, TIPC_ERR_NO_PORT);
/* Connect new socket to it's peer */
tipc_sk_finish_conn(new_tsock, msg_origport(msg), msg_orignode(msg));
--
2.25.1
next prev parent reply other threads:[~2020-09-18 3:10 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200918020110.2063155-1-sashal@kernel.org>
2020-09-18 1:55 ` [PATCH AUTOSEL 5.4 011/330] ath10k: fix array out-of-bounds access Sasha Levin
2020-09-18 1:55 ` [PATCH AUTOSEL 5.4 012/330] ath10k: fix memory leak for tpc_stats_final Sasha Levin
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 031/330] net: silence data-races on sk_backlog.tail Sasha Levin
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 037/330] ice: Fix to change Rx/Tx ring descriptor size via ethtool with DCBx Sasha Levin
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 058/330] mt76: do not use devm API for led classdev Sasha Levin
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 059/330] mt76: add missing locking around ampdu action Sasha Levin
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 061/330] SUNRPC: Capture completion of all RPC tasks Sasha Levin
2020-09-18 1:56 ` Sasha Levin [this message]
2020-09-18 1:56 ` [PATCH AUTOSEL 5.4 079/330] vcc_seq_next should increase position index Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 080/330] neigh_stat_seq_next() " Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 081/330] rt_cpu_seq_next " Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 082/330] ipv6_route_seq_next " Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 090/330] sctp: move trace_sctp_probe_path into sctp_outq_sack Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 107/330] ar5523: Add USB ID of SMCWUSBT-G2 wireless adapter Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 111/330] Bluetooth: Fix refcount use-after-free issue Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 114/330] Bluetooth: prefetch channel before killing sock Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 117/330] skbuff: fix a data race in skb_queue_len() Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 129/330] mt76: clear skb pointers from rx aggregation reorder buffer during cleanup Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 130/330] mt76: fix handling full tx queues in mt76_dma_tx_queue_skb_raw Sasha Levin
2020-09-18 1:57 ` [PATCH AUTOSEL 5.4 139/330] bpf: Remove recursion prevention from rcu free callback Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 145/330] iavf: use tc_cls_can_offload_and_chain0() instead of chain check Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 151/330] Bluetooth: guard against controllers sending zero'd events Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 166/330] ath10k: use kzalloc to read for ath10k_sdio_hif_diag_read Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 168/330] Bluetooth: L2CAP: handle l2cap config request during open state Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 189/330] r8169: improve RTL8168b FIFO overflow workaround Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 194/330] net: axienet: Convert DMA error handler to a work queue Sasha Levin
2020-09-18 1:58 ` [PATCH AUTOSEL 5.4 195/330] net: axienet: Propagate failure of DMA descriptor setup Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 208/330] brcmfmac: Fix double freeing in the fmac usb data path Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 213/330] SUNRPC: Fix a potential buffer overflow in 'svc_print_xprts()' Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 214/330] svcrdma: Fix leak of transport addresses Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 215/330] netfilter: nf_tables: silence a RCU-list warning in nft_table_lookup() Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 229/330] SUNRPC: Don't start a timer on an already queued rpc task Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 244/330] net: openvswitch: use u64 for meter bucket Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 250/330] dpaa2-eth: fix error return code in setup_dpni() Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 252/330] devlink: Fix reporter's recovery condition Sasha Levin
2020-09-18 1:59 ` [PATCH AUTOSEL 5.4 253/330] atm: fix a memory leak of vcc->user_back Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 261/330] Bluetooth: Handle Inquiry Cancel error after Inquiry Complete Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 264/330] tipc: fix memory leak in service subscripting Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 271/330] svcrdma: Fix backchannel return code Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 280/330] e1000: Do not perform reset in reset_task if we are already down Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 296/330] perf metricgroup: Free metric_events on error Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 300/330] wlcore: fix runtime pm imbalance in wl1271_tx_work Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 301/330] wlcore: fix runtime pm imbalance in wlcore_regdomain_config Sasha Levin
2020-09-18 2:00 ` [PATCH AUTOSEL 5.4 315/330] mac80211: skip mpath lookup also for control port tx Sasha Levin
2020-09-18 2:01 ` [PATCH AUTOSEL 5.4 324/330] mt76: fix LED link time failure Sasha Levin
2020-09-18 2:01 ` [PATCH AUTOSEL 5.4 329/330] net: openvswitch: use div_u64() for 64-by-32 divisions 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=20200918020110.2063155-78-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=davem@davemloft.net \
--cc=jon.maloy@ericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tuong.t.lien@dektech.com.au \
--cc=ying.xue@windriver.com \
/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).