Skip to contentSkip to conversation

net: mctp: purge receive queues on sk destruction

PATCH Applied Jeremy Kerr 3 participants 3 messages Jan 26, 2023 – Jan 28, 2023

Subsystems (3)
lore
Share & tools
lore

Jeremy Kerr

author maintainer
#0 lore raw

PATCH 1/1 net: mctp: purge receive queues on sk destruction

We may have pending skbs in the receive queue when the sk is being destroyed; add a destructor to purge the queue.

MCTP doesn't use the error queue, so only the receive_queue is purged.

Fixes 833ef3b91de6 ("mctp: Populate socket implementation")
---
 net/mctp/af_mctp.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/mctp/af_mctp.c +6 -0
index 45bbe3e54cc2..3150f3f0c872 100644
@@ -587,6 +587,11 @@ static void mctp_sk_unhash(struct sock *sk)
 	del_timer_sync(&msk->key_expiry);
 }
 
+static void mctp_sk_destruct(struct sock *sk)
+{
+	skb_queue_purge(&sk->sk_receive_queue);
+}
+
 static struct proto mctp_proto = {
 	.name		= "MCTP",
 	.owner		= THIS_MODULE,
@@ -623,6 +628,7 @@ static int mctp_pf_create(struct net *net, struct socket *sock,
 		return -ENOMEM;
 
 	sock_init_data(sock, sk);
+	sk->sk_destruct = mctp_sk_destruct;
 
 	rc = 0;
 	if (sk->sk_prot->init)
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Jeremy Kerr

We may have pending skbs in the receive queue when the sk is being destroyed; add a destructor to purge the queue.

MCTP doesn't use the error queue, so only the receive_queue is purged.

Fixes 833ef3b91de6 ("mctp: Populate socket implementation")
---
 net/mctp/af_mctp.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/mctp/af_mctp.c +6 -1
index 45bbe3e54cc2..3150f3f0c872 100644
@@ -587,6 +587,11 @@ static void mctp_sk_unhash(struct sock *sk)
        del_timer_sync(&msk->key_expiry);
 }
 
+static void mctp_sk_destruct(struct sock *sk)
+{
+       skb_queue_purge(&sk->sk_receive_queue);
+}
+
 static struct proto mctp_proto = {
        .name           = "MCTP",
        .owner          = THIS_MODULE,
@@ -623,6 +628,7 @@ static int mctp_pf_create(struct net *net, struct socket *sock,
                return -ENOMEM;
 
        sock_init_data(sock, sk);
+       sk->sk_destruct = mctp_sk_destruct;
 
        rc = 0;
        if (sk->sk_prot->init)
--
Quoted 2 lines

2.35.1

Looks good to me.

#2 lore raw
In reply to Jeremy Kerr
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 26 Jan 2023 14:45:51 +0800 you wrote:

We may have pending skbs in the receive queue when the sk is being destroyed; add a destructor to purge the queue.

MCTP doesn't use the error queue, so only the receive_queue is purged.

Fixes 833ef3b91de6 ("mctp: Populate socket implementation")

[...]

Here is the summary with links:
- [net] net: mctp: purge receive queues on sk destruction

    https://git.kernel.org/netdev/net/c/60bd1d9008a5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html