From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3325330DEDC for ; Sat, 25 Jul 2026 19:53:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785009206; cv=none; b=NNBO7mSqsJYXTzbZKLqrCngxCk4WVGxQqv+CCJpwWdxgyzUbJn9Lg3X9uBTaKeVEeLOtkiPYLV7OFSrKtacbZXjgvbKCWhrzIudzq/LKKII4KblkGJzouTizd5mdfJRvYVjh9k4zIhi4J8pxXo5MO0l+GptsEtQgfPZnmND167Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785009206; c=relaxed/simple; bh=7ZN6T1/AH75YPS/XHcc9nUnZtBrIkvt1Zj9ameGBJLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OqPvGw37v9D13nQ+azn+hUljIa3vjg9Y5hzIdnRSf6gWq8m9xm9h0/Mg4s+anJonAoLyQN7YRm2N5Zco8s/zxsvcvPzZaKHSKR1XAqmlW4zHUBM8YlUwKdMk9PnUq0vmY4yMckX+mwpFlWT0BTILJ4LIALVK/5fEHnkawc/uNfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gFf92UED; arc=none smtp.client-ip=209.85.167.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gFf92UED" Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-4a416619cb2so729062b6e.3 for ; Sat, 25 Jul 2026 12:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785009204; x=1785614004; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xH26qF1R9t6qCKYPvNS6zoA9qXRJOpqJZW8w6fjc860=; b=gFf92UEDUnetF5SZGlJ9cm6w1UrlDK9xOcC2yaVi0IsoAPPb+G4LhcVteMchO8Ga5V bHV8mI/CPIzscRXbZOglutbahJj2weE3QDjSKgCHatGrovFr2FXD4qpqSZKvIERCDnVF wgrzCu+daybSTwOvI6D/K3ig0kCU8QAKgS+H37dnQFWrr5I52lvt1UcOH6IjZcxz5HkW YNHfXdirxJufXmvkOkOi/0MPQx+fOUULTIucbZ7moKT9l2qRhBr04A5DZi+TOOsVYXmi LTprsB03ONciDZaRa8ykOUXb9OYsLakYIGQglEOL7hN3oIRCaFCm29x1PZEUiiB/nzs/ 5ODw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785009204; x=1785614004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xH26qF1R9t6qCKYPvNS6zoA9qXRJOpqJZW8w6fjc860=; b=ldzT6uwwOmn6RKRGrwQVCcecax24FGbSnO315DX+uKQXLmw3y6iImh0R/biLqz7eet piZcNBe+ZOPL2SUmzrEM8+FeXEm5oWnzQ5UqJUULKGtdFR/ORWP6Mb/9EnMCseHPB3n0 x5w5GzRF4Lewv8KgU7Y22Z7YY0Y5uehZwa/hDWhr+mwdxE27h/ppTlRufGisJV7MaTXK AX0aU25A0AHaoG8dE73mqGHpOPpLTt2I/yCOlVwZMbMboyGvxRoJBjB6rZZvL6ZihRen Odadm5d7JFv+ha/jQUqmT4l4RrUW8YP4swOZ1Udqy5ALcUNDpExLhjRM/XTC6hdOtvEZ qyAQ== X-Forwarded-Encrypted: i=1; AHgh+Rr9EJKegi6o4sp6560EGA/O2CCnJLvM552tjNMkEdOrXgDgvHCB7gkMAoqLivNMByjulrEEJGvgxyPDzaM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0TbmTGR4EUGZ23aN8vp3TZ1Gda2Tstp6DhA2AL9Y0L2J8MyFt h+o1VYrMkYw3aM9x9N0nCYdtQ0GVjhvmJMVVxlLuUKcZz+e/RcOf5MSC X-Gm-Gg: AR+sD13A/QsoOk8PsFkeKPDP6u65syhzNix2z2uyuLs5IB1oT3a5hEsv7t0Cjk+RgOg O5CS9Ap0si0nJ87kf6DQin5vxD6FHueaMrpFUhvJpQFn3zDiJKWtz37VPycYdBtkG2P04u997hE 8rp97XLDlDzM7hmfh5HSdFQaRzF7bpbRQBOjRe4n2i1MJMZTckhxdwh95a8Nh7ZpgVILZPB4Q5L 2fbQTG8ADutMW6YUt+eYViTo3Ftv0AqKE3oC6ek4kffA6vj0uEZn1lclEuTK6g16Ur3m/tJeiu4 spPolsdQmjJN76jL/B4BX4kKEGnXwEa/KfgipnF7Mf76vWYIiDxxpHJNjilT+wOf3gbzez8PPGq DxgZc70+f3pXPdZFCJuGT+Pkj+GvmP7X5i01jz6BlcUH6V16FHdu45VAP+71GmF07/aUweryHyR Eld7wmQ0k= X-Received: by 2002:a05:6808:1a29:b0:4a4:934:b316 with SMTP id 5614622812f47-4ab6a15c6acmr2921176b6e.21.1785009203969; Sat, 25 Jul 2026 12:53:23 -0700 (PDT) Received: from beelink.. ([155.133.15.206]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-45767488299sm11082928fac.16.2026.07.25.12.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 12:53:23 -0700 (PDT) From: Aldo Ariel Panzardo To: Pauli Virtanen Cc: Aldo Ariel Panzardo , Luiz Augusto von Dentz , marcel@holtmann.org, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] Bluetooth: SCO: give the socket its own sco_conn reference Date: Sat, 25 Jul 2026 16:52:59 -0300 Message-ID: <20260725195310.970347-1-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Pauli, Thanks a lot for the detailed review and for sketching the hci_conn ownership rule -- v3 incorporates it (you're on the patch as Suggested-by): sco_conn_add() now consumes one hci_conn reference and the sco_conn owns it for its whole lifetime, sco_connect() no longer drops hcon on its error paths, sco_connect_cfm() takes a reference before sco_conn_add() (and drops it again if the allocation fails), and the hci_conn_hold() in sco_conn_ready() is gone. That removes the double hci_conn_drop() you spotted on the error paths. One correction to v2: I had also dropped the if (conn->sk) sco_pi(conn->sk)->conn = NULL; clearing in sco_conn_free() as "unreachable". v3 keeps it. Testing the close()-vs-Disconnection-Complete race under KASAN showed that removing it reintroduces a use-after-free on the sco_sock_release() path, so it stays. While validating this I built a /dev/vhci reproducer that races close() of an SCO socket against an injected Disconnection Complete over many iterations, on v7.2-rc4 with KASAN. It reproduces the sco_conn_del() over-put reliably on an unmodified tree (a few thousand iterations), and with this patch that over-put no longer fires. I want to be upfront that it does not leave the reproducer fully clean, though. With the over-put fixed, the same race still occasionally trips a separate use-after-free in the SCODATA receive path, which this patch does not touch: BUG: KASAN: slab-use-after-free in sco_conn_hold_unless_zero+0xbe/0x160 Write of size 4 by task kworker/u17:0 Workqueue: hci0 hci_rx_work Call Trace: sco_conn_hold_unless_zero+0xbe/0x160 sco_recv_scodata+0x13f/0x490 hci_rx_work+0x3af/0x730 sco_recv_scodata() takes conn from hcon->sco_data and calls sco_conn_hold_unless_zero() on it, but kref_get_unless_zero() only guards against a zero refcount, not against the sco_conn already having been freed and its memory reclaimed -- the read of the refcount itself is the UAF. It looks like a pre-existing race around the hcon->sco_data weak pointer rather than something introduced here, but I haven't yet isolated it on an otherwise-unmodified tree, so I didn't want to fold a fix into this patch blind. Happy to dig into that one next (it feels like the sco_conn lifetime wants a firmer owner for hcon->sco_data), either as a follow-up or however you'd prefer to see it handled. Let me know if you'd rather I respin this together with that. Thanks, Aldo