can: bcm: prevent thrtimer UAF in rx path by checking RX_NO_AUTOTIMER
Subsystems (2)
PATCH 1/1 can: bcm: prevent thrtimer UAF in rx path by checking RX_NO_AUTOTIMER
Commit f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()") removed the synchronize_rcu() call from bcm_delete_rx_op() and introduced the RX_NO_AUTOTIMER flag to prevent timers from being rearmed during deletion. However, it only applied this check to op->timer via bcm_rx_starttimer().
It missed the fact that op->thrtimer can also be rearmed by an in-flight bcm_rx_handler() (which runs as an RCU reader) via bcm_rx_update_and_send(). This allows op->thrtimer to be queued after bcm_remove_op() has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed struct bcm_op.
Address the omission by checking the RX_NO_AUTOTIMER flag in bcm_rx_update_and_send() before starting op->thrtimer, effectively preventing it from being rearmed concurrently with teardown.
--- net/can/bcm.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/can/bcm.c +6 -0
@@ -539,6 +539,12 @@ static void bcm_rx_update_and_send(struct bcm_op *op,if (hrtimer_active (&op->thrtimer))return ; +/* bcm_remove_op() may have cancelled thrtimer concurrently with this +* RCU-protected handler; do not rearm it. Mirrors bcm_rx_starttimer(). +*/ +if (op->flags &RX_NO_AUTOTIMER ) +return ; +/* first reception with enabled throttling mode */ if (!op->kt_lastmsg) goto rx_changed_settime;
Signature · 1 line
2.54.0.rc1.555.g9c883467ad-goog
Quoted 12 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.
Quoted 5 lines
Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.Signed-off-by Lee Jones <[email protected]>
Many thanks for the investigation and the fix!
Best regards,
Oliver
Quoted 21 lines
--- net/can/bcm.c | 6 ++++++ 1 file changed, 6 insertions(+)net/can/bcm.c +6
-0@@ -539,6 +539,12 @@ static void bcm_rx_update_and_send(struct bcm_op *op,if (hrtimer_active (&op->thrtimer))return ; +/* bcm_remove_op() may have cancelled thrtimer concurrently with this +* RCU-protected handler; do not rearm it. Mirrors bcm_rx_starttimer(). +*/ +if (op->flags &RX_NO_AUTOTIMER ) +return ; +/* first reception with enabled throttling mode */ if (!op->kt_lastmsg) goto rx_changed_settime;
Marc Kleine-Budde
maintainerQuoted 19 lines · Oliver Hartkopp
Quoted 16 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.
Quoted 5 lines
Quoted 1 line
Signed-off-by Lee Jones <[email protected]>Many thanks for the investigation and the fix!
Acked-by Oliver Hartkopp <[email protected]>
Can we add a Fixes: tag?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Oliver Hartkopp
maintainerQuoted 20 lines · Marc Kleine-Budde
Quoted 19 lines · Oliver Hartkopp
Quoted 16 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Lee Jones <[email protected]>Many thanks for the investigation and the fix!
Acked-by Oliver Hartkopp <[email protected]>Can we add a Fixes: tag?
Yes, we should.
Thanks!
Best regards,
Oliver
Quoted 23 lines · Oliver Hartkopp
Quoted 20 lines · Marc Kleine-Budde
Quoted 19 lines · Oliver Hartkopp
Quoted 16 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Lee Jones <[email protected]>Many thanks for the investigation and the fix!
Acked-by Oliver Hartkopp <[email protected]>Can we add a Fixes: tag?
Do you need me to resubmit or are you okay to apply manually / with b4?
Quoted 5 lines
Yes, we should.
Thanks!
Signed-off-by Oliver Hartkopp <[email protected]>
I'm a little confused by the SoB. Does this mean you've applied it?
Signature · 1 line
Lee Jones
Oliver Hartkopp
maintainerQuoted 37 lines · Lee Jones
Quoted 23 lines · Oliver Hartkopp
Quoted 20 lines · Marc Kleine-Budde
Quoted 19 lines · Oliver Hartkopp
Quoted 16 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Lee Jones <[email protected]>Many thanks for the investigation and the fix!
Acked-by Oliver Hartkopp <[email protected]>Can we add a Fixes: tag?
Fixes f1b4e32aca08 ("can: bcm: use call_rcu() instead of costly synchronize_rcu()")Do you need me to resubmit or are you okay to apply manually / with b4?
Quoted 8 lines
Quoted 5 lines
Yes, we should.
Thanks!
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context. But Marc was sometimes asking for it when I commented and discussed patches in the past.
I also thought Marc would add the Fixes tag on his own.
Best regards,
Oliver
Marc Kleine-Budde
maintainerQuoted 8 lines · Oliver Hartkopp
Quoted 4 lines
Quoted 1 line
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context.
ACK
Quoted 2 lines
But Marc was sometimes asking
for it when I commented and discussed patches in the past.
The rule is: if you post a patch, your S-o-b has to be the last S-o-b in the line.
Quoted 1 line
I also thought Marc would add the Fixes tag on his own.
If you add it in the thread, b-4 will pick it up automatically and this less work for me :)
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Oliver Hartkopp
maintainerQuoted 10 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp
Quoted 4 lines
Quoted 1 line
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context.
Quoted 8 lines
ACK
Quoted 2 lines
But Marc was sometimes asking
for it when I commented and discussed patches in the past.The rule is: if you post a patch, your S-o-b has to be the last S-o-b in the line.
Ok.
Quoted 4 lines
Quoted 1 line
I also thought Marc would add the Fixes tag on his own.
If you add it in the thread, b-4 will pick it up automatically and this less work for me :)
Ah. This time Lee already did the job for b4 ;-)
Best regards,
Oliver
Quoted 10 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp
Quoted 4 lines
Quoted 1 line
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context.
Quoted 7 lines
ACK
Quoted 2 lines
But Marc was sometimes asking
for it when I commented and discussed patches in the past.The rule is: if you post a patch, your S-o-b has to be the last S-o-b in the line.
Right. But SoBs are an indicator that a given person was part of the patch flow; author, submitter, sub-maintainer, maintainer, etc.
In this context Oliver's SoB should have been Reviewed-by or Acked-by.
Thanks for confirming that you use b4 - that makes life easier.
Signature · 1 line
Lee Jones
Oliver Hartkopp
maintainerQuoted 17 lines · Lee Jones
Quoted 15 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp
Quoted 4 lines
Quoted 1 line
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context.
ACK
Quoted 2 lines
But Marc was sometimes asking
for it when I commented and discussed patches in the past.
Quoted 8 lines
Quoted 2 lines
The rule is: if you post a patch, your S-o-b has to be the last S-o-b in the line.
Right. But SoBs are an indicator that a given person was part of the patch flow; author, submitter, sub-maintainer, maintainer, etc.
In this context Oliver's SoB should have been Reviewed-by or Acked-by.
Yes.
I'm author and maintainer of the bcm code - but Marc manages the patch flow for the CAN subsystem. That's why I sent my Acked-by instantly - which was the right reaction. Sorry for the SoB noise.
Many thanks,
OLiver
Quoted 15 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp
Quoted 4 lines
Quoted 1 line
Signed-off-by Oliver Hartkopp <[email protected]>I'm a little confused by the SoB. Does this mean you've applied it?
No. Marc will apply the patch.
My SoB is probably not needed in this context.
ACK
Quoted 2 lines
But Marc was sometimes asking
for it when I commented and discussed patches in the past.
Quoted 7 lines
The rule is: if you post a patch, your S-o-b has to be the last S-o-b in the line.
Quoted 1 line
I also thought Marc would add the Fixes tag on his own.
If you add it in the thread, b-4 will pick it up automatically and this less work for me :)
Any luck with this one Marc.
This should be send to the -rcs ASAP please.
Signature · 1 line
Lee Jones
Quoted 12 lines · Lee Jones
Commit
f1b4e32aca08("can: bcm: usecall_rcu()instead of costlysynchronize_rcu()") removed thesynchronize_rcu()call frombcm_delete_rx_op()and introduced theRX_NO_AUTOTIMERflag to prevent timers from being rearmed during deletion. However, it only applied this check toop->timerviabcm_rx_starttimer().It missed the fact that
op->thrtimercan also be rearmed by an in-flightbcm_rx_handler()(which runs as an RCU reader) viabcm_rx_update_and_send(). This allowsop->thrtimerto be queued afterbcm_remove_op()has already cancelled it, leading to a use-after-free when the timer fires on the deferred-freed structbcm_op.
Quoted 5 lines
Address the omission by checking the
RX_NO_AUTOTIMERflag inbcm_rx_update_and_send()before startingop->thrtimer, effectively preventing it from being rearmed concurrently with teardown.Signed-off-by Lee Jones <[email protected]>
Applied to linux-can.
Thanks,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |