Skip to content

Commit ccf78f7

Browse files
committed
Merge tag 'linux-can-fixes-for-6.17-20250910' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2025-09-10 The 1st patch is by Alex Tran and fixes the Documentation of the struct bcm_msg_head. Davide Caratti's patch enabled the VCAN driver as a module for the Linux self tests. Tetsuo Handa contributes 3 patches that fix various problems in the CAN j1939 protocol. Anssi Hannula's patch fixes a potential use-after-free in the xilinx_can driver. Geert Uytterhoeven's patch fixes the rcan_can's suspend to RAM on R-Car Gen3 using PSCI. * tag 'linux-can-fixes-for-6.17-20250910' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: rcar_can: rcar_can_resume(): fix s2ram with PSCI can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB can: j1939: j1939_local_ecu_get(): undo increment when j1939_local_ecu_get() fails can: j1939: j1939_sk_bind(): call j1939_priv_put() immediately when j1939_local_ecu_get() failed can: j1939: implement NETDEV_UNREGISTER notification handler selftests: can: enable CONFIG_CAN_VCAN as a module docs: networking: can: change bcm_msg_head frames member to support flexible array ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents a2ddf8a + 5c793af commit ccf78f7

File tree

8 files changed

+73
-17
lines changed

8 files changed

+73
-17
lines changed

Documentation/networking/can.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ The broadcast manager sends responses to user space in the same form:
742742
struct timeval ival1, ival2; /* count and subsequent interval */
743743
canid_t can_id; /* unique can_id for task */
744744
__u32 nframes; /* number of can_frames following */
745-
struct can_frame frames[0];
745+
struct can_frame frames[];
746746
};
747747
748748
The aligned payload 'frames' uses the same basic CAN frame structure defined

drivers/net/can/rcar/rcar_can.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ static int rcar_can_resume(struct device *dev)
861861
{
862862
struct net_device *ndev = dev_get_drvdata(dev);
863863
struct rcar_can_priv *priv = netdev_priv(ndev);
864-
u16 ctlr;
865864
int err;
866865

867866
if (!netif_running(ndev))
@@ -873,12 +872,7 @@ static int rcar_can_resume(struct device *dev)
873872
return err;
874873
}
875874

876-
ctlr = readw(&priv->regs->ctlr);
877-
ctlr &= ~RCAR_CAN_CTLR_SLPM;
878-
writew(ctlr, &priv->regs->ctlr);
879-
ctlr &= ~RCAR_CAN_CTLR_CANM;
880-
writew(ctlr, &priv->regs->ctlr);
881-
priv->can.state = CAN_STATE_ERROR_ACTIVE;
875+
rcar_can_start(ndev);
882876

883877
netif_device_attach(ndev);
884878
netif_start_queue(ndev);

drivers/net/can/xilinx_can.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,6 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
690690
dlc |= XCAN_DLCR_EDL_MASK;
691691
}
692692

693-
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
694-
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
695-
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
696-
else
697-
can_put_echo_skb(skb, ndev, 0, 0);
698-
699-
priv->tx_head++;
700-
701693
priv->write_reg(priv, XCAN_FRAME_ID_OFFSET(frame_offset), id);
702694
/* If the CAN frame is RTR frame this write triggers transmission
703695
* (not on CAN FD)
@@ -730,6 +722,14 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
730722
data[1]);
731723
}
732724
}
725+
726+
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
727+
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
728+
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
729+
else
730+
can_put_echo_skb(skb, ndev, 0, 0);
731+
732+
priv->tx_head++;
733733
}
734734

735735
/**

net/can/j1939/bus.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,11 @@ int j1939_local_ecu_get(struct j1939_priv *priv, name_t name, u8 sa)
290290
if (!ecu)
291291
ecu = j1939_ecu_create_locked(priv, name);
292292
err = PTR_ERR_OR_ZERO(ecu);
293-
if (err)
293+
if (err) {
294+
if (j1939_address_is_unicast(sa))
295+
priv->ents[sa].nusers--;
294296
goto done;
297+
}
295298

296299
ecu->nusers++;
297300
/* TODO: do we care if ecu->addr != sa? */

