All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 1/2] Bluetooth: Introduce bt_skb_pull
@ 2021-04-12 18:40 Luiz Augusto von Dentz
  2021-04-12 18:40 ` [RFC 2/2] Bluetooth: HCI: Use bt_skb_pull to parse events Luiz Augusto von Dentz
  2021-04-12 19:37 ` [RFC,1/2] Bluetooth: Introduce bt_skb_pull bluez.test.bot
  0 siblings, 2 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-04-12 18:40 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds bt_skb_pull which will be used to parse events, it checks
the skb contains the given length and then use skb_pull to advance in
data which avoid having to rely on another variable to track the
position in the buffer.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 include/net/bluetooth/bluetooth.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 9125effbf448..449bc8e112f9 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -420,6 +420,18 @@ static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
 	return NULL;
 }
 
+static inline void *bt_skb_pull(struct sk_buff *skb, size_t len)
+{
+	void *data = skb->data;
+
+	if (skb->len < len)
+		return NULL;
+
+	skb_pull(skb, len);
+
+	return data;
+}
+
 int bt_to_errno(u16 code);
 
 void hci_sock_set_flag(struct sock *sk, int nr);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Re: [RFC 2/2] Bluetooth: HCI: Use bt_skb_pull to parse events
@ 2021-04-13  5:18 kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2021-04-13  5:18 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 5361 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210412184033.2504931-2-luiz.dentz@gmail.com>
References: <20210412184033.2504931-2-luiz.dentz@gmail.com>
TO: Luiz Augusto von Dentz <luiz.dentz@gmail.com>

Hi Luiz,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20210412]
[cannot apply to bluetooth/master v5.12-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-Introduce-bt_skb_pull/20210413-024225
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
:::::: branch date: 11 hours ago
:::::: commit date: 11 hours ago
config: i386-randconfig-m021-20210413 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
net/bluetooth/hci_event.c:6092 hci_le_adv_report_evt() warn: potential spectre issue 'info->data' [r] (local cap)
net/bluetooth/hci_event.c:6434 hci_le_phy_update_evt() error: we previously assumed 'ev' could be null (see line 6426)

Old smatch warnings:
net/bluetooth/hci_event.c:849 hci_cc_read_local_ext_features() warn: potential spectre issue 'hdev->features' [w] (local cap)
net/bluetooth/hci_event.c:4575 hci_remote_ext_features_evt() warn: potential spectre issue 'conn->features' [w] (local cap)
net/bluetooth/hci_event.c:6094 hci_le_adv_report_evt() warn: possible spectre second half.  'rssi'

vim +6092 net/bluetooth/hci_event.c

4af605d8c4d3cf Johan Hedberg          2014-03-24  6063  
6039aa73a1323e Gustavo Padovan        2012-05-23  6064  static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
9aa04c9108164e Andre Guedes           2011-05-26  6065  {
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6066  	struct hci_ev_le_advertising_report *ev;
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6067  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6068  	ev = bt_skb_pull(skb, sizeof(*ev));
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6069  	if (!ev) {
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6070  		bt_dev_err(hdev, "Malformed HCI LE metaevent: 0x%2.2x",
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6071  			   HCI_EV_LE_ADVERTISING_REPORT);
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6072  		return;
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6073  	}
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6074  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6075  	if (!ev->num)
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6076  		return;
9aa04c9108164e Andre Guedes           2011-05-26  6077  
a4790dbd43d161 Andre Guedes           2014-02-26  6078  	hci_dev_lock(hdev);
a4790dbd43d161 Andre Guedes           2014-02-26  6079  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6080  	while (ev->num--) {
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6081  		struct hci_ev_le_advertising_info *info;
4af605d8c4d3cf Johan Hedberg          2014-03-24  6082  		s8 rssi;
a4790dbd43d161 Andre Guedes           2014-02-26  6083  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6084  		info = bt_skb_pull(skb, sizeof(*info));
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6085  		if (!info || skb->len < info->length + 1) {
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6086  			bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6087  				   HCI_EV_LE_ADVERTISING_REPORT);
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6088  			break;
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6089  		}
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6090  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6091  		if (info->length <= HCI_MAX_AD_LENGTH) {
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12 @6092  			rssi = info->data[info->length];
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6093  			process_adv_report(hdev, info->type, &info->bdaddr,
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6094  					   info->bdaddr_type, NULL, 0, rssi,
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6095  					   info->data, info->length, false);
ee6493462f7401 Chriz Chow             2018-04-20  6096  		} else {
ee6493462f7401 Chriz Chow             2018-04-20  6097  			bt_dev_err(hdev, "Dropping invalid advertising data");
ee6493462f7401 Chriz Chow             2018-04-20  6098  		}
3c9e919511f87f Andre Guedes           2012-01-10  6099  
a1b501d4f0d7a0 Luiz Augusto von Dentz 2021-04-12  6100  		skb_pull(skb, info->length + 1);
9aa04c9108164e Andre Guedes           2011-05-26  6101  	}
a4790dbd43d161 Andre Guedes           2014-02-26  6102  
a4790dbd43d161 Andre Guedes           2014-02-26  6103  	hci_dev_unlock(hdev);
9aa04c9108164e Andre Guedes           2011-05-26  6104  }
9aa04c9108164e Andre Guedes           2011-05-26  6105  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 38500 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-16 20:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 18:40 [RFC 1/2] Bluetooth: Introduce bt_skb_pull Luiz Augusto von Dentz
2021-04-12 18:40 ` [RFC 2/2] Bluetooth: HCI: Use bt_skb_pull to parse events Luiz Augusto von Dentz
2021-04-13 19:08   ` Marcel Holtmann
2021-04-13 21:15     ` Luiz Augusto von Dentz
2021-04-14 10:10       ` Marcel Holtmann
2021-04-16 20:44         ` Luiz Augusto von Dentz
2021-04-12 19:37 ` [RFC,1/2] Bluetooth: Introduce bt_skb_pull bluez.test.bot
2021-04-12 21:38   ` Luiz Augusto von Dentz
2021-04-13  5:18 [RFC 2/2] Bluetooth: HCI: Use bt_skb_pull to parse events kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.