Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp488430rdb; Tue, 5 Dec 2023 10:41:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBpHlWUjui8yglUZCGRL6aafYsqPWE7G3kZvYZeJUhr8Qwql7DPP2MUu/8Zr5f9KVYhHGd X-Received: by 2002:a17:90a:2f86:b0:286:9734:ba98 with SMTP id t6-20020a17090a2f8600b002869734ba98mr1332788pjd.53.1701801695432; Tue, 05 Dec 2023 10:41:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701801695; cv=none; d=google.com; s=arc-20160816; b=fGeqb46dhhsG8MRFCnd8IdeF1oOGlelf2fOIrgpkn1sAtVIPM08D84k3ASPktl5WBH YBP8T40ZtNoviIRazosbY5rfBJ+CAG3uH5qQ4r738efEvQelAXtc4Mp7XaA3cH9+YKt1 tpRqWrvODsxAzaGHVt5R8Kmner4aG9cKsoLFCijeoF+NRkt5yI5IB/RtrpMViC4BwdXm GfHDneMXTd+apP0HkG6ukO6S6cNhHknAKCuAgZ0pCZun5aVze6OmdmHlHEEXXkm86DIK +JZnNtm5WY8hDsXgevTXmnoV3iPrbIjgqEtF9no45wmgsyFY+ddNzPCsok0IO4yyrJG4 Zh7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=I39hTg0EiGJixeGmFzo1fbQWYgX0mLDDpiIbEwbzBnQ=; fh=LF6CDYFVxiGFE9WXuqX0ply/BlT4ktxuRg2GRZU8lZ8=; b=E9dXIG0E5gac7Gl7aq4/2l5j4hMMnOY/Bsp37EPwVv+8KJRacudYmkGzUHS0e87Nkw 600LELJcaHtIcncf0udb8pKIkS+gxj1d+uFTyitq/Uyf+ZYjDXcE1RlDFF/xe1+ItPOg BD87Kbwoy9dfFlz0tGBRT1BQiCVfeFxUNAO9slcpfQwsYnVQASirllhSWkLscgc2YADn JNkRmhD/2+56FLXwnP0ujPrWfUl9ShMoP5M/yrDpmQKhPm2uQ9sVXrhyza3FjLySoq1e Y6VzaVamIKaQIuxj1fmnPIqKLJPNIHdfgcGnJV2DmiyO2oMD6ie5dDKuX2FduvFKhK8s KFSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gn+UOA1g; spf=pass (google.com: domain of linux-bluetooth+bounces-408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b11-20020a17090a12cb00b00286660609c2si203063pjg.1.2023.12.05.10.41.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 10:41:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gn+UOA1g; spf=pass (google.com: domain of linux-bluetooth+bounces-408-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-408-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8152EB21299 for ; Tue, 5 Dec 2023 18:41:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBB4CD274; Tue, 5 Dec 2023 18:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gn+UOA1g" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F8C8BA for ; Tue, 5 Dec 2023 10:40:58 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c9f9db9567so35267001fa.3 for ; Tue, 05 Dec 2023 10:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701801657; x=1702406457; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=I39hTg0EiGJixeGmFzo1fbQWYgX0mLDDpiIbEwbzBnQ=; b=gn+UOA1gh2cIr1WGsKNWZZgPN3T3f/Xv25Oh7ud7gCIq6ys71PkxUxCgVTMCJEIjC/ 6Lf2A9woPXk8E92Ac1vbt341EiGwF0KngxGAcKslA1lhu4gxow0FrTCWLU2IJ7pa9ho+ xNEGvPhNIdL0mIvXdxUNRxUj12cxwf07eHlpKSE1gtlQCmN6mqTE38ftY9ajMvJ5weD+ kw3xha+Q6Wj5L+eL75lcv7F8A0XggETmkCGPu+NDCJAj7eu5sAecdVf7Hs0qwTO9JFdv MTFjls/Dov+m5hjx2umRwHMYtwlkrKkxmy6sRQRDrkAzzab9Lzc6geIXrzCfujMk551u iXiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701801657; x=1702406457; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I39hTg0EiGJixeGmFzo1fbQWYgX0mLDDpiIbEwbzBnQ=; b=rnXEuf/RMHnByIjFZVTH2LPMh0a3+5+aaMvSi0xJMF/7TdtQOAf7mRPoYmjJ2IJacv QRpDwblbj1s3kLHH98IN4KPDadHCfOwUgCsChIcZl1ubpwcDx8fh2pDwIV7pF/UgROc/ 0aLYSMwwmE4u32/fEGq4bcr5RxERGhcQEdBtI3n1cgNUW9ODYiRzAKVWyrVwj5WtXU6l 4i/0rSo982RO01bExrnUCabHCPH0cQNqy3Mdbu5/TTufHpbgj/8jK6NdG8aCxlS1pvrA r7rk0SZGv7n+rWt+fFwacBaVhyyJEsES9XQ9fHLlbV18ckakSzW7w+qdjMaJxGmD4/tq nqDQ== X-Gm-Message-State: AOJu0YyicBjhTmq1+8cCLvoE55a1GpRssufxAPyZzf5cQonip5ZK/1Y/ Yc0WKe/Jd9oLKAH198OWl2/2PXNTagK+UO4w5RJkiZgB X-Received: by 2002:a2e:9d42:0:b0:2c9:fde5:a354 with SMTP id y2-20020a2e9d42000000b002c9fde5a354mr2233080ljj.44.1701801656429; Tue, 05 Dec 2023 10:40:56 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231205114924.834626-1-xiaokeqinhealth@126.com> In-Reply-To: <20231205114924.834626-1-xiaokeqinhealth@126.com> From: Luiz Augusto von Dentz Date: Tue, 5 Dec 2023 13:40:44 -0500 Message-ID: Subject: Re: [PATCH] Bluetooth: MGMT/SMP: Fix address type when using smp over BREDR To: Xiao Yao Cc: linux-bluetooth@vger.kernel.org, xiaoyao@rock-chips.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Tue, Dec 5, 2023 at 7:05=E2=80=AFAM Xiao Yao w= rote: > > From: Xiao Yao > > When using SMP over BREDR, the identity address(irk/ltk/csrk) is > distributed during the SMP key distribution phase. > > > ACL Data RX: Handle 11 flags 0x02 dlen 12 > BR/EDR SMP: Identity Address Information (0x09) len 7 > Address: F8:7D:76:XX:XX:XX (OUI F8-7D-76) > @ MGMT Event: New Identity Resolving Key (0x0018) plen 30 > Store hint: Yes (0x01) > Random address: 00:00:00:00:00:00 (Non-Resolvable) > BR/EDR Address: F8:7D:76:XX:XX:XX (OUI F8-7D-76) > Key: 30cac11ec2bbc046a3658f62xxxxxxxx > @ MGMT Event: New Long Term Key (0x000a) plen 37 > Store hint: Yes (0x01) > LE Address: F8:7D:76:XX:XX:XX (OUI F8-7D-76) So I assume the above should change to BR/EDR after applying these changes? It probably make sense to have the trace of before and after just to be clearer. > Key type: Authenticated key from P-256 (0x03) > Central: 0x00 > Encryption size: 16 > Diversifier: 0000 > Randomizer: 0000000000000000 > Key: a3ca3f9e06cfa8c512edc13axxxxxxxx > > In the mgmt_new_irk/ltk/csrk() function, addr.type is forcefully converte= d > to BDADDR_LE_PUBLIC using link_to_bdaddr(LE_LINK, irk/ltk/csrk->addr_type= ). > However, the actual address type should be BDADDR_BREDR. Therefore, let's > pass the actual link type to determine the address type. > > Signed-off-by: Xiao Yao > --- > include/net/bluetooth/hci_core.h | 8 +++++--- > net/bluetooth/mgmt.c | 14 ++++++++------ > net/bluetooth/smp.c | 10 +++++----- > 3 files changed, 18 insertions(+), 14 deletions(-) > > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci= _core.h > index eed6c9f37b12..5088fbf4c7f5 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -2278,10 +2278,12 @@ void mgmt_suspending(struct hci_dev *hdev, u8 sta= te); > void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, > u8 addr_type); > bool mgmt_powering_down(struct hci_dev *hdev); > -void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persis= tent); > -void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persis= tent); > +void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persis= tent, > + u8 link_type); > +void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persis= tent, > + u8 link_type); > void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, > - bool persistent); > + bool persistent, u8 link_type); > void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, > u8 bdaddr_type, u8 store_hint, u16 min_interval, > u16 max_interval, u16 latency, u16 timeout); > diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c > index da79a2369dd7..fdfb395e29ba 100644 > --- a/net/bluetooth/mgmt.c > +++ b/net/bluetooth/mgmt.c > @@ -9550,7 +9550,8 @@ static u8 mgmt_ltk_type(struct smp_ltk *ltk) > return MGMT_LTK_UNAUTHENTICATED; > } > > -void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persis= tent) > +void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persis= tent, > + u8 link_type) > { > struct mgmt_ev_new_long_term_key ev; > > @@ -9574,7 +9575,7 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_= ltk *key, bool persistent) > ev.store_hint =3D persistent; > > bacpy(&ev.key.addr.bdaddr, &key->bdaddr); > - ev.key.addr.type =3D link_to_bdaddr(LE_LINK, key->bdaddr_type); > + ev.key.addr.type =3D link_to_bdaddr(link_type, key->bdaddr_type); > ev.key.type =3D mgmt_ltk_type(key); > ev.key.enc_size =3D key->enc_size; > ev.key.ediv =3D key->ediv; > @@ -9593,7 +9594,8 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_= ltk *key, bool persistent) > mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL= ); > } > > -void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persis= tent) > +void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persis= tent, > + u8 link_type) > { > struct mgmt_ev_new_irk ev; > > @@ -9603,14 +9605,14 @@ void mgmt_new_irk(struct hci_dev *hdev, struct sm= p_irk *irk, bool persistent) > > bacpy(&ev.rpa, &irk->rpa); > bacpy(&ev.irk.addr.bdaddr, &irk->bdaddr); > - ev.irk.addr.type =3D link_to_bdaddr(LE_LINK, irk->addr_type); > + ev.irk.addr.type =3D link_to_bdaddr(link_type, irk->addr_type); Perhaps we should incorporate the link_type as part of irk, ltk, csrk, etc, to guarantee this information is always available. > memcpy(ev.irk.val, irk->val, sizeof(irk->val)); > > mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); > } > > void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, > - bool persistent) > + bool persistent, u8 link_type) > { > struct mgmt_ev_new_csrk ev; > > @@ -9632,7 +9634,7 @@ void mgmt_new_csrk(struct hci_dev *hdev, struct smp= _csrk *csrk, > ev.store_hint =3D persistent; > > bacpy(&ev.key.addr.bdaddr, &csrk->bdaddr); > - ev.key.addr.type =3D link_to_bdaddr(LE_LINK, csrk->bdaddr_type); > + ev.key.addr.type =3D link_to_bdaddr(link_type, csrk->bdaddr_type)= ; > ev.key.type =3D csrk->type; > memcpy(ev.key.val, csrk->val, sizeof(csrk->val)); > > diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c > index f1a9fc0012f0..3f640741e07b 100644 > --- a/net/bluetooth/smp.c > +++ b/net/bluetooth/smp.c > @@ -1060,7 +1060,7 @@ static void smp_notify_keys(struct l2cap_conn *conn= ) > } > > if (smp->remote_irk) { > - mgmt_new_irk(hdev, smp->remote_irk, persistent); > + mgmt_new_irk(hdev, smp->remote_irk, persistent, hcon->typ= e); > > /* Now that user space can be considered to know the > * identity address track the connection based on it > @@ -1081,25 +1081,25 @@ static void smp_notify_keys(struct l2cap_conn *co= nn) > if (smp->csrk) { > smp->csrk->bdaddr_type =3D hcon->dst_type; > bacpy(&smp->csrk->bdaddr, &hcon->dst); > - mgmt_new_csrk(hdev, smp->csrk, persistent); > + mgmt_new_csrk(hdev, smp->csrk, persistent, hcon->type); > } > > if (smp->responder_csrk) { > smp->responder_csrk->bdaddr_type =3D hcon->dst_type; > bacpy(&smp->responder_csrk->bdaddr, &hcon->dst); > - mgmt_new_csrk(hdev, smp->responder_csrk, persistent); > + mgmt_new_csrk(hdev, smp->responder_csrk, persistent, hcon= ->type); > } > > if (smp->ltk) { > smp->ltk->bdaddr_type =3D hcon->dst_type; > bacpy(&smp->ltk->bdaddr, &hcon->dst); > - mgmt_new_ltk(hdev, smp->ltk, persistent); > + mgmt_new_ltk(hdev, smp->ltk, persistent, hcon->type); > } > > if (smp->responder_ltk) { > smp->responder_ltk->bdaddr_type =3D hcon->dst_type; > bacpy(&smp->responder_ltk->bdaddr, &hcon->dst); > - mgmt_new_ltk(hdev, smp->responder_ltk, persistent); > + mgmt_new_ltk(hdev, smp->responder_ltk, persistent, hcon->= type); > } > > if (smp->link_key) { > -- > 2.34.1 > > --=20 Luiz Augusto von Dentz