* [PATCH net 0/2] pull-request: can 2023-03-27
@ 2023-03-27 12:48 Marc Kleine-Budde
2023-03-27 12:48 ` [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue() Marc Kleine-Budde
2023-03-27 12:48 ` [PATCH net 2/2] can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write Marc Kleine-Budde
0 siblings, 2 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2023-03-27 12:48 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel
Hello netdev-team,
this is a pull request of 2 patches for net/master.
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.
regards,
Marc
---
The following changes since commit 45977e58ce65ed0459edc9a0466d9dfea09463f5:
net: dsa: b53: mmap: add phy ops (2023-03-27 08:31:34 +0100)
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-6.3-20230327
for you to fetch changes up to 2b4c99f7d9a57ecd644eda9b1fb0a1072414959f:
can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write (2023-03-27 14:40:45 +0200)
----------------------------------------------------------------
linux-can-fixes-for-6.3-20230327
----------------------------------------------------------------
Ivan Orlov (1):
can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write
Oleksij Rempel (1):
can: j1939: prevent deadlock by moving j1939_sk_errqueue()
net/can/bcm.c | 16 ++++++++++------
net/can/j1939/transport.c | 8 ++++++--
2 files changed, 16 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue()
2023-03-27 12:48 [PATCH net 0/2] pull-request: can 2023-03-27 Marc Kleine-Budde
@ 2023-03-27 12:48 ` Marc Kleine-Budde
2023-03-28 2:50 ` patchwork-bot+netdevbpf
2023-03-27 12:48 ` [PATCH net 2/2] can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write Marc Kleine-Budde
1 sibling, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2023-03-27 12:48 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Oleksij Rempel,
syzbot+ee1cd780f69483a8616b, Hillf Danton, stable,
Marc Kleine-Budde
From: Oleksij Rempel <o.rempel@pengutronix.de>
This commit addresses a deadlock situation that can occur in certain
scenarios, such as when running data TP/ETP transfer and subscribing to
the error queue while receiving a net down event. The deadlock involves
locks in the following order:
3
j1939_session_list_lock -> active_session_list_lock
j1939_session_activate
...
j1939_sk_queue_activate_next -> sk_session_queue_lock
...
j1939_xtp_rx_eoma_one
2
j1939_sk_queue_drop_all -> sk_session_queue_lock
...
j1939_sk_netdev_event_netdown -> j1939_socks_lock
j1939_netdev_notify
1
j1939_sk_errqueue -> j1939_socks_lock
__j1939_session_cancel -> active_session_list_lock
j1939_tp_rxtimer
CPU0 CPU1
---- ----
lock(&priv->active_session_list_lock);
lock(&jsk->sk_session_queue_lock);
lock(&priv->active_session_list_lock);
lock(&priv->j1939_socks_lock);
The solution implemented in this commit is to move the
j1939_sk_errqueue() call out of the active_session_list_lock context,
thus preventing the deadlock situation.
Reported-by: syzbot+ee1cd780f69483a8616b@syzkaller.appspotmail.com
Fixes: 5b9272e93f2e ("can: j1939: extend UAPI to notify about RX status")
Co-developed-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/all/20230324130141.2132787-1-o.rempel@pengutronix.de
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/j1939/transport.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index fce9b9ebf13f..fb92c3609e17 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1124,8 +1124,6 @@ static void __j1939_session_cancel(struct j1939_session *session,
if (session->sk)
j1939_sk_send_loop_abort(session->sk, session->err);
- else
- j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
}
static void j1939_session_cancel(struct j1939_session *session,
@@ -1140,6 +1138,9 @@ static void j1939_session_cancel(struct j1939_session *session,
}
j1939_session_list_unlock(session->priv);
+
+ if (!session->sk)
+ j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
}
static enum hrtimer_restart j1939_tp_txtimer(struct hrtimer *hrtimer)
@@ -1253,6 +1254,9 @@ static enum hrtimer_restart j1939_tp_rxtimer(struct hrtimer *hrtimer)
__j1939_session_cancel(session, J1939_XTP_ABORT_TIMEOUT);
}
j1939_session_list_unlock(session->priv);
+
+ if (!session->sk)
+ j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_ABORT);
}
j1939_session_put(session);
base-commit: 45977e58ce65ed0459edc9a0466d9dfea09463f5
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net 2/2] can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write
2023-03-27 12:48 [PATCH net 0/2] pull-request: can 2023-03-27 Marc Kleine-Budde
2023-03-27 12:48 ` [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue() Marc Kleine-Budde
@ 2023-03-27 12:48 ` Marc Kleine-Budde
1 sibling, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2023-03-27 12:48 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Ivan Orlov,
syzbot+c9bfd85eca611ebf5db1, Oliver Hartkopp, Marc Kleine-Budde
From: Ivan Orlov <ivan.orlov0322@gmail.com>
Syzkaller reported the following issue:
=====================================================
BUG: KMSAN: uninit-value in aio_rw_done fs/aio.c:1520 [inline]
BUG: KMSAN: uninit-value in aio_write+0x899/0x950 fs/aio.c:1600
aio_rw_done fs/aio.c:1520 [inline]
aio_write+0x899/0x950 fs/aio.c:1600
io_submit_one+0x1d1c/0x3bf0 fs/aio.c:2019
__do_sys_io_submit fs/aio.c:2078 [inline]
__se_sys_io_submit+0x293/0x770 fs/aio.c:2048
__x64_sys_io_submit+0x92/0xd0 fs/aio.c:2048
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
Uninit was created at:
slab_post_alloc_hook mm/slab.h:766 [inline]
slab_alloc_node mm/slub.c:3452 [inline]
__kmem_cache_alloc_node+0x71f/0xce0 mm/slub.c:3491
__do_kmalloc_node mm/slab_common.c:967 [inline]
__kmalloc+0x11d/0x3b0 mm/slab_common.c:981
kmalloc_array include/linux/slab.h:636 [inline]
bcm_tx_setup+0x80e/0x29d0 net/can/bcm.c:930
bcm_sendmsg+0x3a2/0xce0 net/can/bcm.c:1351
sock_sendmsg_nosec net/socket.c:714 [inline]
sock_sendmsg net/socket.c:734 [inline]
sock_write_iter+0x495/0x5e0 net/socket.c:1108
call_write_iter include/linux/fs.h:2189 [inline]
aio_write+0x63a/0x950 fs/aio.c:1600
io_submit_one+0x1d1c/0x3bf0 fs/aio.c:2019
__do_sys_io_submit fs/aio.c:2078 [inline]
__se_sys_io_submit+0x293/0x770 fs/aio.c:2048
__x64_sys_io_submit+0x92/0xd0 fs/aio.c:2048
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
CPU: 1 PID: 5034 Comm: syz-executor350 Not tainted 6.2.0-rc6-syzkaller-80422-geda666ff2276 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
=====================================================
We can follow the call chain and find that 'bcm_tx_setup' function
calls 'memcpy_from_msg' to copy some content to the newly allocated
frame of 'op->frames'. After that the 'len' field of copied structure
being compared with some constant value (64 or 8). However, if
'memcpy_from_msg' returns an error, we will compare some uninitialized
memory. This triggers 'uninit-value' issue.
This patch will add 'memcpy_from_msg' possible errors processing to
avoid uninit-value issue.
Tested via syzkaller
Reported-by: syzbot+c9bfd85eca611ebf5db1@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=47f897f8ad958bbde5790ebf389b5e7e0a345089
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Fixes: 6f3b911d5f29b ("can: bcm: add support for CAN FD frames")
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20230314120445.12407-1-ivan.orlov0322@gmail.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/bcm.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 27706f6ace34..a962ec2b8ba5 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -941,6 +941,8 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
cf = op->frames + op->cfsiz * i;
err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
+ if (err < 0)
+ goto free_op;
if (op->flags & CAN_FD_FRAME) {
if (cf->len > 64)
@@ -950,12 +952,8 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
err = -EINVAL;
}
- if (err < 0) {
- if (op->frames != &op->sframe)
- kfree(op->frames);
- kfree(op);
- return err;
- }
+ if (err < 0)
+ goto free_op;
if (msg_head->flags & TX_CP_CAN_ID) {
/* copy can_id into frame */
@@ -1026,6 +1024,12 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
bcm_tx_start_timer(op);
return msg_head->nframes * op->cfsiz + MHSIZ;
+
+free_op:
+ if (op->frames != &op->sframe)
+ kfree(op->frames);
+ kfree(op);
+ return err;
}
/*
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue()
2023-03-27 12:48 ` [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue() Marc Kleine-Budde
@ 2023-03-28 2:50 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-28 2:50 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: netdev, davem, kuba, linux-can, kernel, o.rempel,
syzbot+ee1cd780f69483a8616b, hdanton, stable
Hello:
This series was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:
On Mon, 27 Mar 2023 14:48:06 +0200 you wrote:
> From: Oleksij Rempel <o.rempel@pengutronix.de>
>
> This commit addresses a deadlock situation that can occur in certain
> scenarios, such as when running data TP/ETP transfer and subscribing to
> the error queue while receiving a net down event. The deadlock involves
> locks in the following order:
>
> [...]
Here is the summary with links:
- [net,1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue()
https://git.kernel.org/netdev/net/c/d1366b283d94
- [net,2/2] can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write
https://git.kernel.org/netdev/net/c/2b4c99f7d9a5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-28 2:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27 12:48 [PATCH net 0/2] pull-request: can 2023-03-27 Marc Kleine-Budde
2023-03-27 12:48 ` [PATCH net 1/2] can: j1939: prevent deadlock by moving j1939_sk_errqueue() Marc Kleine-Budde
2023-03-28 2:50 ` patchwork-bot+netdevbpf
2023-03-27 12:48 ` [PATCH net 2/2] can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write Marc Kleine-Budde
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.