]> git.baikalelectronics.ru Git - kernel.git/commit
can: isotp: isotp_sendmsg(): fix TX buffer concurrent access in isotp_sendmsg()
authorZiyang Xuan <william.xuanziyang@huawei.com>
Sat, 9 Oct 2021 07:40:30 +0000 (15:40 +0800)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Sun, 17 Oct 2021 12:18:21 +0000 (14:18 +0200)
commit351c22bce6d2a0009ef6b709540197ccbdcb59d8
treef27f25c918a99025f0886a9d0f7ee68a9f3595a3
parent57689dd34e183f5e283c47efcc83e3c228d06013
can: isotp: isotp_sendmsg(): fix TX buffer concurrent access in isotp_sendmsg()

When isotp_sendmsg() concurrent, tx.state of all TX processes can be
ISOTP_IDLE. The conditions so->tx.state != ISOTP_IDLE and
wq_has_sleeper(&so->wait) can not protect TX buffer from being
accessed by multiple TX processes.

We can use cmpxchg() to try to modify tx.state to ISOTP_SENDING firstly.
If the modification of the previous process succeed, the later process
must wait tx.state to ISOTP_IDLE firstly. Thus, we can ensure TX buffer
is accessed by only one process at the same time. And we should also
restore the original tx.state at the subsequent error processes.

Fixes: 3f9425168a78 ("can: add ISO 15765-2:2016 transport protocol")
Link: https://lore.kernel.org/all/c2517874fbdf4188585cf9ddf67a8fa74d5dbde5.1633764159.git.william.xuanziyang@huawei.com
Cc: stable@vger.kernel.org
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/isotp.c