strparser: Fix race condition in strp_done()
Subsystems (2)
PATCH v2 1/1 strparser: Fix race condition in strp_done()
This issue was discovered during a code audit.
When strp_stop() and strp_done() are called without holding lock_sock(), they can race with worker-scheduling paths such as the Delayed ACK handler and ksoftirqd.
Specifically, after cancel_delayed_work_sync() and cancel_work_sync() are invoked from strp_done(), the workers may still be scheduled. As a result, the workers may dereference freed objects.
The following is a simple race scenario:
cpu0 cpu1
espintcp_close()
espintcp_data_ready()
strp_data_ready()
if (unlikely(strp->stopped)) return;
strp_stop()
strp->stopped = 1;
strp_done()
cancel_delayed_work_sync(&strp->msg_timer_work);
strp_read_sock()
tcp_read_sock()
__tcp_read_sock()
strp_recv()
__strp_recv()
strp_start_timer()
mod_delayed_work(&strp->msg_timer_work);To prevent these races, the cancellation APIs are replaced with worker-disabling APIs.
---
Changes in v2:
- Update Fixes tag
- Incorporate Simon’s review: https://lore.kernel.org/all/[email protected]/
- 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/aZLn2Faeg1FB7XOf@v4bel/
--- net/strparser/strparser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/strparser/strparser.c +2 -2
@@ -503,8 +503,8 @@ void strp_done(struct strparser *strp) {WARN_ON (!strp->stopped); -cancel_delayed_work_sync (&strp->msg_timer_work); -cancel_work_sync (&strp->work); +disable_delayed_work_sync (&strp->msg_timer_work); +disable_work_sync (&strp->work);if (strp->skb_head) {kfree_skb (strp->skb_head);
Signature · 1 line
2.43.0
Quoted 29 lines · Hyunwoo Kim
This issue was discovered during a code audit.
When
strp_stop()andstrp_done()are called without holdinglock_sock(), they can race with worker-scheduling paths such as the Delayed ACK handler and ksoftirqd.
Specifically, aftercancel_delayed_work_sync()andcancel_work_sync()are invoked fromstrp_done(), the workers may still be scheduled. As a result, the workers may dereference freed objects.The following is a simple race scenario:
cpu0 cpu1
espintcp_close()espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() cancel_delayed_work_sync(&strp->msg_timer_work); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() strp_start_timer() mod_delayed_work(&strp->msg_timer_work);
Quoted 2 lines
To prevent these races, the cancellation APIs are replaced with worker-disabling APIs.
I'm still not totally convinced by this patch. The comment for strp_done says the function expects to be called at a time when strp_recv cannot happen in parallel:
strp must already be stopped so that strp_recv will no longer be called
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grab bh_lock_sock to make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.
Without that, if strp_recv runs in parallel (not from strp->work) with strp_done, cleaning up skb_head in strp_done seems problematic.
Signature · 1 line
Sabrina
Quoted 30 lines · Sabrina Dubroca
Quoted 29 lines · Hyunwoo Kim
This issue was discovered during a code audit.
When
strp_stop()andstrp_done()are called without holdinglock_sock(), they can race with worker-scheduling paths such as the Delayed ACK handler and ksoftirqd.
Specifically, aftercancel_delayed_work_sync()andcancel_work_sync()are invoked fromstrp_done(), the workers may still be scheduled. As a result, the workers may dereference freed objects.The following is a simple race scenario:
cpu0 cpu1
espintcp_close()espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() cancel_delayed_work_sync(&strp->msg_timer_work); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() strp_start_timer() mod_delayed_work(&strp->msg_timer_work);
Quoted 8 lines
Quoted 2 lines
To prevent these races, the cancellation APIs are replaced with worker-disabling APIs.
I'm still not totally convinced by this patch. The comment for
strp_donesays the function expects to be called at a time whenstrp_recvcannot happen in parallel:strp must already be stopped so that
strp_recvwill no longer be called
OK, I understand.
More specifically, it seems that an issue could occur if strp->skb_head is accessed under the following scenario.
```
cpu0 cpu1
espintcp_close()
espintcp_data_ready()
strp_data_ready()
if (unlikely(strp->stopped)) return;
strp_stop()
strp->stopped = 1;
strp_done()
disable_delayed_work_sync(&strp->msg_timer_work);
kfree_skb(strp->skb_head);
strp_read_sock()
tcp_read_sock()
__tcp_read_sock()
strp_recv()
__strp_recv()
head = strp->skb_head;
...
```Quoted 4 lines
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grab
bh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.
It seems that this is not something that should be handled inside strp itself, but rather something that each caller of strp_stop() is expected to take care of individually. Would that be the right direction?
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Quoted 3 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.
From the espintcp perspective, how about applying a patch along the following lines?
```
diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index e1b11ab59f6e..989638fdc111 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -526,12 +526,28 @@ static void espintcp_release(struct sock *sk)
tcp_release_cb(sk);
}
+static void espintcp_detach_sock(struct sock *sk)
+{
+ struct espintcp_ctx *ctx = espintcp_getctx(sk);
+
+ lock_sock(sk);
+
+ write_lock_bh(&sk->sk_callback_lock);
+ sk->sk_data_ready = ctx->saved_data_ready;
+ sk->sk_write_space = ctx->saved_write_space;
+ write_unlock_bh(&sk->sk_callback_lock);
+
+ strp_stop(&ctx->strp);
+
+ release_sock(sk);
+}
+
static void espintcp_close(struct sock *sk, long timeout)
{
struct espintcp_ctx *ctx = espintcp_getctx(sk);
struct espintcp_msg *emsg = &ctx->partial;
- strp_stop(&ctx->strp);
+ espintcp_detach_sock(sk);
sk->sk_prot = &tcp_prot;
barrier();
```Best regards,
Hyunwoo Kim
Quoted 38 lines · Hyunwoo Kim
Quoted 37 lines · Sabrina Dubroca
Quoted 29 lines · Hyunwoo Kim
This issue was discovered during a code audit.
When
strp_stop()andstrp_done()are called without holdinglock_sock(), they can race with worker-scheduling paths such as the Delayed ACK handler and ksoftirqd.
Specifically, aftercancel_delayed_work_sync()andcancel_work_sync()are invoked fromstrp_done(), the workers may still be scheduled. As a result, the workers may dereference freed objects.The following is a simple race scenario:
cpu0 cpu1
espintcp_close()espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() cancel_delayed_work_sync(&strp->msg_timer_work); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() strp_start_timer() mod_delayed_work(&strp->msg_timer_work);Quoted 2 lines
To prevent these races, the cancellation APIs are replaced with worker-disabling APIs.
I'm still not totally convinced by this patch. The comment for
strp_donesays the function expects to be called at a time whenstrp_recvcannot happen in parallel:
Quoted 5 lines
Quoted 1 line
strp must already be stopped so that
strp_recvwill no longer be calledOK, I understand.
More specifically, it seems that an issue could occur ifstrp->skb_headis accessed under the following scenario.
Yes.
Quoted 22 lines
``` cpu0 cpu1 espintcp_close() espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() disable_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; ... ```Quoted 1 line
Quoted 7 lines
Quoted 3 lines
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grab
bh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?
Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
This is what I was thinking about, yes.
Thanks.
Signature · 1 line
Sabrina
Quoted 85 lines · Sabrina Dubroca
Quoted 38 lines · Hyunwoo Kim
Quoted 37 lines · Sabrina Dubroca
Quoted 29 lines · Hyunwoo Kim
This issue was discovered during a code audit.
When
strp_stop()andstrp_done()are called without holdinglock_sock(), they can race with worker-scheduling paths such as the Delayed ACK handler and ksoftirqd.
Specifically, aftercancel_delayed_work_sync()andcancel_work_sync()are invoked fromstrp_done(), the workers may still be scheduled. As a result, the workers may dereference freed objects.The following is a simple race scenario:
cpu0 cpu1
espintcp_close()espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() cancel_delayed_work_sync(&strp->msg_timer_work); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() strp_start_timer() mod_delayed_work(&strp->msg_timer_work);Quoted 2 lines
To prevent these races, the cancellation APIs are replaced with worker-disabling APIs.
I'm still not totally convinced by this patch. The comment for
strp_donesays the function expects to be called at a time whenstrp_recvcannot happen in parallel:Quoted 5 lines
Quoted 1 line
strp must already be stopped so that
strp_recvwill no longer be calledOK, I understand.
More specifically, it seems that an issue could occur ifstrp->skb_headis accessed under the following scenario.Yes.
Quoted 22 lines
``` cpu0 cpu1 espintcp_close() espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_stop() strp->stopped = 1; strp_done() disable_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; ... ```Quoted 1 line
Quoted 7 lines
Quoted 3 lines
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grab
bh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
It seems that the two changes address slightly different kinds of issues.
If you agree, I can prepare and submit the espintcp callback restoration patch separately shortly.
Best regards,
Hyunwoo Kim
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 23 lines · Hyunwoo Kim
Quoted 22 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 3 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
From the espintcp perspective, how about applying a patch along the following lines?
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur? release_sock() will wait for any espintcp_data_ready()/strp_data_ready() that's already running, and a sk_data_ready that starts after we've changed the callbacks will not end up in strp_data_ready() at all so it won't restart the works that are being stopped by strp_done()?
It's quite reasonable to use disable*_work_sync in strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.
Signature · 1 line
Sabrina
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for any
If the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 8 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.
That said, the _cancel APIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the _disable APIs for the benefit of other strp users or potential future callers.
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the _cancel APIs with the _disable variants, and resubmit it in that form.
What do you think about proceeding in that direction?
Best regards,
Hyunwoo Kim
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?
Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.
Not really. Every user of strp that is open to the strp_recv vs cancel_* race is also open to the strp_recv vs free race, so switching from cancel_* to disable_* is only a partial fix.
But if we took and released the socket lock in strp_done, we would solve the issue for all users even without resetting the callbacks?
@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp)
{
WARN_ON(!strp->stopped);
+ lock_sock(strp->sk);
+ /* sync with other code */
+ release_sock(strp->sk);
+
cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);
- strp->stopped so any new call into strp_data_ready will not do anything
- lock/release need to take bh_lock_sock so any existing call to strp_data_ready will have to complete before we move on to cancel*_work
Or maybe the requirement should be that strp_stop has to be called under lock_sock() (or even just bh_lock_sock), but again I can't figure out if that's ok for sockmap.
Quoted 5 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.
I'm not going to nack a patch doing s/cancel_/disable_/ in strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.
Signature · 1 line
Sabrina
Quoted 55 lines · Sabrina Dubroca
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.
Quoted 6 lines
Not really. Every user of strp that is open to the
strp_recvvs cancel_* race is also open to thestrp_recvvs free race, so switching from cancel_* to disable_* is only a partial fix.But if we took and released the socket lock in
strp_done, we would solve the issue for all users even without resetting the callbacks?
Looks good to me. With this change, it seems the issue can be resolved not only for espintcp but for all strp users.
When strp_stop() runs first:
```
cpu0 cpu1
espintcp_close()
strp_stop()
strp->stopped = 1;
espintcp_data_ready()
strp_data_ready()
if (unlikely(strp->stopped)) return;
strp_done()
lock_sock();
release_sock();
cancel_delayed_work_sync(&strp->msg_timer_work);
kfree_skb(strp->skb_head);
```When strp_data_ready() runs first:
```
cpu0 cpu1
espintcp_data_ready()
strp_data_ready()
if (unlikely(strp->stopped)) return;
espintcp_close()
strp_stop()
strp->stopped = 1;
strp_done()
lock_sock();
strp_read_sock()
tcp_read_sock()
__tcp_read_sock()
strp_recv()
__strp_recv()
head = strp->skb_head;
strp_start_timer()
mod_delayed_work(&strp->msg_timer_work);
...
release_sock();
cancel_delayed_work_sync(&strp->msg_timer_work);
kfree_skb(strp->skb_head);
```In both cases, the race does not appear to cause any problem.
Quoted 14 lines
(quoted diff) +4
-0@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp) { WARN_ON(!strp->stopped); + lock_sock(strp->sk); + /* sync with other code */ + release_sock(strp->sk); + cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);
Quoted 8 lines
-
strp->stoppedso any new call intostrp_data_readywill not do anything- lock/release need to take
bh_lock_sockso any existing call tostrp_data_readywill have to complete before we move on to cancel*_workOr maybe the requirement should be that
strp_stophas to be called
From my perspective, adding lock_sock() inside strp_done(), as in the patch above, looks cleaner.
Quoted 2 lines
under
lock_sock()(or even justbh_lock_sock), but again I can't figure out if that's ok for sockmap.
sockmap/psock has a more complex call stack compared to other strp users, so I'm also not entirely certain about that part.
Quoted 8 lines
Quoted 7 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.
Quoted 4 lines
I'm not going to nack a patch doing s/cancel_/disable_/ in
strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.
I agree with your point there. Still, after the core patches addressing this race are applied, I plan to resubmit the _disable patch with an updated commit message. I think applying that change is still beneficial.
Best regards,
Hyunwoo Kim
Quoted 136 lines · Hyunwoo Kim
Quoted 55 lines · Sabrina Dubroca
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.Quoted 6 lines
Not really. Every user of strp that is open to the
strp_recvvs cancel_* race is also open to thestrp_recvvs free race, so switching from cancel_* to disable_* is only a partial fix.But if we took and released the socket lock in
strp_done, we would solve the issue for all users even without resetting the callbacks?Looks good to me. With this change, it seems the issue can be resolved not only for espintcp but for all strp users.
When
strp_stop()runs first:``` cpu0 cpu1 espintcp_close() strp_stop() strp->stopped = 1; espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_done() lock_sock(); release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```When
strp_data_ready()runs first:``` cpu0 cpu1 espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; espintcp_close() strp_stop() strp->stopped = 1; strp_done() lock_sock(); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; strp_start_timer() mod_delayed_work(&strp->msg_timer_work); ... release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```In both cases, the race does not appear to cause any problem.
Quoted 14 lines
(quoted diff) +4
-0@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp) { WARN_ON(!strp->stopped); + lock_sock(strp->sk); + /* sync with other code */ + release_sock(strp->sk); + cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);Quoted 8 lines
-
strp->stoppedso any new call intostrp_data_readywill not do anything- lock/release need to take
bh_lock_sockso any existing call tostrp_data_readywill have to complete before we move on to cancel*_workOr maybe the requirement should be that
strp_stophas to be calledFrom my perspective, adding
lock_sock()insidestrp_done(), as in the patch above, looks cleaner.
Quoted 5 lines
Quoted 2 lines
under
lock_sock()(or even justbh_lock_sock), but again I can't figure out if that's ok for sockmap.sockmap/psock has a more complex call stack compared to other strp users, so I'm also not entirely certain about that part.
I looked into the sockmap/psock side. sk_psock_strp_data_ready() is protected by read_lock_bh(&sk->sk_callback_lock), and during teardown sk_psock_drop() performs callback restoration and strp_stop() under write_lock_bh(&sk->sk_callback_lock), so sockmap/psock doesn't have this race to begin with.
As for introducing this patch, in sockmap/psock strp_done() is only called from sk_psock_destroy(), which is scheduled via queue_rcu_work() and runs on system_percpu_wq after an RCU GP, so no locks including lock_sock are held at that point. And since lock_sock is released before cancel_work_sync, there's no circular dependency with do_strp_work/strp_msg_timeout either. So this patch shouldn't introduce any new issues for sockmap/psock.
Quoted 21 lines
Quoted 9 lines
Quoted 8 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.Quoted 4 lines
I'm not going to nack a patch doing s/cancel_/disable_/ in
strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.I agree with your point there. Still, after the core patches addressing this race are applied, I plan to resubmit the
_disablepatch with an updated commit message. I think applying that change is still beneficial.Best regards,
Hyunwoo Kim
Quoted 149 lines · Hyunwoo Kim
Quoted 136 lines · Hyunwoo Kim
Quoted 55 lines · Sabrina Dubroca
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.Quoted 6 lines
Not really. Every user of strp that is open to the
strp_recvvs cancel_* race is also open to thestrp_recvvs free race, so switching from cancel_* to disable_* is only a partial fix.But if we took and released the socket lock in
strp_done, we would solve the issue for all users even without resetting the callbacks?Looks good to me. With this change, it seems the issue can be resolved not only for espintcp but for all strp users.
When
strp_stop()runs first:``` cpu0 cpu1 espintcp_close() strp_stop() strp->stopped = 1; espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_done() lock_sock(); release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```When
strp_data_ready()runs first:``` cpu0 cpu1 espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; espintcp_close() strp_stop() strp->stopped = 1; strp_done() lock_sock(); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; strp_start_timer() mod_delayed_work(&strp->msg_timer_work); ... release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```In both cases, the race does not appear to cause any problem.
Quoted 14 lines
(quoted diff) +4
-0@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp) { WARN_ON(!strp->stopped); + lock_sock(strp->sk); + /* sync with other code */ + release_sock(strp->sk); + cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);Quoted 8 lines
-
strp->stoppedso any new call intostrp_data_readywill not do anything- lock/release need to take
bh_lock_sockso any existing call tostrp_data_readywill have to complete before we move on to cancel*_workOr maybe the requirement should be that
strp_stophas to be calledFrom my perspective, adding
lock_sock()insidestrp_done(), as in the patch above, looks cleaner.Quoted 5 lines
Quoted 2 lines
under
lock_sock()(or even justbh_lock_sock), but again I can't figure out if that's ok for sockmap.sockmap/psock has a more complex call stack compared to other strp users, so I'm also not entirely certain about that part.
I looked into the sockmap/psock side.
sk_psock_strp_data_ready()is protected byread_lock_bh(&sk->sk_callback_lock), and during teardownsk_psock_drop()performs callback restoration andstrp_stop()underwrite_lock_bh(&sk->sk_callback_lock), so sockmap/psock doesn't have this race to begin with.
Quoted 6 lines
As for introducing this patch, in sockmap/psock
strp_done()is only called fromsk_psock_destroy(), which is scheduled viaqueue_rcu_work()and runs onsystem_percpu_wqafter an RCU GP, so no locks includinglock_sockare held at that point. And sincelock_sockis released beforecancel_work_sync, there's no circular dependency with do_strp_work/strp_msg_timeout either. So this patch shouldn't introduce any new issues for sockmap/psock.
Hi Sabrina,
Could you please provide an update on the status of this patch?
Best regards,
Hyunwoo Kim
Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
Quoted 9 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.Quoted 4 lines
I'm not going to nack a patch doing s/cancel_/disable_/ in
strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.I agree with your point there. Still, after the core patches addressing this race are applied, I plan to resubmit the
_disablepatch with an updated commit message. I think applying that change is still beneficial.Best regards,
Hyunwoo Kim
Quoted 157 lines · Hyunwoo Kim
Quoted 149 lines · Hyunwoo Kim
Quoted 136 lines · Hyunwoo Kim
Quoted 55 lines · Sabrina Dubroca
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.Quoted 6 lines
Not really. Every user of strp that is open to the
strp_recvvs cancel_* race is also open to thestrp_recvvs free race, so switching from cancel_* to disable_* is only a partial fix.But if we took and released the socket lock in
strp_done, we would solve the issue for all users even without resetting the callbacks?Looks good to me. With this change, it seems the issue can be resolved not only for espintcp but for all strp users.
When
strp_stop()runs first:``` cpu0 cpu1 espintcp_close() strp_stop() strp->stopped = 1; espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_done() lock_sock(); release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```When
strp_data_ready()runs first:``` cpu0 cpu1 espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; espintcp_close() strp_stop() strp->stopped = 1; strp_done() lock_sock(); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; strp_start_timer() mod_delayed_work(&strp->msg_timer_work); ... release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```In both cases, the race does not appear to cause any problem.
Quoted 14 lines
(quoted diff) +4
-0@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp) { WARN_ON(!strp->stopped); + lock_sock(strp->sk); + /* sync with other code */ + release_sock(strp->sk); + cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);Quoted 8 lines
-
strp->stoppedso any new call intostrp_data_readywill not do anything- lock/release need to take
bh_lock_sockso any existing call tostrp_data_readywill have to complete before we move on to cancel*_workOr maybe the requirement should be that
strp_stophas to be calledFrom my perspective, adding
lock_sock()insidestrp_done(), as in the patch above, looks cleaner.Quoted 5 lines
Quoted 2 lines
under
lock_sock()(or even justbh_lock_sock), but again I can't figure out if that's ok for sockmap.sockmap/psock has a more complex call stack compared to other strp users, so I'm also not entirely certain about that part.
I looked into the sockmap/psock side.
sk_psock_strp_data_ready()is protected byread_lock_bh(&sk->sk_callback_lock), and during teardownsk_psock_drop()performs callback restoration andstrp_stop()underwrite_lock_bh(&sk->sk_callback_lock), so sockmap/psock doesn't have this race to begin with.Quoted 6 lines
As for introducing this patch, in sockmap/psock
strp_done()is only called fromsk_psock_destroy(), which is scheduled viaqueue_rcu_work()and runs onsystem_percpu_wqafter an RCU GP, so no locks includinglock_sockare held at that point. And sincelock_sockis released beforecancel_work_sync, there's no circular dependency with do_strp_work/strp_msg_timeout either. So this patch shouldn't introduce any new issues for sockmap/psock.
Quoted 7 lines
Hi Sabrina,
Could you please provide an update on the status of this patch?
Best regards,
Hyunwoo Kim
Dear Sabrina,
This issue has been public for some time and seems to be gradually fading from attention.
Could you please let me know the current status of the work on this?
Best regards,
Hyunwoo Kim
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
Quoted 10 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.Quoted 4 lines
I'm not going to nack a patch doing s/cancel_/disable_/ in
strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.I agree with your point there. Still, after the core patches addressing this race are applied, I plan to resubmit the
_disablepatch with an updated commit message. I think applying that change is still beneficial.Best regards,
Hyunwoo Kim
Quoted 133 lines · Hyunwoo Kim
Quoted 55 lines · Sabrina Dubroca
Quoted 46 lines · Hyunwoo Kim
Quoted 29 lines · Sabrina Dubroca
Sorry for the delay, I wanted to think about the race condition a bit more.
Quoted 25 lines · Hyunwoo Kim
Quoted 24 lines · Sabrina Dubroca
Quoted 9 lines · Hyunwoo Kim
Quoted 4 lines · Sabrina Dubroca
2026-02-20, 18:29:55 +0900, Hyunwoo Kim wrote:
"strp stopped" is not really enough, I think we'd also need to reset the CBs, and then grabbh_lock_sockto make sure a previously-running ->sk_data_ready has completed. This is what kcm does, at least.It seems that this is not something that should be handled inside strp itself, but rather something that each caller of
strp_stop()is expected to take care of individually. Would that be the right direction?Agree.
Quoted 2 lines
It also appears that ovpn and kcm handle this by implementing their own callback restoration logic.
Right. I tried to look at skmsg/psock (the other user of strp), but didn't get far enough to verify if it's handling this correctly.
Quoted 4 lines
Quoted 2 lines
Without that, if
strp_recvruns in parallel (not fromstrp->work) withstrp_done, cleaning upskb_headinstrp_doneseems problematic.From the espintcp perspective, how about applying a patch along the following lines?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This is what I was thinking about, yes.
In my opinion, it might be cleaner to split the espintcp callback restoration work into a separate patch, rather than merging it into the strparser v3 patch. What do you think?
Sure. But once espintcp is fixed in that way, can the original race condition with strparser still occur?
release_sock()will wait for anyIf the espintcp callback restoration patch is applied, the strparser race should no longer occur in espintcp.
Quoted 5 lines
espintcp_data_ready()/strp_data_ready() that's already running, and a
sk_data_readythat starts after we've changed the callbacks will not end up instrp_data_ready()at all so it won't restart the works that are being stopped bystrp_done()?Quoted 7 lines
Quoted 3 lines
It's quite reasonable to use disable*_work_sync in
strp_done, but I'm not sure there's a bug other than espintcp not terminating itself correctly on the socket.That said, the
_cancelAPIs in strparser still appear to carry some structural risk, so it might still make sense to switch to the_disableAPIs for the benefit of other strp users or potential future callers.Quoted 6 lines
Not really. Every user of strp that is open to the
strp_recvvs cancel_* race is also open to thestrp_recvvs free race, so switching from cancel_* to disable_* is only a partial fix.But if we took and released the socket lock in
strp_done, we would solve the issue for all users even without resetting the callbacks?Looks good to me. With this change, it seems the issue can be resolved not only for espintcp but for all strp users.
When
strp_stop()runs first:``` cpu0 cpu1 espintcp_close() strp_stop() strp->stopped = 1; espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; strp_done() lock_sock(); release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```When
strp_data_ready()runs first:``` cpu0 cpu1 espintcp_data_ready() strp_data_ready() if (unlikely(strp->stopped)) return; espintcp_close() strp_stop() strp->stopped = 1; strp_done() lock_sock(); strp_read_sock() tcp_read_sock() __tcp_read_sock() strp_recv() __strp_recv() head = strp->skb_head; strp_start_timer() mod_delayed_work(&strp->msg_timer_work); ... release_sock(); cancel_delayed_work_sync(&strp->msg_timer_work); kfree_skb(strp->skb_head); ```In both cases, the race does not appear to cause any problem.
Quoted 22 lines
(quoted diff) +4
-0@@ -503,6 +503,10 @@ void strp_done(struct strparser *strp) { WARN_ON(!strp->stopped); + lock_sock(strp->sk); + /* sync with other code */ + release_sock(strp->sk); + cancel_delayed_work_sync(&strp->msg_timer_work); cancel_work_sync(&strp->work);-
strp->stoppedso any new call intostrp_data_readywill not do anything- lock/release need to take
bh_lock_sockso any existing call tostrp_data_readywill have to complete before we move on to cancel*_workOr maybe the requirement should be that
strp_stophas to be called
Quoted 8 lines
Quoted 1 line
From my perspective, adding
lock_sock()insidestrp_done(), as in thepatch above, looks cleaner.
Quoted 2 lines
under
lock_sock()(or even justbh_lock_sock), but again I can't figure out if that's ok for sockmap.sockmap/psock has a more complex call stack compared to other strp users, so I'm also not entirely certain about that part.
For sockmap, I think it's not affected by this race.
The sockmap path has additional synchronization:
1. sk_psock_strp_data_ready() holds read_lock_bh(&sk->sk_callback_lock) when calling strp_data_ready(), while sk_psock_drop() holds write_lock_bh(&sk->sk_callback_lock) when calling strp_stop(). This rwlock serializes the stopped flag check with the stopped flag set.
2. strp_done() is not called directly from sk_psock_drop(), but deferred via queue_rcu_work() → sk_psock_destroy() → sk_psock_done_strp().
The RCU grace period guarantees that all in-flight sk_psock_strp_data_ready() calls (which are within rcu_read_lock() sections) have completed before strp_done() runs. So cancel_delayed_work_sync() / cancel_work_sync() in strp_done() won't be defeated by a subsequent re-schedule.
I think it common practice to use strparser just like the doc says:
void strp_done(struct strparser *strp);
strp_done is called to release any resources held by the stream parser instance. This must be called after the stream processor has been stopped.
Quoted 21 lines
Quoted 9 lines
Quoted 8 lines
With that in mind, perhaps the direct fix for this race could be handled in the espintcp callback restoration patch. For the strparser patch, I could instead adjust the commit message to reflect that it removes a potential hazard by replacing the
_cancelAPIs with the_disablevariants, and resubmit it in that form.Quoted 4 lines
I'm not going to nack a patch doing s/cancel_/disable_/ in
strp_done, but it doesn't fully solve the race condition if the caller isn't doing the right thing, and it doesn't do anything if the strp user is handling the teardown correctly.I agree with your point there. Still, after the core patches addressing this race are applied, I plan to resubmit the
_disablepatch with an updated commit message. I think applying that change is still beneficial.Best regards,
Hyunwoo Kim