net/can/j1939/j1939-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ void j1939_priv_get(struct j1939_priv *priv);
212212

213213
/* notify/alert all j1939 sockets bound to ifindex */
214214
void j1939_sk_netdev_event_netdown(struct j1939_priv *priv);
215+
void j1939_sk_netdev_event_unregister(struct j1939_priv *priv);
215216
int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk);
216217
void j1939_tp_init(struct j1939_priv *priv);
217218

net/can/j1939/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ static int j1939_netdev_notify(struct notifier_block *nb,
377377
j1939_sk_netdev_event_netdown(priv);
378378
j1939_ecu_unmap_all(priv);
379379
break;
380+
case NETDEV_UNREGISTER:
381+
j1939_sk_netdev_event_unregister(priv);
382+
break;
380383
}
381384

382385
j1939_priv_put(priv);

net/can/j1939/socket.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
521521
ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa);
522522
if (ret) {
523523
j1939_netdev_stop(priv);
524+
jsk->priv = NULL;
525+
synchronize_rcu();
526+
j1939_priv_put(priv);
524527
goto out_release_sock;
525528
}
526529

@@ -1300,6 +1303,55 @@ void j1939_sk_netdev_event_netdown(struct j1939_priv *priv)
13001303
read_unlock_bh(&priv->j1939_socks_lock);
13011304
}
13021305

1306+
void j1939_sk_netdev_event_unregister(struct j1939_priv *priv)
1307+
{
1308+
struct sock *sk;
1309+
struct j1939_sock *jsk;
1310+
bool wait_rcu = false;
1311+
1312+
rescan: /* The caller is holding a ref on this "priv" via j1939_priv_get_by_ndev(). */
1313+
read_lock_bh(&priv->j1939_socks_lock);
1314+
list_for_each_entry(jsk, &priv->j1939_socks, list) {
1315+
/* Skip if j1939_jsk_add() is not called on this socket. */
1316+
if (!(jsk->state & J1939_SOCK_BOUND))
1317+
continue;
1318+
sk = &jsk->sk;
1319+
sock_hold(sk);
1320+
read_unlock_bh(&priv->j1939_socks_lock);
1321+
/* Check if j1939_jsk_del() is not yet called on this socket after holding
1322+
* socket's lock, for both j1939_sk_bind() and j1939_sk_release() call
1323+
* j1939_jsk_del() with socket's lock held.
1324+
*/
1325+
lock_sock(sk);
1326+
if (jsk->state & J1939_SOCK_BOUND) {
1327+
/* Neither j1939_sk_bind() nor j1939_sk_release() called j1939_jsk_del().
1328+
* Make this socket no longer bound, by pretending as if j1939_sk_bind()
1329+
* dropped old references but did not get new references.
1330+
*/
1331+
j1939_jsk_del(priv, jsk);
1332+
j1939_local_ecu_put(priv, jsk->addr.src_name, jsk->addr.sa);
1333+
j1939_netdev_stop(priv);
1334+
/* Call j1939_priv_put() now and prevent j1939_sk_sock_destruct() from
1335+
* calling the corresponding j1939_priv_put().
1336+
*
1337+
* j1939_sk_sock_destruct() is supposed to call j1939_priv_put() after
1338+
* an RCU grace period. But since the caller is holding a ref on this
1339+
* "priv", we can defer synchronize_rcu() until immediately before
1340+
* the caller calls j1939_priv_put().
1341+
*/
1342+
j1939_priv_put(priv);
1343+
jsk->priv = NULL;
1344+
wait_rcu = true;
1345+
}
1346+
release_sock(sk);
1347+
sock_put(sk);
1348+
goto rescan;
1349+
}
1350+
read_unlock_bh(&priv->j1939_socks_lock);
1351+
if (wait_rcu)
1352+
synchronize_rcu();
1353+
}
1354+
13031355
static int j1939_sk_no_ioctlcmd(struct socket *sock, unsigned int cmd,
13041356
unsigned long arg)
13051357
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_CAN=m
2+
CONFIG_CAN_DEV=m
3+
CONFIG_CAN_VCAN=m

0 commit comments

Comments
 (0)