From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068620; b=2gw3bby2bZ9OMyNSlyaKG/mEQKqWnf04qBZs5D0hULUERPGkWMXB7C+1s8lT1REhGT9u CJOcEEcyzey0Y2PvYle4Cw5/IEheSEZyaUMGsmJclknEicfA9oafwwW47vRnJKyMHw+0H EDcgCQv50O6yjwmcpoG8oPlzIhp1ZjqYdRHN2UwJFqHj3ToJx7kIbgry3ZoFl914H6BZq 7bg1dc3QVwN+r2/bJj1m49IvDT4PVG1K5W9ggJfs5PqCcw7YfQB+Vev+42um/YIgeSucF fVvdNM0WtqwNi1BmIjzFurGOnh/dLzx2I6GuwQyMVhw8M+6pa5iVfBPbjWy5ceImI8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068620; 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=f9C4GCl8yoRED9YZDc/OKk5SK6n6g/ivIiDh4y/6unk=; b=B/5tvmZf7M1N0UheYl1hiVjC+rJXcHqJnT2X/F/62ZITrv2c67ZZnMc2v3MRO4jYLXHz iqiDYDAH8enB1xng3Ve3oKVDyTxythfbHGo3yZ/fHgBHAvPRtctg5xQc7z8V1PmlUGLA9 7yRZuxAAvZvq1Dl7LEZiU4maZhTNll/2szpemuQVXAcp9Zc1cFgtJiK9gntjbUHXHGBOX 6lwuRPvwlXOSYVuvUi8o3k/cRhDc7UoKyeshpm1hZSP6AImPjSzDRGIEE6wlnoN585pNy Ug57DU8EMelErG/HtW68G7nEcY4qKqnuPcW3pThbM8SuGn7dCL0S2thYNmyefGLICfg== 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=WbRcjNpU; arc=none smtp.remote-ip=209.85.217.43 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 9628A606A320 for ; Mon, 30 Nov 2026 19:57:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9628A606A320 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=WbRcjNpU Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-7d2d18f1bf5so5896854137.0 for ; Mon, 30 Nov 2026 11:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796068619; x=1796673419; 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=f9C4GCl8yoRED9YZDc/OKk5SK6n6g/ivIiDh4y/6unk=; b=WbRcjNpUhfNLwutatIdHkjlltri3YYHNz6aKKFeo3kMstaKzEFIFEwtmLKTy5NrlCY nOg/RRit/Th1Uo7a+nTqJlZzh1QQFlQwz2Z5dJ/LQFyVuYP2X2lqQ/Ze7zPeKZs2Y23S HcNKX8v+JH/iodBoML+T+sKhDwFsLUztYuXTkoJSiO7DkuJY5DZR/bIzY358TANRT+6F fieTiu3R+/26CchmPuIcVwrKtD0ijmLDqqTWyWTCQUCPLkEtmk3+EZ+HfDx/QBlcCnwB kGdqFnnd3QJUWO53QR3b+mDq0YQTbTZR6ZiHFiQ3D8eHY+EvQJ4HoWDh4bM5Nvc6EZlr lO3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796068619; x=1796673419; 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=f9C4GCl8yoRED9YZDc/OKk5SK6n6g/ivIiDh4y/6unk=; b=hmRA7qt20VRaIl7aS+d6mBI0Dm5IAvqI2Yi0FxdAOFN6A+bFrgZ7IEqteK9mTXazuY w22nyOh9o7TKroOlhJVNB2iioGBYmJ1d4jta6Qx0AR7eEUqPWMqPO0646YHZZb0OvI7e dt6UDZfV/FJC/kmrxwj5TXsPVoULtgBOGp2/RJ2Ba5xWx4lz+AIjrPxAzSdpxLWtXoLg 5cN5IlDvj+fpn6fmntjApVQfM/ncCAO8/MFVmoYx1up5HTrsHX0cHKlFEr7YvIMA0vwX C82RXTjxMY5oZEPbYez/iVbOMH53zen4tkzvAPO74xCjvpPibdpHfQBpPhu+TvpwC+BA yVgg== X-Gm-Message-State: APuU4Z/dBcGQ0ZRJkw+nc5CqLKRL75ScqAbldzPkHMy7a6D/kWrbU5jN ct2Ofl0WeXJW0eDO8LN9j6oYAvFy/z4IxjQPk3dqGYWyqfpT/8k+Q3gjxJOVHDWZ X-Gm-Gg: AZFdTZe2+rt6LnmU1UKDI73tzbXp3i2icO930naVTW1r1pUKF7TpHIPhWA713uSPryj +1V15x/SQ147EFygIWVBQaokinVvqQ5/mXALdUnVHdwHl0ZX1a5yQbma42QYa+pK21xM6PbhE1P 6snKRdOLd1il32zVYKavjSR8BYqvK7HsfDyNGMh1XililODz5aO8seydWHUxNx8JijZsHpoiLEd XQE0prIZpoELRk/FZZbbFUFyRR9yEgF5eidC5eEy0xhVEAak9KgGEH7Qp8VEVkabmFl6kIvyM9a x02Clws8JSJ4bU3Cq4WSpVEh+2n79rZoLviU3Hh5OwotRA18UviifOGF0iQjii7zsR/rBFy4ZS/ /pZIaep9z8ppo1DzswUkWzbKV92gTJKV84bZ7mFzEwZMuU+vUJHCPN1zizhWeLXo/nLnUONGL2p eSQFCGUf2I0zRkF0pm7eR9wn9WE44EhMuXv4WTOhFY34eN6eH9ZAStHvyJIv2xY5EQ+qoFDTXR7 gQBDTUNUwXzbqdhbLrtzamBK77OsbSNeHnKoqdekdp7mhAd79L7vkxSIK/QhtxHaqkqF8LESBr5 zNn1ovRpyt4/6qxi2uVaz63GS9vHzzBSp2t/sIo34kKYijIkrd5ZZlcJydgYaotTnvrwUmsELH8 /YaOyUETpppmZXtf6/+BAaR8IqUCWfu3edIKf9QrS6817ek+BfxQJ5Vi4FjdjqcDhbslBYHDp+A k7PUA4 X-Received: by 2002:a05:6102:5091:b0:7d2:cbb5:71f9 with SMTP id ada2fe7eead31-7d7393ff1eemr21056433137.7.1796068619446; Mon, 30 Nov 2026 11:56:59 -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.56.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:56:59 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 2/5] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Date: Mon, 30 Nov 2026 14:56:51 -0500 Message-ID: <20261130195654.560637-3-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 l2cap_ecred_rsp_defer() responds to a request that has some of its channels refused with a rejection for all of them, deleting the channels that userspace has already accepted as well, e.g. when the listener limits the number of channels, like bluetoothd does for EATT. A L2CAP_CREDIT_BASED_CONNECTION_RSP can accept only some of the channels of the request: the destination CID of the ones refused is set to 0x0000 and the result tells that only some of the connections were refused. Fix this by responding with L2CAP_CR_LE_NO_MEM if only some of the channels were refused, with the destination CID of the ones accepted and none for the refused ones, and by deleting only the refused ones. If all of them are refused the response is unchanged. Fixes: 9aa9d9473f15 ("Bluetooth: L2CAP: Fix responding with wrong PDU type") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 72 +++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 943effc86740..363ac139deeb 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4065,6 +4065,39 @@ static void l2cap_ecred_list_defer(struct l2cap_chan *chan, void *data) } } +struct l2cap_ecred_defer_count { + int pending; + int accepted; + int refused; +}; + +static void l2cap_ecred_list_count(struct l2cap_chan *chan, void *data) +{ + struct l2cap_ecred_defer_count *count = data; + + /* The idents are not unique among the channels of the connection, so + * only count the ones l2cap_ecred_rsp_defer() responds to. + */ + if (chan->mode != L2CAP_MODE_EXT_FLOWCTL || + test_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags) || + !test_bit(FLAG_DEFER_SETUP, &chan->flags)) + return; + + switch (chan->state) { + case BT_CONNECT2: + /* Still pending accept */ + count->pending++; + return; + case BT_CONNECTED: + count->accepted++; + return; + default: + /* If not connected or pending accept it has been refused */ + count->refused++; + return; + } +} + struct l2cap_ecred_rsp_data { struct l2cap_chan *locked_chan; struct { @@ -4072,6 +4105,7 @@ struct l2cap_ecred_rsp_data { __le16 scid[L2CAP_ECRED_MAX_CID]; } __packed pdu; int count; + bool partial; }; /* Lock @chan if it is not @locked_chan, and has same or lower nesting level. @@ -4141,14 +4175,23 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data) chan->ident = 0; /* Unreachable, check in l2cap_ecred_conn_req. If reached, drop rest */ - if (WARN_ON_ONCE(rsp->count >= ARRAY_SIZE(rsp->pdu.scid))) + if (WARN_ON_ONCE(rsp->count >= ARRAY_SIZE(rsp->pdu.scid))) { rsp->pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_NO_MEM); + l2cap_chan_del(chan, ECONNRESET); + goto done; + } - /* Include all channels pending with the same ident */ - if (!rsp->pdu.rsp.result) + /* Include all channels pending with the same ident, the ones refused + * have no destination CID if only some of them were. + */ + if (chan->state == BT_CONNECTED) { rsp_flex->dcid[rsp->count++] = cpu_to_le16(chan->scid); - else + } else { + if (rsp->partial) + rsp_flex->dcid[rsp->count++] = 0; + l2cap_chan_del(chan, ECONNRESET); + } done: if (locked) @@ -4161,8 +4204,8 @@ void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan) { struct l2cap_conn *conn = chan->conn; struct l2cap_ecred_rsp_data data; + struct l2cap_ecred_defer_count count = {}; u16 id = chan->ident; - int result = 0; if (!id) return; @@ -4181,13 +4224,24 @@ void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan) data.pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_SUCCESS); /* Verify that all channels are ready */ - __l2cap_chan_list_id(conn, id, l2cap_ecred_list_defer, &result); + __l2cap_chan_list_id(conn, id, l2cap_ecred_list_count, &count); - if (result > 0) + if (count.pending) return; - if (result < 0) - data.pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_AUTHORIZATION); + /* Only some of the channels may have been refused, e.g. if the + * listener limits the number of channels, in which case the others + * are accepted. + */ + if (count.refused) { + if (count.accepted) { + data.pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_NO_MEM); + data.partial = true; + } else { + data.pdu.rsp.result = + cpu_to_le16(L2CAP_CR_LE_AUTHORIZATION); + } + } /* Build response */ __l2cap_chan_list_id(conn, id, l2cap_ecred_rsp_defer, &data); -- 2.56.0