From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068623; b=RFduByDuJkFzq7jrAyTb+s/YurjdSdG5aAavqymbCK7DzyeQR61ifOhP06w7vikFI6nC uE/l1JjiowWnMLZqwztfUpOMzyOSzioZg82zdTbVjGzS5WQYu+DIbZgYqUcSy/QIhT50c Ti5IaGmEUjX26v4PS0p8leKWXujweh9QNIqUkCoRSv8Vdt/MRZWN458PjUq8nZXzPJkAc Nlj+AzLav3iq2JiSHUEXFPAXeVRmY2URxwsH5kfplzguVNuqJdGZt+7ivs0BHUbtzJUoF ZVsh/cN2faFoVQxdG5CfphypGUsmkGphNPPOBbYQktqsqmRwoaa/mznPbPKtnu58H0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068623; 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=Dcr1CjoUxzee9ubNaXmjJsJHXLBDavw0Ha3VJivcgfg=; b=PW8eilbVVjggIi1dT0xkfEhXLkSmq5cVvP5SEZXj4jVOuczhyxddmEFc1Tcxczad/v5X hl1eg8WNkbHjmH1BwHZtg2v8Ye0hyPu9RkD1Fm4RnpHIrrrl+TdfYFIsj02Lq9YAZ6cMr cMhRs1c8HgKpypD7izkg3and8t/Hw3iv2uj8lFNxc2D5s4CWrBWwsv4oE1aHL0NRbgW8h ZpubnJYQ2MQBo9f0uEPSlBy2bw/huHWePJGP6b8E/NaT1w+Rz+s71fqUNidt+cPWRvCVW nuAOAuuyPUN3nN+06B6AvqLnIrMex1tErWClaJnt7+IzzJ04RrZLQbQSybvtrCEV9HQ== 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=byBRuVzM; arc=none smtp.remote-ip=209.85.222.48 Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 4E57B606A32A for ; Mon, 30 Nov 2026 19:57:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4E57B606A32A 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=byBRuVzM Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-9906034086cso3031385241.1 for ; Mon, 30 Nov 2026 11:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796068622; x=1796673422; 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=Dcr1CjoUxzee9ubNaXmjJsJHXLBDavw0Ha3VJivcgfg=; b=byBRuVzMzTuiGEmPwYp4ueFQRhOYldItra5y1QoP5Zl6+wark545DqwBFOM/1tlmy4 J155mZQEbyX+X6iSTftCMFthZLeXlHm32DGvcye2+FyknyZ3JJ1YZKapcyldAJg1OHls e1JJiFsvY+B6lwJF5D+McRfYg+LtupnjCcJjLvhoRKURi9QKJiIQA81OaAKNcpIA+Gli HZBdl5k+1dXtP0Jy9bKMBth5b4nwlMFhIR1rr1JWR30uWt0/65xzWkHIavtqqHcxJaJU 7wbVcNbD/VrIxgubnoSveyLJ6OjHtCYQNeyUAGKKlfIGW1BlhfTPzb+FJVXm95dOQmaQ e4qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796068622; x=1796673422; 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=Dcr1CjoUxzee9ubNaXmjJsJHXLBDavw0Ha3VJivcgfg=; b=0yGq/FISR3qUdEey9rOxpdPk2I3Or/qHDFpqPQrMzMTMqdSUQs6r//YEJkXjZXkuZx 7DrgGIGSv2CRCiSmFxGjQqk1+jMCZ+pHSx/DmVCgY2tgJhwXZ0NSwdWtpFuCD/sn+YeS KVKaTSR4m1GQ8gvRyrG+vJBcm7UhdrWGutnVbguzOM3w7AvITFQVHKN01ge3yfjTP+QU csF+ewdtV64blOBFq3ia2Z9ID+O9L0PApO3mc3ydLYBDI3n4bC3g+Jxsk9eHNM6kOazX LGSp4XE2GI2x3n0PnLMNw1WTL6wvnYx7xXZK+3upXnQWZtaswhUjIqQ+p1gwrpidi6ZB JMdA== X-Gm-Message-State: APuU4Z8WwHBraXNiHh01PmCo3wvDUABXZmNPixR0Pq8ZJ1PWIDWHryr3 y+vL5YizvaKGZTBeyP4Kmy/K1FhqTzJjQG4HrP8o69pHOt/ea/13kNPmTrwtr70V X-Gm-Gg: AZFdTZeki/NycXorVT5aYnw1xAomcx759rCBI99wBTzHdDe90mLzhuLIMHQe5SjhIt1 x1Khtnh0jLcd4U22FYD25vnsbPsHYB7qClscDEwWXkfDluJE9liB/6YWIj8cuezfUZ3lUCS9kcW ndNtxkbWtFkPa/mCwadZyZO3hgyf6FKFK4onE2hnkhTAn2cdPX5rDxntd2l5CrebdqIRVdQB9XE PxdJpJevMzT5L0mvi50dWV493X/IOCt8h3k0muUFadr3tImMc+QjZq1n63717XK+qoUHP0y712c uEjQz8SY+eydgtjSU5O6r4iD0L9P0D3uBF0Pf+kWAw6Ewj1dg7HEPKTj1vGyiV7YZtVNA3UP5k7 RD6ASURkEEe0Dw6btQ3go/xnIcrzKE9mzqmvUWHvzRIF13qdrEjqwYvJmWVR8mCgcWTZuEeULnq w1LpJvyfqsjCcE2YO1XZPycSpB5VqPcX96qu9bGA37czWrajYCImtEp+Ng0GoPP48xNKRzNACg2 +iZX7u8qigzs6ubCQbNpZCtxPnMnkVlpU/kXXDMm1btECi5iPogFtjx4S2e4r9w7izfc78KQXi5 G2Z41xuSjsQTnTBc7kPZzm6qiTOD9/0p4e9EOR28vRRt1RZs1hJCv90oFu8CC9GAtPqSRRGetfE 11x0bJEaoC9u/thWeKIXDx33eMGlPQU67JzsQMF/6h2quxuGQQQMooagjehZt5CbB0syiP5XQRk HcWiM= X-Received: by 2002:a05:6102:6e88:b0:7cc:b246:31e2 with SMTP id ada2fe7eead31-7d73977da7dmr15284383137.22.1796068622013; Mon, 30 Nov 2026 11:57:02 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6dec7cb5sm36694016241.2.2026.11.30.11.57.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:57:01 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 5/5] Bluetooth: L2CAP: Don't offer deferred channels before security is met Date: Mon, 30 Nov 2026 14:56:54 -0500 Message-ID: <20261130195654.560637-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130195654.560637-1-luiz.dentz@gmail.com> References: <20261130195654.560637-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 456db92f35eb..de26a0bedfe0 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1850,7 +1850,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; @@ -1918,6 +1924,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