Skip to content

Commit ebd3b82

Browse files
committed
Merge tag 'linux-can-fixes-for-6.3-20230327' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2023-03-27 Oleksij Rempel and Hillf Danton contribute a patch for the CAN J1939 protocol that prevents a potential deadlock in j1939_sk_errqueue(). Ivan Orlov fixes an uninit-value in the CAN BCM protocol in the bcm_tx_setup() function. * tag 'linux-can-fixes-for-6.3-20230327' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can: can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write can: j1939: prevent deadlock by moving j1939_sk_errqueue() ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4f7702a + 2b4c99f commit ebd3b82

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

net/can/bcm.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
941941

942942
cf = op->frames + op->cfsiz * i;
943943
err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
944+
if (err < 0)
945+
goto free_op;
944946

945947
if (op->flags & CAN_FD_FRAME) {
946948
if (cf->len > 64)
@@ -950,12 +952,8 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
950952
err = -EINVAL;
951953
}
952954

953-
if (err < 0) {
954-
if (op->frames != &op->sframe)
955-
kfree(op->frames);
956-
kfree(op);
957-
return err;
958-
}
955+
if (err < 0)
956+
goto free_op;
959957

960958
if (msg_head->flags & TX_CP_CAN_ID) {
961959
/* copy can_id into frame */
@@ -1026,6 +1024,12 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
10261024
bcm_tx_start_timer(op);
10271025

10281026
return msg_head->nframes * op->cfsiz + MHSIZ;
1027+
1028+
free_op:
1029+
if (op->frames != &op->sframe)
1030+
kfree(op->frames);
1031+
kfree(op);
1032+
return err;
10291033
}
10301034

10311035
/*

net/can/j1939/transport.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,6 @@ static void __j1939_session_cancel(struct j1939_session *session,
11241124

11251125
if (session->sk)
11261126
j1939_sk_send_loop_abort(session->sk, session->err);
1127-
else
1128-
j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
11291127
}
11301128

11311129
static void j1939_session_cancel(struct j1939_session *session,
@@ -1140,6 +1138,9 @@ static void j1939_session_cancel(struct j1939_session *session,
11401138
}
11411139

11421140
j1939_session_list_unlock(session->priv);
1141+
1142+
if (!session->sk)
1143+
j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
11431144
}
11441145

11451146
static enum hrtimer_restart j1939_tp_txtimer(struct hrtimer *hrtimer)
@@ -1253,6 +1254,9 @@ static enum hrtimer_restart j1939_tp_rxtimer(struct hrtimer *hrtimer)
12531254
__j1939_session_cancel(session, J1939_XTP_ABORT_TIMEOUT);
12541255
}
12551256
j1939_session_list_unlock(session->priv);
1257+
1258+
if (!session->sk)
1259+
j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
12561260
}
12571261

12581262
j1939_session_put(session);

0 commit comments

Comments
 (0)