Commit 424e95d
can: isotp: fix tx.buf use-after-free in isotp_sendmsg()
isotp_sendmsg() uses only cmpxchg() on so->tx.state to serialize access
to so->tx.buf. isotp_release() waits for ISOTP_IDLE via
wait_event_interruptible() and then calls kfree(so->tx.buf).
If a signal interrupts the wait_event_interruptible() inside close()
while tx.state is ISOTP_SENDING, the loop exits early and release
proceeds to force ISOTP_SHUTDOWN and continues to kfree(so->tx.buf)
while sendmsg may still be reading so->tx.buf for the final CAN frame
in isotp_fill_dataframe().
The so->tx.buf can be allocated once when the standard tx.buf length needs
to be extended. Move the kfree() of this potentially extended tx.buf to
sk_destruct time when either isotp_sendmsg() and isotp_release() are done.
Fixes: 96d1c81 ("can: isotp: add module parameter for maximum pdu size")
Cc: [email protected]
Reported-by: Ali Norouzi <[email protected]>
Co-developed-by: Ali Norouzi <[email protected]>
Signed-off-by: Ali Norouzi <[email protected]>
Signed-off-by: Oliver Hartkopp <[email protected]>
Link: https://patch.msgid.link/20260319-fix-can-gw-and-can-isotp-v2-2-c45d52c6d2d8@pengutronix.de
Signed-off-by: Marc Kleine-Budde <[email protected]>1 parent b9c310d commit 424e95d
1 file changed
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1248 | 1248 | | |
1249 | 1249 | | |
1250 | 1250 | | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | 1251 | | |
1258 | 1252 | | |
1259 | 1253 | | |
| |||
1622 | 1616 | | |
1623 | 1617 | | |
1624 | 1618 | | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
1625 | 1634 | | |
1626 | 1635 | | |
1627 | 1636 | | |
| |||
1666 | 1675 | | |
1667 | 1676 | | |
1668 | 1677 | | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
1669 | 1681 | | |
1670 | 1682 | | |
1671 | 1683 | | |
| |||
0 commit comments