Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp305600ybh; Wed, 15 Jul 2020 02:24:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDia1fWJIm+pNMPwkp9B6Ql36zEcrYJgjs77tTjfG3YsRbOR4tol7VS35HOMqvuKSGGVVw X-Received: by 2002:a17:906:aac9:: with SMTP id kt9mr8067229ejb.488.1594805095962; Wed, 15 Jul 2020 02:24:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594805095; cv=none; d=google.com; s=arc-20160816; b=fWRk/zQjmpUmbOYQHQFyl+NJW+gYS0CfYKkTLSGGHORef2cZotv825m/i/Laz4l00m 6vt4h9yH2OHFEl7C529nnl6fDvpnRILmLgGKx30PD9kYoVSTkaEE/ad/WFa3t67E0p/W KrZCoeooEX5fYD3hyC9zS57ELg8Dthl9/v1F1oCNSc3rC1WGR7b4FShW5bpuk80fesCX LufPfRy4ELDAQQXCbAZOoXeqowyGu8BA/r4mQx6h4yJByCECH0kUdMby0BcKv/KHMlR9 ekzGFoj7QG+tJQKkAwzjQ6hcptxaUiFBJKPwvnCj7bbNly001W610gXdqbdG4JNbuqBL +qOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature:dkim-signature; bh=grCkdD2jWEA7onIL8+JQxWBTuTayEwlI232LXSaOf/A=; b=zp5aX9Ss13eVNuaQVfpbkyvwrjn1ZqxRsnqA3rbe4dabCuIlr+xbK1AUkwdaq8oNtq UbVel7QNk9dDrrrRoQz/2Lu5NABLvKuBZaYAWJtbngi19uTmeIa5nz+yHjwAdWgzRqPY VqRVsscfiYR227vKiSZAp1Ym7Lpo1b7fKfKnYrRE1NjdTvNg48IJrRFumgYmUL9sl6q2 Bezu7jkOvaE8iaFDnSSxVUYH6HxgHQZQv7bm6EpeIrC/RPd36rnrKRZpoBFytYxRBHi+ ThaauBa6+fiWLtQiR0QQTumfbRUpF6tD3ZliVgK9sZGM9D9yeIrZEexPelL6tjyL5/lR LPuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pks.im header.s=fm1 header.b=mpAXdMG0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=LCQWndut; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bl25si786005ejb.731.2020.07.15.02.24.13; Wed, 15 Jul 2020 02:24:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@pks.im header.s=fm1 header.b=mpAXdMG0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=LCQWndut; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729958AbgGOI7G (ORCPT + 99 others); Wed, 15 Jul 2020 04:59:06 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:60363 "EHLO wout1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729952AbgGOI7F (ORCPT ); Wed, 15 Jul 2020 04:59:05 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 5F74A39C; Wed, 15 Jul 2020 04:59:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 15 Jul 2020 04:59:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:mime-version:content-type; s=fm1; bh=grCkdD2jWEA7onIL8+JQxWBTuTayEwlI232LXSaOf/A=; b=mpAXdMG0Axyw 7CSwPzMx88d7FkwpGytvD0Nt4qW176ehshE47ZlSjcAc14Sz9Fxr1oMuXTU/YQiY rZWJFyrr43saTgNYN641JBdeSWNUvY8aVAPia8hr+9sc6XN6mZde/wWk0DUQn1WO PLCbHnZr/K6JYZtMH65OHImiFrIm75iaU6tLBlHWK93WjrJK4maYObdp1DxmQtyl 6lsP3P7LE90eh82GX6myVgiZyHMd2CuSe7EiaVCtnm0FtVM15DYgpqX3A9S4DASG UVvGbTMiWOf4BAvogr+b/FSzQyVa9r+x55qipf7t9izza7dTm64UvORR3/AFeRIS ltofovgWiA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=grCkdD2jWEA7onIL8+JQxWBTuTayE wlI232LXSaOf/A=; b=LCQWndutDSHn1WlTEgvmfS7WvXTuzsVVioHxWFxGBwplK Nhu12F+I1Gh1d7yJdhAbbAqs3wnKMB90B7gmFfmu6Ly1h84lr0rxYsB0ug7Q0m9K ufvhue16B4ilVugY31y+VPp/62DCruRY60cMrEgCpMpVeVyV9fV9VQzjvgj0kdcV xdRXRnLfXdftu7L7+z9/jZsG4PquegYqiP6hWIUjpQZLE8/ls0FHq8jUVI8eyZHl 2Jc2OILFeajUWTSo9/YBy1WmjM0FUKBUR/b+EmnRhk1ePpJp8qFY42JFDYYyXhRT 3eit3M1nWTvUA5n4os/Gn94b5CTjXlzD3ia5DmB6A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrfedvgddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugesghdtreertddtvdenucfhrhhomheprfgrthhrihgtkhcu ufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepje eifedvueelfffgjeduffdvgefhiefgjefgvddvfeduvefffeevfffhgfekieffnecukfhp peejkedrheehrdegkedrfedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x4e37301f.dyn.telefonica.de [78.55.48.31]) by mail.messagingengine.com (Postfix) with ESMTPA id B4EFB30600B2; Wed, 15 Jul 2020 04:59:02 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 4c2231ee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 Jul 2020 08:58:58 +0000 (UTC) Date: Wed, 15 Jul 2020 10:59:47 +0200 From: Patrick Steinhardt To: linux-bluetooth@vger.kernel.org Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Subject: [PATCH] Bluetooth: Fix updating connecton state in `hci_encrypt_cfm` Message-ID: <0df5bf3eac160de28b9493a8959510980a8a8e8b.1594803508.git.ps@pks.im> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="eAbsdosE1cNLO4uF" Content-Disposition: inline Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --eAbsdosE1cNLO4uF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Starting with the upgrade to v5.8-rc3, I've noticed I wasn't able to connect to my Bluetooth headset properly anymore. While connecting to the device would eventually succeed, bluetoothd seemed to be confused about the current connection state where the state was flapping hence and forth. Bisecting this issue led to commit 3ca44c16b0dc ("Bluetooth: Consolidate encryption handling in hci_encrypt_cfm"), which refactored `hci_encrypt_cfm` to also handle updating the connection state. The commit in question changed the code to call `hci_connect_cfm` inside `hci_encrypt_cfm` and updating the connection state. But the conversion didn't keep old behaviour of when the connection state is updated, which now causes us to not properly update it anymore. Fix the issue by adding another parameter to the function that allows callers to specify whether the connection state should be updated, which allows us to restore previous behaviour. Fixes: 3ca44c16b0dc ("Bluetooth: Consolidate encryption handling in hci_enc= rypt_cfm") Signed-off-by: Patrick Steinhardt --- include/net/bluetooth/hci_core.h | 4 ++-- net/bluetooth/hci_event.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_c= ore.h index cdd4f1db8670..9abcc4a89abc 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1381,13 +1381,13 @@ static inline void hci_auth_cfm(struct hci_conn *co= nn, __u8 status) conn->security_cfm_cb(conn, status); } =20 -static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) +static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, __u= 8 update_state) { struct hci_cb *cb; __u8 encrypt; =20 if (conn->state =3D=3D BT_CONFIG) { - if (status) + if (update_state) conn->state =3D BT_CONNECTED; =20 hci_connect_cfm(conn, status); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index cfeaee347db3..483d35eda2f1 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2931,7 +2931,7 @@ static void hci_auth_complete_evt(struct hci_dev *hde= v, struct sk_buff *skb) &cp); } else { clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); - hci_encrypt_cfm(conn, ev->status); + hci_encrypt_cfm(conn, ev->status, 0); } } =20 @@ -3016,7 +3016,7 @@ static void read_enc_key_size_complete(struct hci_dev= *hdev, u8 status, conn->enc_key_size =3D rp->key_size; } =20 - hci_encrypt_cfm(conn, 0); + hci_encrypt_cfm(conn, 0, 1); =20 unlock: hci_dev_unlock(hdev); @@ -3134,7 +3134,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hd= ev, struct sk_buff *skb) } =20 notify: - hci_encrypt_cfm(conn, ev->status); + hci_encrypt_cfm(conn, ev->status, !ev->status); =20 unlock: hci_dev_unlock(hdev); --=20 2.27.0 --eAbsdosE1cNLO4uF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAl8OxYIACgkQVbJhu7ck PpRjOxAAhU43UIvw1uWfrB0Sl/6And9SXbT580tLQWc33qgJrgKEAr4ec5bIX5c5 UsNgmtmzkmw2Ka1xgvBPr/g4TMC6UQOwdvi+nCYWVtjyDZ0cogkvAZQGyUg3Re74 xfrO/Ef9PMrpGE3RlnctiOlut2blCK6SyGM37KYFI7Ec/20GTlDmQlkBY0BkZlyL d4VcwQQ5jtRXaT6YQOPghJP7ksohNA18QxP9DfUKYStZT9J5FW2XybsQF9Um5R7B xPv3BtYIpmWB44/n1dhZCHd6Tk20uWnsLgD2L0/xRx4J8KMLVr4OtqhqijoVGL2O TFGZNKvwb9YAN8HTxlqPDEBMv1nu5bPEAI9LUTIjcQZDPMxiNMTq1xesjoPuHeKu g6sB8p9fDgT/n3FlcZZpshweechp1U5tFcqN/3wlsqWTBvk1cVrMsK6IHyMJH/WE LB47DtyjLtMG8T41B545kTPccMRClPoQPohoBmFWS5JriAS+1pFAxs+EkUp8dDwT u0H6QKfokFF0gyeYDlbz+YsdP68nq78YtWhjRb7fCmF7Vu7Q8AhUdosNRNcVgemM b0vl/L7rh+Dgj2kNVXSsrb7VWfjcntyua4EMjemW8M+5bFT2MFWtyfA5wSg40X5F QCSkF/HFKGy+0cTZHjQH/AVFeYMfkXxPoO9z8Jv5ROD5gn+4Zls= =q2aI -----END PGP SIGNATURE----- --eAbsdosE1cNLO4uF--