linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Emeltchenko Andrei <Andrei.Emeltchenko.news@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [RFCv2 5/6] Bluetooth: Correct packet len calculation
Date: Thu, 08 Dec 2011 10:18:03 +0200	[thread overview]
Message-ID: <1323332283.1965.12.camel@aeonflux> (raw)
In-Reply-To: <1323266216-25261-6-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

> Remove unneeded skb_pull and correct packet length calculation
> removing magic number.
> ---
>  net/bluetooth/hci_event.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index cfccf7e..21c1bf0 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -2268,8 +2268,6 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
>  	struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
>  	int i;
>  
> -	skb_pull(skb, sizeof(*ev));
> -
>  	BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
>  
>  	if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
> @@ -2277,7 +2275,8 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
>  		return;
>  	}
>  
> -	if (skb->len < ev->num_hndl * 4) {
> +	if (skb->len < ev->num_hndl * sizeof(struct hci_comp_pkts_info) +
> +			sizeof(*ev)) {
>  		BT_DBG("%s bad parameters", hdev->name);
>  		return;
>  	}

actually this check is not enough. You need to make this two-fold.

	if (skb->len < sizeof(*ev)) {
		...
		return;
	}

This needs to be checked first. Otherwise you are accessing ev->num_hndl
before even knowing that it is valid. A malicious device could otherwise
sneak in some weird behavior.

Regards

Marcel



  reply	other threads:[~2011-12-08  8:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07 13:56 [RFCv2 0/6] Implement basic HCI block-based flow control Emeltchenko Andrei
2011-12-07 13:56 ` [RFCv2 1/6] Bluetooth: Add HCI Read Data Block Size function Emeltchenko Andrei
2011-12-18 23:36   ` Gustavo Padovan
2011-12-07 13:56 ` [RFCv2 2/6] Bluetooth: Simplify num_comp_pkts_evt function Emeltchenko Andrei
2011-12-08  8:12   ` Marcel Holtmann
2011-12-18 23:37   ` Gustavo Padovan
2011-12-07 13:56 ` [RFCv2 3/6] Bluetooth: Check for flow control mode Emeltchenko Andrei
2011-12-08  8:13   ` Marcel Holtmann
2011-12-18 23:40   ` Gustavo Padovan
2011-12-07 13:56 ` [RFCv2 4/6] Bluetooth: Clean up magic pointers Emeltchenko Andrei
2011-12-08  8:14   ` Marcel Holtmann
2011-12-07 13:56 ` [RFCv2 5/6] Bluetooth: Correct packet len calculation Emeltchenko Andrei
2011-12-08  8:18   ` Marcel Holtmann [this message]
2011-12-08  8:26     ` Emeltchenko Andrei
2011-12-08  8:30       ` Marcel Holtmann
2011-12-07 13:56 ` [RFCv2 6/6] Bluetooth: Process num completed data blocks event Emeltchenko Andrei
2011-12-08  8:19   ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323332283.1965.12.camel@aeonflux \
    --to=marcel@holtmann.org \
    --cc=Andrei.Emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).