From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-06-19 22:01:26
Hello Jakub, hello David,
this is a pull request of 5 patches for net/master.
The first patch is by Thadeu Lima de Souza Cascardo and fixes a
potential use-after-free in the CAN broadcast manager socket, by
delaying the release of struct bcm_op after synchronize_rcu().
Oliver Hartkopp's patch fixes a similar potential user-after-free in
the CAN gateway socket by synchronizing RCU operations before removing
gw job entry.
Another patch by Oliver Hartkopp fixes a potential use-after-free in
the ISOTP socket by omitting unintended hrtimer restarts on socket
release.
Oleksij Rempel's patch for the j1939 socket fixes a potential
use-after-free by setting the SOCK_RCU_FREE flag on the socket.
The last patch is by Pavel Skripkin and fixes a use-after-free in the
ems_usb CAN driver.
All patches are intended for stable and have stable@v.k.o on Cc.
regards,
Marc
---
The following changes since commit dda2626b86c2c1813b7bfdd10d2fdd849611fc97:
Merge branch 'ezchip-fixes' (2021-06-19 11:46:24 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-5.13-20210619
for you to fetch changes up to ab4a0b8fcb9a95c02909b62049811bd2e586aaa4:
net: can: ems_usb: fix use-after-free in ems_usb_disconnect() (2021-06-19 23:54:00 +0200)
----------------------------------------------------------------
linux-can-fixes-for-5.13-20210619
----------------------------------------------------------------
Oleksij Rempel (1):
can: j1939: j1939_sk_init(): set SOCK_RCU_FREE to call sk_destruct() after RCU is done
Oliver Hartkopp (2):
can: gw: synchronize rcu operations before removing gw job entry
can: isotp: isotp_release(): omit unintended hrtimer restart on socket release
Pavel Skripkin (1):
net: can: ems_usb: fix use-after-free in ems_usb_disconnect()
Thadeu Lima de Souza Cascardo (1):
can: bcm: delay release of struct bcm_op after synchronize_rcu()
drivers/net/can/usb/ems_usb.c | 3 ++-
net/can/bcm.c | 7 ++++++-
net/can/gw.c | 3 +++
net/can/isotp.c | 7 ++++---
net/can/j1939/main.c | 4 ++++
net/can/j1939/socket.c | 3 +++
6 files changed, 22 insertions(+), 5 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-06-19 22:01:30
From: Oliver Hartkopp <socketcan@hartkopp.net>
can_can_gw_rcv() is called under RCU protection, so after calling
can_rx_unregister(), we have to call synchronize_rcu in order to wait
for any RCU read-side critical sections to finish before removing the
kmem_cache entry with the referenced gw job entry.
Link: https://lore.kernel.org/r/20210618173645.2238-1-socketcan@hartkopp.net
Fixes: c1aabdf379bc ("can-gw: add netlink based CAN routing")
Cc: linux-stable <redacted>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/gw.c | 3 +++
1 file changed, 3 insertions(+)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-06-19 22:01:34
From: Thadeu Lima de Souza Cascardo <redacted>
can_rx_register() callbacks may be called concurrently to the call to
can_rx_unregister(). The callbacks and callback data, though, are
protected by RCU and the struct sock reference count.
So the callback data is really attached to the life of sk, meaning
that it should be released on sk_destruct. However, bcm_remove_op()
calls tasklet_kill(), and RCU callbacks may be called under RCU
softirq, so that cannot be used on kernels before the introduction of
HRTIMER_MODE_SOFT.
However, bcm_rx_handler() is called under RCU protection, so after
calling can_rx_unregister(), we may call synchronize_rcu() in order to
wait for any RCU read-side critical sections to finish. That is,
bcm_rx_handler() won't be called anymore for those ops. So, we only
free them, after we do that synchronize_rcu().
Fixes: ffd980f976e7 ("[CAN]: Add broadcast manager (bcm) protocol")
Link: https://lore.kernel.org/r/20210619161813.2098382-1-cascardo@canonical.com
Cc: linux-stable <redacted>
Reported-by: syzbot+0f7e7e5e2f4f40fa89c0@syzkaller.appspotmail.com
Reported-by: Norbert Slusarek <redacted>
Signed-off-by: Thadeu Lima de Souza Cascardo <redacted>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/bcm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-06-19 22:01:35
From: Oliver Hartkopp <socketcan@hartkopp.net>
When closing the isotp socket, the potentially running hrtimers are
canceled before removing the subscription for CAN identifiers via
can_rx_unregister().
This may lead to an unintended (re)start of a hrtimer in
isotp_rcv_cf() and isotp_rcv_fc() in the case that a CAN frame is
received by isotp_rcv() while the subscription removal is processed.
However, isotp_rcv() is called under RCU protection, so after calling
can_rx_unregister, we may call synchronize_rcu in order to wait for
any RCU read-side critical sections to finish. This prevents the
reception of CAN frames after hrtimer_cancel() and therefore the
unintended (re)start of the hrtimers.
Link: https://lore.kernel.org/r/20210618173713.2296-1-socketcan@hartkopp.net
Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol")
Cc: linux-stable <redacted>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/isotp.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
From: Marc Kleine-Budde <mkl@pengutronix.de> Date: 2021-06-19 22:01:37
From: Oleksij Rempel <o.rempel@pengutronix.de>
Set SOCK_RCU_FREE to let RCU to call sk_destruct() on completion.
Without this patch, we will run in to j1939_can_recv() after priv was
freed by j1939_sk_release()->j1939_sk_sock_destruct()
Fixes: 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct callback")
Link: https://lore.kernel.org/r/20210617130623.12705-1-o.rempel@pengutronix.de
Cc: linux-stable <redacted>
Reported-by: Thadeu Lima de Souza Cascardo <redacted>
Reported-by: syzbot+bdf710cfc41c186fdff3@syzkaller.appspotmail.com
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/j1939/main.c | 4 ++++
net/can/j1939/socket.c | 3 +++
2 files changed, 7 insertions(+)
@@ -193,6 +193,10 @@ static void j1939_can_rx_unregister(struct j1939_priv *priv)can_rx_unregister(dev_net(ndev),ndev,J1939_CAN_ID,J1939_CAN_MASK,j1939_can_recv,priv);+/* The last reference of priv is dropped by the RCU deferred+*j1939_sk_sock_destruct()ofthelastsocket,sowecan+*safelydropthisreferencehere.+*/j1939_priv_put(priv);}
@@ -398,6 +398,9 @@ static int j1939_sk_init(struct sock *sk)atomic_set(&jsk->skb_pending,0);spin_lock_init(&jsk->sk_session_queue_lock);INIT_LIST_HEAD(&jsk->sk_session_queue);++/* j1939_sk_sock_destruct() depends on SOCK_RCU_FREE flag */+sock_set_flag(sk,SOCK_RCU_FREE);sk->sk_destruct=j1939_sk_sock_destruct;sk->sk_protocol=CAN_J1939;
Hello:
This pull request was applied to netdev/net.git (refs/heads/master):
On Sun, 20 Jun 2021 00:01:10 +0200 you wrote:
Hello Jakub, hello David,
this is a pull request of 5 patches for net/master.
The first patch is by Thadeu Lima de Souza Cascardo and fixes a
potential use-after-free in the CAN broadcast manager socket, by
delaying the release of struct bcm_op after synchronize_rcu().
[...]