Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1314470pxy; Fri, 23 Apr 2021 05:29:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyqJksdGjXW9dXyFycGc6/jeA23IlVqgLLg6UndI+MU8vEg0EyKfKr6UE7QoGj7x2s61V3 X-Received: by 2002:a17:906:d154:: with SMTP id br20mr3953843ejb.28.1619180989110; Fri, 23 Apr 2021 05:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619180989; cv=none; d=google.com; s=arc-20160816; b=hXIR++5933M29JtGhmOdVaBI9FdO1WzkESn6C6VfAA+2Q8p8xEnP0RphYVjfxt9sd3 35ysDVd3oWpSBexoXc0t1QvXDg0qG7FoOj/ONgsVSTbafqQ9/nyE+WSXNNVEdK1nOMzz v0kyDCwICMkuxSyJHK45jpHTiuqs/eM3c5FOZVeqGQCXblhzWMzBY/wBJQdGqYkSsFWp z4fAREaw7LyOoTlj9dsSfkwZEspfaDo63DElS4gycjoCdTvgae6KrZ0zarsKeR6rfilA u4iGJbsWqYEKZh/bcKHUIv9tzBRxUMH+9zYp232Ks1Qie1Or7JJl/YbuusenqV0M6cp/ a4RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=/2BHTiICOSWyau+6JXJno/QnzFQDkab9hUgn7IKtb5A=; b=Sffc6JJhdq+PolL7MZ3o9cAd6L7uFIcf7jcQwby5JDcFxkDn+Gk/HCiOSkNQMwWdbN 0hsGXFrRG6VCgDhsT+eidjPaiQYqi84J/PPixNaqmCQWpP+PsJJeKtmjagNtP2bORCXX SdFKsRUuYa9cBwtfW6GtVfa34REEw9/ClvuRHgb1VDnFENr/tnm42/1Mz9ukduXW4dzc T8Juw90xoiLjwpf6wBXuIn+mphg9cIJA6qENw88wKa/Ki8JyxWkNTo8uPguvYYZ05SFg jSf+kAAwSw1wzZjCnX0Gr8rSRSvoukggp2uecQDr/jH8/eS8sbxC0sxLwsjCSI/LZ0aI SbVQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n10si4770940edy.130.2021.04.23.05.29.23; Fri, 23 Apr 2021 05:29:49 -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; 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 S242301AbhDWM3I convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Apr 2021 08:29:08 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:36079 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242328AbhDWM3E (ORCPT ); Fri, 23 Apr 2021 08:29:04 -0400 Received: from marcel-macbook.holtmann.net (p4fefc624.dip0.t-ipconnect.de [79.239.198.36]) by mail.holtmann.org (Postfix) with ESMTPSA id 44672CED00; Fri, 23 Apr 2021 14:36:14 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [PATCH v2 04/10] Bluetooth: HCI: Use skb_pull to parse Inquiry Result event From: Marcel Holtmann In-Reply-To: <20210419171257.3865181-5-luiz.dentz@gmail.com> Date: Fri, 23 Apr 2021 14:28:27 +0200 Cc: linux-bluetooth@vger.kernel.org Content-Transfer-Encoding: 8BIT Message-Id: References: <20210419171257.3865181-1-luiz.dentz@gmail.com> <20210419171257.3865181-5-luiz.dentz@gmail.com> To: Luiz Augusto von Dentz X-Mailer: Apple Mail (2.3654.60.0.2.21) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, > This uses skb_pull to check the Inquiry Result events received have > the minimum required length. > > Signed-off-by: Luiz Augusto von Dentz > --- > include/net/bluetooth/hci.h | 5 +++++ > net/bluetooth/hci_event.c | 19 ++++++++++++++----- > 2 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h > index 9251ae3a2ce0..b65205b4d830 100644 > --- a/include/net/bluetooth/hci.h > +++ b/include/net/bluetooth/hci.h > @@ -1910,6 +1910,11 @@ struct inquiry_info { > __le16 clock_offset; > } __packed; > > +struct hci_ev_inquiry_result { > + __u8 num; > + struct inquiry_info info[]; > +}; > + > #define HCI_EV_CONN_COMPLETE 0x03 > struct hci_ev_conn_complete { > __u8 status; > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index c353dfafb04c..6516538fe238 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -2990,13 +2990,21 @@ static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) > > static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) > { > + struct hci_ev_inquiry_result *ev; > struct inquiry_data data; > - struct inquiry_info *info = (void *) (skb->data + 1); > - int num_rsp = *((__u8 *) skb->data); > + int i; > > - BT_DBG("%s num_rsp %d", hdev->name, num_rsp); > + ev = hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT, sizeof(*ev)); > + if (!ev) > + return; > > - if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) > + if (!hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT, > + flex_array_size(ev, info, ev->num))) > + return; > + > + BT_DBG("%s num %d", hdev->name, ev->num); please switch to bt_dev_dbg() here. Regards Marcel