FAILED: patch "[PATCH] ksmbd: fix use-after-free in __smb2_lease_break_noti()" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 21a4e47578d44c6b37c4fc4aba8ed7cc8dbb13de
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025042110-bovine-triangle-a138@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 21a4e47578d44c6b37c4fc4aba8ed7cc8dbb13de Mon Sep 17 00:00:00 2001
From: Namjae Jeon <[email protected]>
Date: Fri, 11 Apr 2025 15:19:46 +0900
Subject: [PATCH] ksmbd: fix use-after-free in __smb2_lease_break_noti()
Move tcp_transport free to ksmbd_conn_free. If ksmbd connection is referenced when ksmbd server thread terminates, It will not be freed, but conn->tcp_transport is freed. __smb2_lease_break_noti can be performed asynchronously when the connection is disconnected. __smb2_lease_break_noti calls ksmbd_conn_write, which can cause use-after-free
when conn->ksmbd_transport is already freed.
fs/smb/server/connection.c +3 -1
@@ -39,8 +39,10 @@ void ksmbd_conn_free(struct ksmbd_conn *conn)xa_destroy (&conn->sessions);kvfree (conn->request_buf);kfree (conn->preauth_info); -if (atomic_dec_and_test (&conn->refcnt)) +if (atomic_dec_and_test (&conn->refcnt)) { +ksmbd_free_transport (conn->transport);kfree (conn); + } }/**
fs/smb/server/transport_tcp.c +9 -5
@@ -93,15 +93,19 @@ static struct tcp_transport *alloc_transport(struct socket *client_sk)return t; } +void ksmbd_free_transport (struct ksmbd_transport *kt) +{ +struct tcp_transport *t =TCP_TRANS (kt); + +sock_release (t->sock); +kfree (t->iov); +kfree (t); +} +static void free_transport (struct tcp_transport *t) {kernel_sock_shutdown (t->sock,SHUT_RDWR ); -sock_release (t->sock); - t->sock =NULL ; -ksmbd_conn_free (KSMBD_TRANS (t)->conn); -kfree (t->iov); -kfree (t); }/**
fs/smb/server/transport_tcp.h +1 -0
@@ -8,6 +8,7 @@int ksmbd_tcp_set_interfaces (char *ifc_list,int ifc_list_sz);struct interface *ksmbd_find_netdev_name_iface_list (char *netdev_name); +void ksmbd_free_transport (struct ksmbd_transport *kt);int ksmbd_tcp_init (void );void ksmbd_tcp_destroy (void );