Netdev List
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: davem@davemloft.net
Cc: edumazet@google.com, horms@kernel.org, kuba@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	pabeni@redhat.com, tom@herbertland.com,
	Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] kcm: Fix socket use-after-free in kcm_unattach()
Date: Thu, 17 Sep 2026 16:36:56 +0000	[thread overview]
Message-ID: <20260917163656.2162621-1-vulab@iscas.ac.cn> (raw)

In the unreserved path of kcm_unattach(), the reference held by the
psock on the underlying TCP socket is dropped with sock_put() before
the socket file is released with fput(csk->sk_socket->file) and before
release_sock() is called at the end of the function. If that was the
last reference on the socket, both uses access freed memory.

Drop the socket reference only after the last use of the socket: move
the fput() before the sock_put() and release the socket lock before
dropping the final reference.

Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 net/kcm/kcmsock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index 3912e75079f5..b3838a19f0a7 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -1457,9 +1457,11 @@ static void kcm_unattach(struct kcm_psock *psock)
 		mux->psocks_cnt--;
 		spin_unlock_bh(&mux->lock);
 
-		sock_put(csk);
 		fput(csk->sk_socket->file);
 		kmem_cache_free(kcm_psockp, psock);
+		release_sock(csk);
+		sock_put(csk);
+		return;
 	}
 
 	release_sock(csk);
-- 
2.34.1


             reply	other threads:[~2026-09-17 16:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 16:36 Wentao Liang [this message]
2026-09-21 17:24 ` [PATCH] kcm: Fix socket use-after-free in kcm_unattach() netdev-bot+sashiko

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=20260917163656.2162621-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@herbertland.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