Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3651923pxb; Mon, 24 Jan 2022 14:29:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOW41fbfst94W0t1zcePnMNqsTg6j+FejUpwLidqEdj1/uA+/mH68DI9aEX2kOEHG697Vr X-Received: by 2002:a17:902:c9c2:b0:14a:f0e3:679a with SMTP id q2-20020a170902c9c200b0014af0e3679amr16087065pld.36.1643063345816; Mon, 24 Jan 2022 14:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063345; cv=none; d=google.com; s=arc-20160816; b=K5OEJMFkPmR5JUTXQklHMjr7B05nqMS1b9VbflhYt0+X9OxvsE1joVcvuuTr5Deug7 V1Fh67GGzzXraFedjEcNFHbIwp9usCBdcc0gEvRD6O5URxaAEclb6F9pBt9tfMqDscRG 5/3eRXC9nJYqbQU2A38pGRey994FbskIyJhfgKUd17fnM0yp69wLzKz7ZCmO6o/BxCOS +X/4Cw2IwY5rF+YYXlnvR/3csoK0YuTfZsfoXFUQN+6jc/lgz1HzIfc3TeN+/jQpNR3w SzA6JY8nPypy7uDLUYsQ8ibZEV3300vKh5jWawDEHbxC/pY2YrAXAf4mXVqJGD74wMpv hGag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gk5vnO15psenadtFu+8BoNMuNlDC3SE4Mkl7+ZVPl50=; b=oESr+B/qfhqLhBenhBtmvF81rHP2Ar4Kr8rIdfOg/3bOAF98SYhmDj+0xBZ1D6WFNj guvjzFBgzUZIrmOaFRwG6UftSrL1vBbtKdz8FdsAcjWmBYXU2alyAchKACVqSQTlrAJE UWRRcRgKeYvwOCjLOcIG+VORxQQG/Kcm1Rmh9P/IP5k74Q6p9A0tQue6ViUdqfkyNjzp Ki9Nf2zirj1Rmxh4fI/pJPyMni9/LD3vGlt+C2MaXCsWhKECTV28eTJBTHSYV4kLPAy+ 00HXK8SoDzUORGX6M9e1Djug6UQErHRX8wzQvtkbp6sZeBUyMDMGthlOqY32ny2fkCGH 0vLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2D2AFof3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mu12si846746pjb.0.2022.01.24.14.28.53; Mon, 24 Jan 2022 14:29:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2D2AFof3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348264AbiAXWSY (ORCPT + 99 others); Mon, 24 Jan 2022 17:18:24 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:33686 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1447918AbiAXVLo (ORCPT ); Mon, 24 Jan 2022 16:11:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9B936B81233; Mon, 24 Jan 2022 21:11:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C161BC340E5; Mon, 24 Jan 2022 21:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058702; bh=nbudAHV5Id/HIQCDuN+n30CdC18eMXg3cLWyw/aOG2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2D2AFof3BofQ3g9/IWo4SVqQ8pKfVXZC0HRt+DwaQVXI8Q+4mSlheueNfi/ITubsJ jKh0e7Q0HFs+omrvWGOJXtADkvnGhd9MB6AeehUxoNEzxyoGgmOImitcuCBM6NoOta lv29Q1tA3f4+Cz6VKlOwjxxj61aDRkKc0CbMTLQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.16 0342/1039] Bluetooth: L2CAP: Fix using wrong mode Date: Mon, 24 Jan 2022 19:35:31 +0100 Message-Id: <20220124184136.798730800@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luiz Augusto von Dentz [ Upstream commit 30d57722732d9736554f85f75f9d7ad5402d192e ] If user has a set to use SOCK_STREAM the socket would default to L2CAP_MODE_ERTM which later needs to be adjusted if the destination address is LE which doesn't support such mode. Fixes: 15f02b9105625 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_sock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 4574c5cb1b596..251017c69ab7f 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -161,7 +161,11 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) break; } - if (chan->psm && bdaddr_type_is_le(chan->src_type)) + /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and + * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set. + */ + if (chan->psm && bdaddr_type_is_le(chan->src_type) && + chan->mode != L2CAP_MODE_EXT_FLOWCTL) chan->mode = L2CAP_MODE_LE_FLOWCTL; chan->state = BT_BOUND; @@ -255,7 +259,11 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, return -EINVAL; } - if (chan->psm && bdaddr_type_is_le(chan->src_type) && !chan->mode) + /* Use L2CAP_MODE_LE_FLOWCTL (CoC) in case of LE address and + * L2CAP_MODE_EXT_FLOWCTL (ECRED) has not been set. + */ + if (chan->psm && bdaddr_type_is_le(chan->src_type) && + chan->mode != L2CAP_MODE_EXT_FLOWCTL) chan->mode = L2CAP_MODE_LE_FLOWCTL; l2cap_sock_init_pid(sk); -- 2.34.1