From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796138941; b=oYNCy4/AnzjI4UQRTDtOAbyvU3xJJ9gDsS07FJCdt7bUzf5I8bkrgOsCmlPRAj6tiUIz yHyn441AxX8VwwZYjkhdC1I2y0pC9oNwMFCQEnOSslORLinh8TAdnVOrkoNAJBKUz+VfF l/Fpref2Z5BURqaYyxSOgp3l5qrXN01G9ds+4Yr01nbFyGRk/wrM8BGFbeht30dMYvwBk Sm/u2rid9rjBe1q9Ca8SLt2HxrB8P2bOnfocx7FOzGujgyQFmkJKdD8FnBX2VIzkc3BLH OPLWw6PMEuS2I1AqFZcAlgUNQPM/na1aaCOGNQ8Zgi0v+PlL3O6/lGgpcbjy869UA0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796138941; 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=c6vmD4hy2c/aFjPBjxNdCnuKp/t7UUOjfRzGct9Vavo=; b=yTHe6rAoH3oH0nwFccoFRr1Nc5IAHCYcm1Y1YiGyZvGR5vjrVOhXuf4Pl3awDRc1kmOT BWzSGCJ2M6J2pyBABFv2B4BRFgpw343vugTdmZc6j108k67D5DFgMqdgvgmGRjwAgn9vR 1UxIPgOIyO/1aVCkU7Ay2ujr+qxMj1ZdM/uuBKtg8pkP9sDZncYaOx+TiUuvmk9Bcw9kZ WVZZ1yCZcteCfSuOYuKIxl8PKuQTj0Zz5GteAJz3yUN6uInnzDtTcIBTG0e+26+hXFSPF BkPEdUjiaRS521sObPZgNlzRlMttkcP5fe5KTG2Xq4Rsa67UdmPsdUatyYwBjlG1NNg== 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=j61LjL0o; arc=none smtp.remote-ip=209.85.222.54 Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) (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 52996606A31A for ; Tue, 1 Dec 2026 15:29:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52996606A31A 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=j61LjL0o Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-9907a58f14dso3438826241.2 for ; Tue, 01 Dec 2026 07:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796138940; x=1796743740; 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=c6vmD4hy2c/aFjPBjxNdCnuKp/t7UUOjfRzGct9Vavo=; b=j61LjL0oPwXOtQf/RzEITFPe1n42c1dsaX7hn2HX2/fZghRQlqIN/NX2z3vIeo+rcV 9WuLuztcI8LnJPMACwbEOvX52Gl6BXW11DdYpKvWcpkv2Ejjy+GbF4ON1t7mGuSd9NV2 xFIf+hOD+sR3Ka7Kh462YzGBBlabQo5SiEeTav0q4jEGGsC3Cd+b4iKaRfMGjk1so4GO ry9lxZaD/iHSIwHme9yF5xEItmrCM1iPFw88KdWuu+BzfVbbXy3N+t8vRLZLw8v97gqW r0TSv6qnL3SmKrf9/zeC9SzfQrGL1T4acaRZTD5Urs63uyBhLBwGZviXf2Q0dXsMRLIn b4fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796138940; x=1796743740; 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=c6vmD4hy2c/aFjPBjxNdCnuKp/t7UUOjfRzGct9Vavo=; b=yXkcKbW/heHiu31Lef10EdOzFL47YIwY4cwwmkvlPcxGaC7nFSPGUWabXEqH1NIYuC vQihQw6Ct7eYk9R9JMnhbyb9p4a+DUTjmlkFB3lSb4vi5NdS76pO4pJq4dKLzo59Cx1N nxobsl0xajwkPm+J7Wp8QCcK6B2RSymSmvoXiDO2bia9r5Rc225cCnVo08tkJtm06PiC VzYihlVEg2AayGhc+3ECHaH5UNQu93saexJVtECGxVuEgPLFkerpY2Q72q9XijmkPBlX J/L8WduYQKn6H8Os856oYI4FtCdtuzNr+dk3N5PhVa1dr4341xHDkhNZCkvMjGEwOZeB D/RQ== X-Gm-Message-State: APuU4Z8Gok1GcKYCo6rsH9lUbF0gF4hxJvQ0I5a7FsTtevMnk2Vi/oy0 9Kb2NZ8AoRQFbJ5UhsyhH9pPB+qx0Z4tOOPK4nux2ZXoSz95JDkau+7MatmH5lezovc= X-Gm-Gg: AZFdTZfje7bt88+nEJo7SM3fnX9PeJYlKXRAPRW7r3/7ZIjDLMsMSzRNfrHTNgsh5xZ 5dEoAP4ux2nqaN00qZSi8KeaIDqzLc37DOfPPG4JXDIv58WLm6dPPy3YPpQSCysQdMejaMKoe9O 9ZJ9R/VUzXGyitfezf6dxkN90ApsfrjMotsVqT9p4Kf7O1xZfpgdTKUaxPBW5OWrZNIFCNpLrFG 2IeqBO17tgDTU52O+laN4uKJ4UMOp9+FbKZcwjgoD1sHsUKHyyM+1nnirPQmR1CBlqTZkOe1GYr MMUkpl8TZ0NGkXLCHShObDk6SEWudXwu45yHqfvYd6YPGh4vMRaphrED7STui8uSKtBuoOBsiS4 wTwU1EtCP/7+5OwXcxnsGMzWeg44nuASBPFckmp44sXgnMbj7UhMCz2JGV4iZ3J17raSI1/dmsV jx+VvBMz95SPNZJoQk5TP0+n0ltEXU4bC8lzAdoKoHdGg13lPcwv0qqz96JtvCQxmAfPEVCzJLF L5NPoTCpEeLW4zuyq0Hxw5UgytGbxUbfa5fbCzVWbcH0eS4eXCi8WUUGUy/7K+gH68LJLj3m8t0 tkkDJtvtxESsGJggFNFbANyYAQ5MpYC9+bki1Ljz8ySpuCZqQES7m0Gub71Dz52P1PKm0AhjAc5 KXiwP2wRsEJwWWUrZ1tQc320gbgT7v/vx8dztNsdZbVwtQY0UFUpnIOdLTmctxv99Kf5PcR78ew ECcho= X-Received: by 2002:a05:6122:9003:b0:5ee:b4a:681f with SMTP id 71dfb90a1353d-5ee8af6c710mr22995884e0c.20.1796138940209; Tue, 01 Dec 2026 07:29:00 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6df8a29csm37603297241.5.2026.12.01.07.28.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:28:59 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v11 6/6] Bluetooth: L2CAP: Don't offer deferred channels before security is met Date: Tue, 1 Dec 2026 10:28:53 -0500 Message-ID: <20261201152853.1118148-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261201152853.1118148-1-luiz.dentz@gmail.com> References: <20261201152853.1118148-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 3bdeb4258950..5780f9b53c8b 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1857,7 +1857,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; @@ -1925,6 +1931,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