FAILED: patch "[PATCH] rxrpc: serialize kernel accept preallocation with socket" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x dc175389b18c29a5303ee83169ec653adfae3e17
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072052-carve-yelp-e5c8@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From dc175389b18c29a5303ee83169ec653adfae3e17 Mon Sep 17 00:00:00 2001
From: Li Daming <[email protected]>
Date: Tue, 9 Jun 2026 15:09:09 +0100
Subject: [PATCH] rxrpc: serialize kernel accept preallocation with socket
teardown
rxrpc_kernel_charge_accept() reads rx->backlog without any socket/backlog synchronization and passes that raw pointer into rxrpc_service_prealloc_one(). A concurrent rxrpc_discard_prealloc() sets rx->backlog = NULL and frees the backlog rings, so a kernel preallocation worker can keep using a freed struct rxrpc_backlog while updating *_backlog_head/tail and array slots.
Serialize the state check and backlog lookup with the socket lock, and reject kernel preallocation once teardown has disabled listening or discarded the service backlog.
net/rxrpc/call_accept.c +19 -6
@@ -471,13 +471,26 @@ int rxrpc_kernel_charge_accept(struct socket *sock, rxrpc_notify_rx_t notify_rx, unsigned long user_call_ID, gfp_t gfp, unsigned int debug_id) { - struct rxrpc_sock *rx = rxrpc_sk(sock->sk); -struct rxrpc_backlog *b = rx->backlog; + struct rxrpc_backlog *b; +struct rxrpc_sock *rx; +struct sock *sk; +int ret; -if (sock->sk->sk_state ==RXRPC_CLOSE ) -return -ESHUTDOWN ; + sk = sock->sk; + rx =rxrpc_sk (sk); -return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, - gfp, debug_id); +lock_sock (sk); +if (sk->sk_state !=RXRPC_SERVER_LISTENING || !rx->backlog) { + ret = -ESHUTDOWN ; + goto out; + } + + b = rx->backlog; + ret =rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, + gfp, debug_id); + +out: +release_sock (sk); +return ret; }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
Sasha Levin
maintainerPATCH 1/2 rxrpc: Pull out certain app callback funcs into an ops table
From: David Howells <[email protected]>
[ Upstream commit 23738cc8048322cf324f330cd697380fb3455da5 ]
A number of functions separately furnish an AF_RXRPC socket with callback function pointers into a kernel app (such as the AFS filesystem) that is using it. Replace most of these with an ops table for the entire socket. This makes it easier to add more callback functions.
Note that the call incoming data processing callback is retaind as that gets set to different things, depending on the type of op.
Stable-dep-of: dc175389b18c ("rxrpc: serialize kernel accept preallocation with socket teardown")
--- fs/afs/rxrpc.c | 11 ++++++++--- include/net/af_rxrpc.h | 25 +++++++++++++++---------- net/rxrpc/af_rxrpc.c | 20 ++++++++------------ net/rxrpc/ar-internal.h | 3 +-- net/rxrpc/call_accept.c | 34 ++++++++++++++++------------------ net/rxrpc/rxperf.c | 10 +++++++--- 6 files changed, 55 insertions(+), 48 deletions(-)
fs/afs/rxrpc.c +8 -3
@@ -24,8 +24,15 @@ static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsignedstatic void afs_process_async_call (struct work_struct *);static void afs_rx_new_call (struct sock *,struct rxrpc_call *,unsigned long );static void afs_rx_discard_new_call (struct rxrpc_call *,unsigned long ); +static void afs_rx_attach (struct rxrpc_call *rxcall,unsigned long user_call_ID);static int afs_deliver_cm_op_id (struct afs_call *); +static const struct rxrpc_kernel_ops afs_rxrpc_callback_ops = { + .notify_new_call = afs_rx_new_call, + .discard_new_call = afs_rx_discard_new_call, + .user_attach_call = afs_rx_attach, +}; +/* asynchronous incoming call initial processing */ static const struct afs_call_type afs_RXCMxxxx = { .name ="CB.xxxx" ,
@@ -84,8 +91,7 @@ int afs_open_socket(struct afs_net *net)* it sends back to us. */ -rxrpc_kernel_new_call_notification (socket, afs_rx_new_call, - afs_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &afs_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
@@ -752,7 +758,6 @@ void afs_charge_preallocation(struct work_struct *work)if (rxrpc_kernel_charge_accept (net->socket, afs_wake_up_async_call, - afs_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
include/net/af_rxrpc.h +15 -10
@@ -29,18 +29,23 @@ enum rxrpc_interruptibility {*/ extern atomic_t rxrpc_debug_id; +/* +* Operations table for rxrpc to call out to a kernel application (e.g. kAFS). +*/ +struct rxrpc_kernel_ops { +void (*notify_new_call)(struct sock *sk,struct rxrpc_call *call, +unsigned long user_call_ID); +void (*discard_new_call)(struct rxrpc_call *call,unsigned long user_call_ID); +void (*user_attach_call)(struct rxrpc_call *call,unsigned long user_call_ID); +}; +typedef void (*rxrpc_notify_rx_t )(struct sock *,struct rxrpc_call *,unsigned long );typedef void (*rxrpc_notify_end_tx_t )(struct sock *,struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_notify_new_call_t )(struct sock *,struct rxrpc_call *, -unsigned long ); -typedef void (*rxrpc_discard_new_call_t )(struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_user_attach_call_t )(struct rxrpc_call *,unsigned long ); -void rxrpc_kernel_new_call_notification (struct socket *, -rxrpc_notify_new_call_t , -rxrpc_discard_new_call_t ); +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops); struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, struct rxrpc_peer *peer, struct key *key,
@@ -70,9 +75,9 @@ struct rxrpc_peer *rxrpc_kernel_get_call_peer(struct socket *sock, struct rxrpc_const struct sockaddr_rxrpc *rxrpc_kernel_remote_srx (const struct rxrpc_peer *peer);const struct sockaddr *rxrpc_kernel_remote_addr (const struct rxrpc_peer *peer);unsigned int rxrpc_kernel_get_srtt (const struct rxrpc_peer *); -int rxrpc_kernel_charge_accept (struct socket *,rxrpc_notify_rx_t , -rxrpc_user_attach_call_t ,unsigned long ,gfp_t , -unsigned int ); +int rxrpc_kernel_charge_accept (struct socket *sock,rxrpc_notify_rx_t notify_rx, +unsigned long user_call_ID,gfp_t gfp, +unsigned int debug_id);void rxrpc_kernel_set_tx_length (struct socket *,struct rxrpc_call *,s64 );bool rxrpc_kernel_check_life (const struct socket *,const struct rxrpc_call *);u32 rxrpc_kernel_get_epoch (struct socket *,struct rxrpc_call *);
net/rxrpc/af_rxrpc.c +8 -12
@@ -464,24 +464,20 @@ u32 rxrpc_kernel_get_epoch(struct socket *sock, struct rxrpc_call *call)EXPORT_SYMBOL (rxrpc_kernel_get_epoch);/** -* rxrpc_kernel_new_call_notification - Get notifications of new calls -* @sock: The socket to intercept received messages on -* @notify_new_call: Function to be called when new calls appear -* @discard_new_call: Function to discard preallocated calls +* rxrpc_kernel_set_notifications - Set table of callback operations +* @sock: The socket to install table upon +* @app_ops: Callback operation table to set * -* Allow a kernel service to be given notifications about new calls. +* Allow a kernel service to set a table of event notifications on a socket. */ -void rxrpc_kernel_new_call_notification ( -struct socket *sock, -rxrpc_notify_new_call_t notify_new_call, -rxrpc_discard_new_call_t discard_new_call) +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops) {struct rxrpc_sock *rx =rxrpc_sk (sock->sk); - rx->notify_new_call = notify_new_call; - rx->discard_new_call = discard_new_call; + rx->app_ops = app_ops; } -EXPORT_SYMBOL (rxrpc_kernel_new_call_notification); +EXPORT_SYMBOL (rxrpc_kernel_set_notifications);/** * rxrpc_kernel_set_max_life - Set maximum lifespan on a call
net/rxrpc/ar-internal.h +1 -2
@@ -142,8 +142,7 @@ struct rxrpc_backlog {struct rxrpc_sock {/* WARNING: sk has to be the first member */ struct sock sk; -rxrpc_notify_new_call_t notify_new_call;/* Func to notify of new call */ -rxrpc_discard_new_call_t discard_new_call;/* Func to discard a new call */ +const struct rxrpc_kernel_ops *app_ops;/* Table of kernel app notification funcs */ struct rxrpc_local *local;/* local endpoint */ struct rxrpc_backlog *backlog;/* Preallocation for services */ spinlock_t incoming_lock;/* Incoming call vs service shutdown lock */
net/rxrpc/call_accept.c +16 -18
@@ -34,7 +34,6 @@ static void rxrpc_dummy_notify(struct sock *sk, struct rxrpc_call *call,static int rxrpc_service_prealloc_one (struct rxrpc_sock *rx,struct rxrpc_backlog *b,rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -123,9 +122,10 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx, call->user_call_ID = user_call_ID; call->notify_rx = notify_rx; -if (user_attach_call) { +if (rx->app_ops && + rx->app_ops->user_attach_call) {rxrpc_get_call (call, rxrpc_call_get_kernel_service); -user_attach_call (call, user_call_ID); + rx->app_ops->user_attach_call (call, user_call_ID); }rxrpc_get_call (call, rxrpc_call_get_userid);
@@ -221,9 +221,10 @@ void rxrpc_discard_prealloc(struct rxrpc_sock *rx)struct rxrpc_call *call = b->call_backlog[tail];rxrpc_see_call (call, rxrpc_call_see_discard);rcu_assign_pointer (call->socket, rx); -if (rx->discard_new_call) { +if (rx->app_ops && + rx->app_ops->discard_new_call) {_debug ("discard %lx" , call->user_call_ID); - rx->discard_new_call (call, call->user_call_ID); + rx->app_ops->discard_new_call (call, call->user_call_ID);if (call->notify_rx) call->notify_rx = rxrpc_dummy_notify;rxrpc_put_call (call, rxrpc_call_put_kernel);
@@ -392,8 +393,9 @@ bool rxrpc_new_incoming_call(struct rxrpc_local *local,rxrpc_incoming_call (rx, call, skb); conn = call->conn; -if (rx->notify_new_call) - rx->notify_new_call (&rx->sk, call, call->user_call_ID); +if (rx->app_ops && + rx->app_ops->notify_new_call) + rx->app_ops->notify_new_call (&rx->sk, call, call->user_call_ID);spin_lock (&conn->state_lock);if (conn->state ==RXRPC_CONN_SERVICE_UNSECURED ) {
@@ -445,8 +447,7 @@ int rxrpc_user_charge_accept(struct rxrpc_sock *rx, unsigned long user_call_ID)if (rx->sk.sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b,NULL ,NULL , user_call_ID, -GFP_KERNEL , +return rxrpc_service_prealloc_one (rx, b,NULL , user_call_ID,GFP_KERNEL ,atomic_inc_return (&rxrpc_debug_id)); }
@@ -454,20 +455,18 @@ int rxrpc_user_charge_accept(struct rxrpc_sock *rx, unsigned long user_call_ID)* rxrpc_kernel_charge_accept - Charge up socket with preallocated calls * @sock: The socket on which to preallocate * @notify_rx: Event notification function for the call -* @user_attach_call: Func to attach call to user_call_ID * @user_call_ID: The tag to attach to the preallocated call * @gfp: The allocation conditions. * @debug_id: The tracing debug ID. * -* Charge up the socket with preallocated calls, each with a user ID. A -* function should be provided to effect the attachment from the user's side. -* The user is given a ref to hold on the call. +* Charge up the socket with preallocated calls, each with a user ID. The +* ->user_attach_call() callback function should be provided to effect the +* attachment from the user's side. The user is given a ref to hold on the +* call. * * Note that the call may be come connected before this function returns. */ -int rxrpc_kernel_charge_accept (struct socket *sock, -rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call, +int rxrpc_kernel_charge_accept (struct socket *sock,rxrpc_notify_rx_t notify_rx,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -477,8 +476,7 @@ int rxrpc_kernel_charge_accept(struct socket *sock,if (sock->sk->sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b, notify_rx, - user_attach_call, user_call_ID, +return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, gfp, debug_id); }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
net/rxrpc/rxperf.c +7 -3
@@ -136,6 +136,12 @@ static void rxperf_notify_end_reply_tx(struct sock *sock, RXPERF_CALL_SV_AWAIT_ACK); } +static const struct rxrpc_kernel_ops rxperf_rxrpc_callback_ops = { + .notify_new_call = rxperf_rx_new_call, + .discard_new_call = rxperf_rx_discard_new_call, + .user_attach_call = rxperf_rx_attach, +}; +/* * Charge the incoming call preallocation. */
@@ -161,7 +167,6 @@ static void rxperf_charge_preallocation(struct work_struct *work)if (rxrpc_kernel_charge_accept (rxperf_socket, rxperf_notify_rx, - rxperf_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
@@ -209,8 +214,7 @@ static int rxperf_open_socket(void)if (ret <0 ) goto error_2; -rxrpc_kernel_new_call_notification (socket, rxperf_rx_new_call, - rxperf_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &rxperf_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 rxrpc: serialize kernel accept preallocation with socket teardown
From: Li Daming <[email protected]>
[ Upstream commit dc175389b18c29a5303ee83169ec653adfae3e17 ]
rxrpc_kernel_charge_accept() reads rx->backlog without any socket/backlog synchronization and passes that raw pointer into rxrpc_service_prealloc_one(). A concurrent rxrpc_discard_prealloc() sets rx->backlog = NULL and frees the backlog rings, so a kernel preallocation worker can keep using a freed struct rxrpc_backlog while updating *_backlog_head/tail and array slots.
Serialize the state check and backlog lookup with the socket lock, and reject kernel preallocation once teardown has disabled listening or discarded the service backlog.
--- net/rxrpc/call_accept.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
net/rxrpc/call_accept.c +19 -6
@@ -470,13 +470,26 @@ int rxrpc_kernel_charge_accept(struct socket *sock, rxrpc_notify_rx_t notify_rx, unsigned long user_call_ID, gfp_t gfp, unsigned int debug_id) { - struct rxrpc_sock *rx = rxrpc_sk(sock->sk); -struct rxrpc_backlog *b = rx->backlog; + struct rxrpc_backlog *b; +struct rxrpc_sock *rx; +struct sock *sk; +int ret; -if (sock->sk->sk_state ==RXRPC_CLOSE ) -return -ESHUTDOWN ; + sk = sock->sk; + rx =rxrpc_sk (sk); + +lock_sock (sk); +if (sk->sk_state !=RXRPC_SERVER_LISTENING || !rx->backlog) { + ret = -ESHUTDOWN ; + goto out; + } + + b = rx->backlog; + ret =rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, + gfp, debug_id); -return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, - gfp, debug_id); +out: +release_sock (sk); +return ret; }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
Signature · 1 line
2.53.0