public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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