public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk)
@ 2026-04-21  2:51 SeungJu Cheon
  2026-04-21  2:51 ` [PATCH v2 1/2] Bluetooth: ISO: Fix data-race on dst in iso_sock_connect() SeungJu Cheon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: SeungJu Cheon @ 2026-04-21  2:51 UTC (permalink / raw)
  To: luiz.dentz, marcel
  Cc: linux-bluetooth, netdev, linux-kernel, me, skhan,
	linux-kernel-mentees, SeungJu Cheon

Found while auditing iso_pi(sk) field accesses after a KCSAN report.
Patch 1/2 is the reported race on iso_pi(sk)->dst in iso_sock_connect();
patch 2/2 covers related races on other iso_pi(sk) fields accessed in
iso_connect_{bis,cis}() and iso_connect_ind() that were found by
inspection during the same audit.

Changes in v2:
 - Patch 1/2: Use sa->iso_bdaddr directly instead of caching the
   bacmp() result in a local variable, as suggested by Luiz [1].
   This avoids reading from iso_pi(sk) entirely for the broadcast
   check.

 - Patch 2/2: No changes.

v1: https://lore.kernel.org/linux-bluetooth/20260418053239.128190-1-suunj1331@gmail.com/

[1] https://lore.kernel.org/linux-bluetooth/CABBYNZLBoU3byfK_G+=sTkBx3wNwEh2X6_7dG4+4LFtrc3Skpw@mail.gmail.com/

SeungJu Cheon (2):
  Bluetooth: ISO: Fix data-race on dst in iso_sock_connect()
  Bluetooth: ISO: Fix data-race on iso_pi(sk) in socket and HCI event
    paths

 net/bluetooth/iso.c | 56 +++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 25 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH 1/2] Bluetooth: ISO: Fix data-race on dst in iso_sock_connect()
@ 2026-04-18  5:34 SeungJu Cheon
  2026-04-18  6:17 ` Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk) bluez.test.bot
  0 siblings, 1 reply; 6+ messages in thread
From: SeungJu Cheon @ 2026-04-18  5:34 UTC (permalink / raw)
  To: luiz.dentz, marcel
  Cc: linux-bluetooth, netdev, linux-kernel, me, skhan,
	linux-kernel-mentees, SeungJu Cheon

iso_sock_connect() copies the destination address into
iso_pi(sk)->dst under lock_sock, then releases the lock and reads
it back with bacmp() to decide between the CIS and BIS connect
paths:

    lock_sock(sk);
    bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr);
    iso_pi(sk)->dst_type = sa->iso_bdaddr_type;
    release_sock(sk);

    if (bacmp(&iso_pi(sk)->dst, BDADDR_ANY))  // <- no lock held

This read after release_sock() races with any concurrent write to
iso_pi(sk)->dst on the same socket.

Fix by performing the bacmp() inside the lock_sock critical section
and caching the result in a local variable.

This patch addresses only the bacmp() race in iso_sock_connect();
other unprotected iso_pi(sk) accesses are fixed separately in the
next patch.

KCSAN report:

BUG: KCSAN: data-race in memcmp+0x39/0xb0

race at unknown origin, with read to 0xffff8f96ea66dde3 of 1 bytes by task 549 on cpu 1:
 memcmp+0x39/0xb0
 iso_sock_connect+0x275/0xb40
 __sys_connect_file+0xbd/0xe0
 __sys_connect+0xe0/0x110
 __x64_sys_connect+0x40/0x50
 x64_sys_call+0xcad/0x1c60
 do_syscall_64+0x133/0x590
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

value changed: 0x00 -> 0xee

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 549 Comm: iso_race_combin Not tainted 7.0.0-08391-g1d51b370a0f8 #40 PREEMPT(lazy)

Fixes: ccf74f2390d6 ("Bluetooth: Add BTPROTO_ISO socket type")
Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
---
 net/bluetooth/iso.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c
index be145e2736b7..14963ba68597 100644
--- a/net/bluetooth/iso.c
+++ b/net/bluetooth/iso.c
@@ -1169,6 +1169,7 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
 	struct sockaddr_iso *sa = (struct sockaddr_iso *)addr;
 	struct sock *sk = sock->sk;
 	int err;
+	bool bcast;
 
 	BT_DBG("sk %p", sk);
 
@@ -1191,9 +1192,11 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
 	bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr);
 	iso_pi(sk)->dst_type = sa->iso_bdaddr_type;
 
+	bcast = !bacmp(&iso_pi(sk)->dst, BDADDR_ANY);
+
 	release_sock(sk);
 
-	if (bacmp(&iso_pi(sk)->dst, BDADDR_ANY))
+	if (!bcast)
 		err = iso_connect_cis(sk);
 	else
 		err = iso_connect_bis(sk);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-21 17:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21  2:51 [PATCH v2 0/2] Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk) SeungJu Cheon
2026-04-21  2:51 ` [PATCH v2 1/2] Bluetooth: ISO: Fix data-race on dst in iso_sock_connect() SeungJu Cheon
2026-04-21  4:08   ` Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk) bluez.test.bot
2026-04-21  2:51 ` [PATCH v2 2/2] Bluetooth: ISO: Fix data-race on iso_pi(sk) in socket and HCI event paths SeungJu Cheon
2026-04-21 17:40 ` [PATCH v2 0/2] Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk) patchwork-bot+bluetooth
  -- strict thread matches above, loose matches on Subject: below --
2026-04-18  5:34 [PATCH 1/2] Bluetooth: ISO: Fix data-race on dst in iso_sock_connect() SeungJu Cheon
2026-04-18  6:17 ` Bluetooth: ISO: Fix KCSAN data-races on iso_pi(sk) bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox