* [PATCH net 1/1] xfrm: input: hold netns during deferred transport reinjection
[not found] <cover.1779308659.git.zcliangcn@gmail.com>
@ 2026-05-22 9:31 ` Ren Wei
2026-05-26 10:26 ` Steffen Klassert
0 siblings, 1 reply; 2+ messages in thread
From: Ren Wei @ 2026-05-22 9:31 UTC (permalink / raw)
To: netdev
Cc: steffen.klassert, herbert, davem, sd, yuantan098, bird, tr0jan,
zcliangcn, n05ec
From: Zhengchuan Liang <zcliangcn@gmail.com>
Transport-mode reinjection stores a struct net pointer in skb->cb and
uses it later from xfrm_trans_reinject(). That pointer must stay valid
until the deferred callback runs.
Take a netns reference when queueing deferred reinjection work and drop
it after the callback completes. Use maybe_get_net() so the queueing
path does not revive a namespace that is already being torn down.
This keeps the existing workqueue design and fixes the netns lifetime
handling in one place for all users of xfrm_trans_queue_net().
Fixes: 7b3801927e52 ("xfrm: introduce xfrm_trans_queue_net")
Cc: stable@kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Co-developed-by: Luxing Yin <tr0jan@lzu.edu.cn>
Signed-off-by: Luxing Yin <tr0jan@lzu.edu.cn>
Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
Assisted-by: Codex:gpt-5.4
---
net/xfrm/xfrm_input.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index f65291eba1f6..cd7036a7d5c8 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -797,9 +797,12 @@ static void xfrm_trans_reinject(struct work_struct *work)
spin_unlock_bh(&trans->queue_lock);
local_bh_disable();
- while ((skb = __skb_dequeue(&queue)))
- XFRM_TRANS_SKB_CB(skb)->finish(XFRM_TRANS_SKB_CB(skb)->net,
- NULL, skb);
+ while ((skb = __skb_dequeue(&queue))) {
+ struct net *net = XFRM_TRANS_SKB_CB(skb)->net;
+
+ XFRM_TRANS_SKB_CB(skb)->finish(net, NULL, skb);
+ put_net(net);
+ }
local_bh_enable();
}
@@ -807,6 +810,7 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,
int (*finish)(struct net *, struct sock *,
struct sk_buff *))
{
struct xfrm_trans_tasklet *trans;
+ struct net *hold_net;
trans = this_cpu_ptr(&xfrm_trans_tasklet);
@@ -816,8 +820,12 @@ int xfrm_trans_queue_net(struct net *net, struct sk_buff *skb,
BUILD_BUG_ON(sizeof(struct xfrm_trans_cb) > sizeof(skb->cb));
+ hold_net = maybe_get_net(net);
+ if (!hold_net)
+ return -ENODEV;
+
XFRM_TRANS_SKB_CB(skb)->finish = finish;
- XFRM_TRANS_SKB_CB(skb)->net = net;
+ XFRM_TRANS_SKB_CB(skb)->net = hold_net;
spin_lock_bh(&trans->queue_lock);
__skb_queue_tail(&trans->queue, skb);
spin_unlock_bh(&trans->queue_lock);
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net 1/1] xfrm: input: hold netns during deferred transport reinjection
2026-05-22 9:31 ` [PATCH net 1/1] xfrm: input: hold netns during deferred transport reinjection Ren Wei
@ 2026-05-26 10:26 ` Steffen Klassert
0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2026-05-26 10:26 UTC (permalink / raw)
To: Ren Wei; +Cc: netdev, herbert, davem, sd, yuantan098, bird, tr0jan, zcliangcn
On Fri, May 22, 2026 at 05:31:55PM +0800, Ren Wei wrote:
> From: Zhengchuan Liang <zcliangcn@gmail.com>
>
> Transport-mode reinjection stores a struct net pointer in skb->cb and
> uses it later from xfrm_trans_reinject(). That pointer must stay valid
> until the deferred callback runs.
>
> Take a netns reference when queueing deferred reinjection work and drop
> it after the callback completes. Use maybe_get_net() so the queueing
> path does not revive a namespace that is already being torn down.
>
> This keeps the existing workqueue design and fixes the netns lifetime
> handling in one place for all users of xfrm_trans_queue_net().
>
> Fixes: 7b3801927e52 ("xfrm: introduce xfrm_trans_queue_net")
> Cc: stable@kernel.org
> Reported-by: Yuan Tan <yuantan098@gmail.com>
> Reported-by: Xin Liu <bird@lzu.edu.cn>
> Co-developed-by: Luxing Yin <tr0jan@lzu.edu.cn>
> Signed-off-by: Luxing Yin <tr0jan@lzu.edu.cn>
> Signed-off-by: Zhengchuan Liang <zcliangcn@gmail.com>
> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
> Assisted-by: Codex:gpt-5.4
Applied, thanks a lot!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-26 10:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1779308659.git.zcliangcn@gmail.com>
2026-05-22 9:31 ` [PATCH net 1/1] xfrm: input: hold netns during deferred transport reinjection Ren Wei
2026-05-26 10:26 ` Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox