can: isotp: prevent race between isotp_bind() and isotp_setsockopt()
authorNorbert Slusarek <nslusarek@gmx.net>
Tue, 11 May 2021 22:43:54 +0000 (00:43 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 12 May 2021 06:52:47 +0000 (08:52 +0200)
commit2b17c400aeb44daf041627722581ade527bb3c1d
tree9698aa0e13520c2f97bc508c37a19a98906f751b
parent440c3247cba3d9433ac435d371dd7927d68772a7
can: isotp: prevent race between isotp_bind() and isotp_setsockopt()

A race condition was found in isotp_setsockopt() which allows to
change socket options after the socket was bound.
For the specific case of SF_BROADCAST support, this might lead to possible
use-after-free because can_rx_unregister() is not called.

Checking for the flag under the socket lock in isotp_bind() and taking
the lock in isotp_setsockopt() fixes the issue.

Fixes: 921ca574cd38 ("can: isotp: add SF_BROADCAST support for functional addressing")
Link: https://lore.kernel.org/r/trinity-e6ae9efa-9afb-4326-84c0-f3609b9b8168-1620773528307@3c-app-gmx-bs06
Reported-by: Norbert Slusarek <nslusarek@gmx.net>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Norbert Slusarek <nslusarek@gmx.net>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/isotp.c