* [PATCH net v2] espintcp: Fix race condition in espintcp_close()
@ 2026-02-17 17:16 Hyunwoo Kim
2026-02-18 9:44 ` Simon Horman
2026-02-19 22:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Hyunwoo Kim @ 2026-02-17 17:16 UTC (permalink / raw)
To: horms, steffen.klassert, herbert, davem, edumazet, kuba, pabeni
Cc: netdev, imv4bel
This issue was discovered during a code audit.
After cancel_work_sync() is called from espintcp_close(),
espintcp_tx_work() can still be scheduled from paths such as
the Delayed ACK handler or ksoftirqd.
As a result, the espintcp_tx_work() worker may dereference a
freed espintcp ctx or sk.
The following is a simple race scenario:
cpu0 cpu1
espintcp_close()
cancel_work_sync(&ctx->work);
espintcp_write_space()
schedule_work(&ctx->work);
To prevent this race condition, cancel_work_sync() is
replaced with disable_work_sync().
Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
Changes in v2:
- Shorten the patch subject
- Target the net tree
- Add the bug discovery background and the race scenario to the commit message
- v1: https://lore.kernel.org/all/aZLmvv51f5Iu9G7b@v4bel/
---
net/xfrm/espintcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index bf744ac9d5a7..8709df716e98 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -536,7 +536,7 @@ static void espintcp_close(struct sock *sk, long timeout)
sk->sk_prot = &tcp_prot;
barrier();
- cancel_work_sync(&ctx->work);
+ disable_work_sync(&ctx->work);
strp_done(&ctx->strp);
skb_queue_purge(&ctx->out_queue);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] espintcp: Fix race condition in espintcp_close()
2026-02-17 17:16 [PATCH net v2] espintcp: Fix race condition in espintcp_close() Hyunwoo Kim
@ 2026-02-18 9:44 ` Simon Horman
2026-02-19 22:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2026-02-18 9:44 UTC (permalink / raw)
To: Hyunwoo Kim
Cc: steffen.klassert, herbert, davem, edumazet, kuba, pabeni, netdev,
Sabrina Dubroca
+ Sabrina
On Wed, Feb 18, 2026 at 02:16:43AM +0900, Hyunwoo Kim wrote:
> This issue was discovered during a code audit.
>
> After cancel_work_sync() is called from espintcp_close(),
> espintcp_tx_work() can still be scheduled from paths such as
> the Delayed ACK handler or ksoftirqd.
> As a result, the espintcp_tx_work() worker may dereference a
> freed espintcp ctx or sk.
>
> The following is a simple race scenario:
>
> cpu0 cpu1
>
> espintcp_close()
> cancel_work_sync(&ctx->work);
> espintcp_write_space()
> schedule_work(&ctx->work);
>
> To prevent this race condition, cancel_work_sync() is
> replaced with disable_work_sync().
>
> Fixes: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> ---
> Changes in v2:
> - Shorten the patch subject
> - Target the net tree
> - Add the bug discovery background and the race scenario to the commit message
> - v1: https://lore.kernel.org/all/aZLmvv51f5Iu9G7b@v4bel/
Thanks for taking my review into account [1].
This version looks good to me.
Reviewed-by: Simon Horman <horms@kernel.org>
It seems that get_maintainer.pl highlights that Sabrina is also a
maintainer, so I have CCed here and left the full context of the
patch in place for her convenience.
[1] https://lore.kernel.org/netdev/aZSbSOVuRgkjeezg@v4bel/
> ---
> net/xfrm/espintcp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
> index bf744ac9d5a7..8709df716e98 100644
> --- a/net/xfrm/espintcp.c
> +++ b/net/xfrm/espintcp.c
> @@ -536,7 +536,7 @@ static void espintcp_close(struct sock *sk, long timeout)
> sk->sk_prot = &tcp_prot;
> barrier();
>
> - cancel_work_sync(&ctx->work);
> + disable_work_sync(&ctx->work);
> strp_done(&ctx->strp);
>
> skb_queue_purge(&ctx->out_queue);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v2] espintcp: Fix race condition in espintcp_close()
2026-02-17 17:16 [PATCH net v2] espintcp: Fix race condition in espintcp_close() Hyunwoo Kim
2026-02-18 9:44 ` Simon Horman
@ 2026-02-19 22:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-02-19 22:40 UTC (permalink / raw)
To: Hyunwoo Kim
Cc: horms, steffen.klassert, herbert, davem, edumazet, kuba, pabeni,
netdev
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 18 Feb 2026 02:16:43 +0900 you wrote:
> This issue was discovered during a code audit.
>
> After cancel_work_sync() is called from espintcp_close(),
> espintcp_tx_work() can still be scheduled from paths such as
> the Delayed ACK handler or ksoftirqd.
> As a result, the espintcp_tx_work() worker may dereference a
> freed espintcp ctx or sk.
>
> [...]
Here is the summary with links:
- [net,v2] espintcp: Fix race condition in espintcp_close()
https://git.kernel.org/netdev/net/c/e1512c1db9e8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-19 22:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 17:16 [PATCH net v2] espintcp: Fix race condition in espintcp_close() Hyunwoo Kim
2026-02-18 9:44 ` Simon Horman
2026-02-19 22:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox