From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796151818; b=GjvpYxe1kgw7FE8WeQO2ojVrI76D3ZUwAMrHXSZF3vGa2hFeyAzrkY72WJxI2C8AyOSg 4+6t41DnUIz3GWmonc5H6N4w+D1S4PytF5IUd9CBJcFtLGUnC3rlbtvhTKLA4zxN6mIDA uQTIUsZe6SgUiOxnqnkUCn+Z4B2uRXtf2sgK4OtwP0y479NZg9rCUpIiDGF4UzRxJiSA5 fTMTtdPEccXJBpVDimzCqKFCqtYbIFyO3tZp+baszLCtFbFEKi5tZkqPCSrsV1Xo0zzf4 Vr7swWtw1FSDHJq767hW1UiMfS3xNLguq8SE0iGG0xThq3qtMa1sr/d4f8CW7eNlAYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796151818; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=VCBBjXa7oMpear2ZWFWucKN/k4U9H6GStUvsg+c/X/8=; b=L54SxRbdsutJawP81hEmChsJe+ZoV1+/k4fHf9TaFcy33mMKp0IC1NTmwN1rBpPgGDQd +RfRW+263GVfthFGmUqiMN0OSBnxIkOFi2I+MzlhNRNQEsQuyvSKoGUhFHA1uPOjya3FH rBZzGnfOQ4D6VSErEJF0bVcm+nJ/OXRTWIFKcCFB57COK7f1SKZbQo37cwhSZLWsas6G4 152lqERlXo9Mj5dpzYXZtThKsByE1mg/s7IO4+3S9z38YiJJdSGyLIYWdV1AnOc+4lMvJ Mr87ENsiR3wy3tVOfrPG75H0TrehoPBKq1G94F/lSFrWzbz3xX49unttgof4TBLZhTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GRoRHSm8; arc=none smtp.remote-ip=209.85.217.46 Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8599D606A322 for ; Tue, 1 Dec 2026 19:03:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8599D606A322 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.a=rsa-sha256 header.s=20260707 header.b=GRoRHSm8 Received: by mail-vs1-f46.google.com with SMTP id ada2fe7eead31-7cc0e865dd1so4166819137.1 for ; Tue, 01 Dec 2026 11:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796151817; x=1796756617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=VCBBjXa7oMpear2ZWFWucKN/k4U9H6GStUvsg+c/X/8=; b=GRoRHSm8OlflA0jxcsbj91Wy71dIFSD4Smsz3TpHUJaRgUY/wwmXRLhEcf/x4SGv3m TYaW21xf2KCYLjq0XPySOvrc92kSIQTpUGM8aw6aQWNupyFq3WkZJ9oOwOj+eBKN5ai5 Oh6MnaX2MCksp7X6BIcEQRhB7S9BB1WbGj22OeGkFrEuYULS0rna4aKaDMMF0nqNSS6b e6rBXgSerw2E4vRMtls+3mgB2tX4cvZ99yS+xWYrEL3B9hkQ+bpDKkM1/P/RaQr4OXrT nBp8qROP8sgSek1AdXxAyw1dmHMXNRPDv04glUBokFX8jku6SpTuLv0/c43wIa3LmiSj pJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796151817; x=1796756617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=VCBBjXa7oMpear2ZWFWucKN/k4U9H6GStUvsg+c/X/8=; b=c09YV5CzlYsDJ4Z+d0akBuxVyUWJQD5FrJceSpV/2mXMQ5bPzfI2SVQ2UeNYLZTu9H hDT8+IPnhjL+z2HBp843qa4Ww5mFLWTwTvAmJDbAJ5873PJnV0HjrNhVJK6zGa0C6zhR ApS89em6AVoUlYu1sghOaiVw/fFUWhLC79s42M28LP9CzzUe1FAXy81P58H598xfZr7M +9PcaTeoXm/DRT/Cq1uozagdCHLuqrcheTj46qt5RBJTlQuYsbXvDE8qp2tjViv9soVI qlEhtHXqF7PsdKVtR0frmcOQLcEGE0jcXLXfR7pF6qy4PSUMscPE7ATQGk8R7xMlWTXm pdyg== X-Gm-Message-State: APuU4Z/D+yT52K/t73W1tprGoKEva+1+Fr0r7os6XcIdOZmBhG/LOmCA EMKxaVUD4pWKxAOPZXeKsazSflP6RcWtDjXiM7WW35VsQ2ky4Y6Cogs+HT/I1txsD4g= X-Gm-Gg: AZFdTZfUthKEI26ebVDeatZACIi3eTEyHq6m0DOpaknroESEt+wYaZF1Av/cQoDvNTl xBXexUM0/0arvYsn+o1/jC8RMtyNjFydWbT686wnnNwnLvP+ysnTt6GDwtykeSTj2AxzLWBSV/D tM0p9G8YRQNKRm8YTt00RfT15Z75xewp+Rk3T1GoBvqy857h5pTFJRv2KRnhA52r0KNlBzQzvwL SvSURHLsLUZUJtRYs07pzNj1HJLiXlHj0GHXuSebUsn43lUsQ63YSI1nD+WyibVB6/OiON9Nywe RsqNd4vIDfztuKRDu+uXZCimTJOQRW+54ZIk/RvpSbjX22IxRMwpSWyhgAQFAV7MzW0f5ol6fWj aAJ7cxg2sVjf7NBrg8+FDIQYbe0NsEsTpx5FurNV39HNZeKFtBYRApUGDVc+MgQfiC93JdsqMbi 7nJC+zbfcWVlKEeFdmfGFtm81B4S2BoLJ/DtV7G1Zfg/nh6+PYHxnLs8mfn6eJ3NIzdnAfWkn52 B//YqO9CYfT0VPvl3KLfdA0S8l/XO/75H3NO0yEpkrz7REXs4IDBc8pS/3YAzwnDx6DrJ9D65W8 xu/iQmmImIRwRFn2S+B0rnwuvhRgG5mMtEOrm1qyKLhhPN1haujjmsAYyaXoYlLL6S/LZTarZjE zk7XrfwzCben9Astk7forlcqTeXU/1pJar3njOm6BPGCGoNA5Ct+OB1E= X-Received: by 2002:a05:6102:b03:b0:7d2:b199:6712 with SMTP id ada2fe7eead31-7d739629c4bmr24818675137.30.1796151817429; Tue, 01 Dec 2026 11:03:37 -0800 (PST) Received: from lvondent-mobl5 ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6dfc0b22sm38919229241.6.2026.12.01.11.03.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 11:03:37 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v12 6/6] Bluetooth: L2CAP: Don't offer deferred channels before security is met Date: Tue, 1 Dec 2026 14:03:25 -0500 Message-ID: <20261201190325.110874-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201190325.110874-1-luiz.dentz@gmail.com> References: <20261201190325.110874-1-luiz.dentz@gmail.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz A BR/EDR channel is moved to BT_CONNECT2 as soon as the connection request is answered as pending, no matter if it is waiting for the information exchange, for the link security or for userspace to authorize it, and the socket state follows the channel state. bt_accept_poll() assumes that a child in BT_CONNECT2 of a listener using BT_DEFER_SETUP is waiting to be authorized, and bt_accept_dequeue() returns any child of such a listener, so although the listener is only notified once the security is met, a listener that doesn't wait for it can accept() the child and then authorize it with recvmsg() while authentication is still pending. l2cap_sock_defer() then moves the channel to BT_CONFIG and responds with L2CAP_CR_SUCCESS, and if authentication fails afterwards the channel is left open since l2cap_security_cfm() doesn't close channels in BT_CONFIG. Fix this by only moving the socket to BT_CONNECT2 when the channel is offered to the listener with l2cap_sock_defer_cb(), which is only called once the security is met, and by only letting accept() return a child of a listener using BT_DEFER_SETUP once it is in BT_CONNECT2, as bt_accept_poll() does. The child stays in the accept queue so the backlog limit and the cleanup done when the listener is closed are not affected. Fixes: f66dc81f44d9 ("Bluetooth: Add support for deferring L2CAP connection setup") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/af_bluetooth.c | 6 +++++- net/bluetooth/l2cap_sock.c | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index 7758e9ea3848..103d61d13fbf 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c @@ -330,8 +330,12 @@ struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock) continue; } + /* With deferred setup only a child in BT_CONNECT2 has been + * offered to the listener, see bt_accept_poll(). + */ if (sk->sk_state == BT_CONNECTED || !newsock || - test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags)) { + (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags) && + sk->sk_state == BT_CONNECT2)) { bt_accept_unlink(sk); if (newsock) sock_graft(sk, newsock); diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 4e45da2b5975..4e7787ec033c 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1861,7 +1861,13 @@ static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state, lock_sock(sk); - sk->sk_state = state; + /* BT_CONNECT2 also covers a channel still waiting for the information + * exchange or link security. Only l2cap_sock_defer_cb() moves the + * socket to BT_CONNECT2, once the channel can be offered to the + * listener. + */ + if (state != BT_CONNECT2) + sk->sk_state = state; if (err) sk->sk_err = err; @@ -1929,6 +1935,8 @@ static void l2cap_sock_defer_cb(struct l2cap_chan *chan) lock_sock(sk); + sk->sk_state = BT_CONNECT2; + parent = bt_sk(sk)->parent; if (parent) parent->sk_data_ready(parent); -- 2.56.1