From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073156; b=tkbxz3KZfuRnNJRiU9Psxt6wQ7qnWkhnLw7Y65OGtsV5B7Gs0Rilhnt3xiEM58e2cfRE lQ1kVmI/frmBxBTxzDenEcI2gprUr4eF/uhio2ius/jD/EE5lPMUl3Lxk66o5AgS9omsp nzcpzLXKbet+yJy8uhptoX7++FYLEgxAt0yApb2e0ySkNCnJAMu7EERee9AgBfloDPV7l qk+M7CqVH5WPw3HouqZsL2lnwHQhF3bqrn9p1jhUWAPTl68RU8v+lPpI6zgNMrxAAbRhF +khEXqVh47Mi5BBJoXjGoCIaWZYG4swKYCjpTNaSmh3wOqbgu9dBP/1IHHEki6h8hgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073156; 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=k1SVFzqjYc1NPobPOrgU2z0mjgosmDyyrWROoGAS2g0=; b=Xb5aDnb9qIWTl6+5GX1JllFcwd8GAQ4iK/y9c2EnIqT6gbbmxbaYM7XX+U9vLgklVWpx SGaFGJW98QUAhq9fnMwluGNjuGWA3CqUa0msiYxYCEljBoSiMesADZeZ5EbKsZqodUgDj YWSzy3yVnT+FXO5rrsARNI8H++5WSk3Qfaximn87tqNhRGxxpW3Fs/+eW7W06DPBgvtk9 BF3u8kGsiKCpuGQs1+YsJCHP8MhAd9OSrSFMeo4inJLwX5R6uQXpbkTn5LPGAbpNNz+EY h0+Zs6F5Izv/JMhXw11us743++LMfuOPkymv0GF3UBQzKVo3bHsSWUXCn0pTdnI1ZBQ== 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=nVB2zbTy; arc=none smtp.remote-ip=209.85.222.52 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) (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 CFA49606A31A for ; Mon, 30 Nov 2026 21:12:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CFA49606A31A 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=nVB2zbTy Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-99e81f5ec91so5305056241.2 for ; Mon, 30 Nov 2026 13:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796073155; x=1796677955; 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=k1SVFzqjYc1NPobPOrgU2z0mjgosmDyyrWROoGAS2g0=; b=nVB2zbTy+1si0fAyx6BYI4HBCelGwsNsaaXvGyehK3FnulJUQV1Ek0pi3E8XSwtEaJ QyWZWkXKBP6fSNGUUL8Mvt9N+0V/bmOqfspIfC4VJ1h7S1rhNBQN+VsUGYt/9CIjXH+E +iXl3GAqn33hAVPFENlbSxqwHeNL0b9ROrxqTIS7YA1lSuJ/GHeuGZaw7t8qWN1R+ggu nCzmCys4uQ9cQG/H/CeFw6RzGAPeKdx3+RXYkkFrzoHsZDjU60tgxUBpX+GQD6sCZoFL yG+ulPPn53WW3XYxweOhhGQWA/3lGl36zZLkeQcSWzV+VRL4pW23d9mJU5667UYCzxGa BXcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073155; x=1796677955; 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=k1SVFzqjYc1NPobPOrgU2z0mjgosmDyyrWROoGAS2g0=; b=MteM6JaUU29uiyWXIVgmVrvaJrisYZ83bmvrIv2hZM5fJUv+9awQdLzxMmKezhyMeh +QC+hG02T1z9CurzIfugFmhlrUPBYHJ+OthaoFoZ3eLr0CXDuDVfxuAfC1I4VQN/2PTn 1x1ytuYfZGUQ2UslEmp+16x1Ap8f6GXTxzuKISFgvtGT5GAUH6fBQ0Np/GT/6E9f8uZb b0/EwG+ldVU6jQDjgYCRQo5kV9ngJ/83v+mxIeLVBYqkQ57mjbO98ISvDt7sk24EwGhB by/7KqZ8+zLbLXFnR5fIW7I4Xi9ohdKeBM9LtCz/kdsmfNrzJ7INivTKM0/tLdOafIDW SKSA== X-Gm-Message-State: APuU4Z+Wc4uNMbwn3zMXdb2slCiLh9h3Gmp0+WHqTN/OPj/e1uETc2bI 4PHrBU5AhgSs4JY9dHJ7/FmAXCXmZ33s311iRMjr51tTQzPO5KL0k7xkn0apurRLSTo= X-Gm-Gg: AZFdTZe07d/JtOvr6fuYbPJnA5dPya/6jE8bCeUrzXmfHHalnmH9yxaSp26tY8zLmAh bMkjZJovvW+rvmIfVSQ4q12KuIpulyQkaLktx38aTu/JDzvD90xaNO6mm7vL9aueGBqBlatzqzQ IWfKQq0U03dPcjXbA6fJ3Byvw9yObbpdxfu0tHvKi1tI5mtouEyTHFkiWN7hoE2LtSR7utS4dtY NibqABq9bKgAFD09JoKCyDV3xfzKt2efcPj5cioVvyrkttFvyor/pqi6H964IeAseSd3VhOzmyb 4+d3Lt6ZvEV0IaFU496rYYKqytF94hL56Q43H4z3On7i3BacdtlwmNw4hP+MX79krycomtZTKgD jeLZl9E8oKZVE/UXa9jM5kY69cdCYrHNPLCfdOVuJBVKY1n4LNvK2cyB2FIwfepDOUlTLIyGzm/ Rz5qzED/0Z5hNobyheHqDyAd1V06cj3dgNK5uJywVl1baSYJdd5saGFL5k81h3KwTVP2QegJJoa WYJXDld+1DLo36WQ0E4XNY7lWR5ds9Rz5iGe0UpKKbhC9De3H2kpAcNjecMZoxGRhjEpgdgofVG JAVnrP4Oll2aujQlvm1eGdCi8Cz66/G943V1hFTmzBpV8eO2BNYwYSQZ4raiX0wHdHjtzirorDH VtVAyjwLkPKU1HemoEJNZ4NFjjUDUACOJv5CVijT8istDZPso9LLkw4cbIrIrvMBmpDjh/EPRRu hjY5Lh X-Received: by 2002:a05:6122:4d0e:b0:5c9:ae70:e784 with SMTP id 71dfb90a1353d-5ee8adf32e1mr20677856e0c.3.1796073154646; Mon, 30 Nov 2026 13:12:34 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee8b609bc7sm35472261e0c.12.2026.11.30.13.12.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:12:34 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v9 5/5] Bluetooth: L2CAP: Don't offer deferred channels before security is met Date: Mon, 30 Nov 2026 16:12:28 -0500 Message-ID: <20261130211228.621145-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130211228.621145-1-luiz.dentz@gmail.com> References: <20261130211228.621145-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 aab8345654d6..8587363ae57d 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1848,7 +1848,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; @@ -1916,6 +1922,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.0