linux-wpan.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Schmidt <stefan@osg.samsung.com>
To: Alexander Aring <alex.aring@gmail.com>, linux-wpan@vger.kernel.org
Cc: kernel@pengutronix.de
Subject: Re: [RFCv2 bluetooth-next 14/16] ieee802154: 6lowpan: check on valid 802.15.4 frame
Date: Mon, 31 Aug 2015 00:03:17 +0200	[thread overview]
Message-ID: <55E37DA5.5030604@osg.samsung.com> (raw)
In-Reply-To: <1440089265-23366-15-git-send-email-alex.aring@gmail.com>

Hello.

On 20/08/15 18:47, Alexander Aring wrote:
> This patch adds frame control checks to check if the received frame is
> something which could contain a 6LoWPAN packet.
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
>   include/linux/ieee802154.h  | 25 +++++++++++++++++++++++++
>   include/net/mac802154.h     | 15 +++++++++++++++
>   net/ieee802154/6lowpan/rx.c |  8 ++++++++
>   3 files changed, 48 insertions(+)
>
> diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
> index 1dc1f4e..db01492 100644
> --- a/include/linux/ieee802154.h
> +++ b/include/linux/ieee802154.h
> @@ -205,6 +205,31 @@ enum {
>   	IEEE802154_SCAN_IN_PROGRESS = 0xfc,
>   };
>   
> +/* frame control handling */
> +#define IEEE802154_FCTL_FTYPE		0x0003
> +#define IEEE802154_FCTL_INTRA_PAN	0x0040
> +
> +#define IEEE802154_FTYPE_DATA		0x0001
> +
> +/*
> + * ieee802154_is_data - check if type is IEEE802154_FTYPE_DATA
> + * @fc: frame control bytes in little-endian byteorder
> + */
> +static inline int ieee802154_is_data(__le16 fc)
> +{
> +	return (fc & cpu_to_le16(IEEE802154_FCTL_FTYPE)) ==
> +		cpu_to_le16(IEEE802154_FTYPE_DATA);
> +}
> +
> +/**
> + * ieee802154_is_intra_pan - check if intra pan id communication
> + * @fc: frame control bytes in little-endian byteorder
> + */
> +static inline bool ieee802154_is_intra_pan(__le16 fc)
> +{
> +	return fc & cpu_to_le16(IEEE802154_FCTL_INTRA_PAN);
> +}
> +
>   /**
>    * ieee802154_is_valid_psdu_len - check if psdu len is valid
>    * available lengths:
> diff --git a/include/net/mac802154.h b/include/net/mac802154.h
> index b7f9961..32bd7c0 100644
> --- a/include/net/mac802154.h
> +++ b/include/net/mac802154.h
> @@ -250,6 +250,21 @@ struct ieee802154_ops {
>   };
>   
>   /**
> + * ieee802154_get_fc_from_skb - get the frame control field from an skb
> + * @skb: skb where the frame control field will be get from
> + */
> +static inline __le16 ieee802154_get_fc_from_skb(const struct sk_buff *skb)
> +{
> +	/* return some invalid fc on failure */
> +	if (unlikely(skb->mac_len < 2)) {
> +		WARN_ON(1);
> +		return cpu_to_le16(0);
> +	}
> +
> +	return (__force __le16)__get_unaligned_memmove16(skb_mac_header(skb));
> +}
> +
> +/**
>    * ieee802154_be64_to_le64 - copies and convert be64 to le64
>    * @le64_dst: le64 destination pointer
>    * @be64_src: be64 source pointer
> diff --git a/net/ieee802154/6lowpan/rx.c b/net/ieee802154/6lowpan/rx.c
> index f98ebf5..5be996a 100644
> --- a/net/ieee802154/6lowpan/rx.c
> +++ b/net/ieee802154/6lowpan/rx.c
> @@ -11,6 +11,7 @@
>   #include <linux/if_arp.h>
>   
>   #include <net/6lowpan.h>
> +#include <net/mac802154.h>
>   #include <net/ieee802154_netdev.h>
>   
>   #include "6lowpan_i.h"
> @@ -278,6 +279,13 @@ static inline bool lowpan_is_reserved(u8 dispatch)
>    */
>   static inline bool lowpan_rx_h_check(struct sk_buff *skb)
>   {
> +	__le16 fc = ieee802154_get_fc_from_skb(skb);
> +
> +	/* check on ieee802154 conform 6LoWPAN header */
> +	if (!ieee802154_is_data(fc) ||
> +	    !ieee802154_is_intra_pan(fc))
> +		return false;
> +
>   	/* check if we can dereference the dispatch */
>   	if (unlikely(!skb->len))
>   		return false;

Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>

regards
Stefan Schmidt

  reply	other threads:[~2015-08-30 22:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-20 16:47 [RFCv2 bluetooth-next 00/16] ieee802154: 6lowpan: cleanup and rework dispatch evaluation Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 01/16] ieee802154: 6lowpan: change dev vars to wdev and ldev Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 02/16] ieee802154: 6lowpan: register packet layer while open Alexander Aring
2015-08-30 21:48   ` Stefan Schmidt
2015-09-01  7:38     ` Alexander Aring
2015-09-01  7:45       ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 03/16] ieee802154: 6lowpan: remove check on null Alexander Aring
2015-08-30 21:49   ` Stefan Schmidt
2015-09-01  7:52     ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 04/16] ieee802154: 6lowpan: remove set to zero Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 05/16] ieee802154: 6lowpan: remove EXPORT_SYMBOL Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 06/16] ieee802154: 6lowpan: change if lowpan dev is running Alexander Aring
2015-08-30 21:51   ` Stefan Schmidt
2015-09-01  7:53     ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 07/16] ieee802154: 6lowpan: cleanup pull of iphc bytes Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 08/16] ieee802154: 6lowpan: trivial checks at first Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 09/16] ieee802154: 6lowpan: earlier skb->dev switch Alexander Aring
2015-08-30 21:54   ` Stefan Schmidt
2015-09-01  7:53     ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 10/16] ieee820154: 6lowpan: dispatch evaluation rework Alexander Aring
2015-08-27 17:53   ` Alexander Aring
2015-08-31  9:28   ` Stefan Schmidt
2015-09-01  7:43     ` Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 11/16] ieee802154: 6lowpan: add generic lowpan header check Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 12/16] ieee802154: 6lowpan: add handler for all dispatch values Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 13/16] ieee802154: 6lowpan: add check for reserved dispatch Alexander Aring
2015-08-30 22:00   ` Stefan Schmidt
2015-09-01  7:39     ` Alexander Aring
2015-09-01  7:56     ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 14/16] ieee802154: 6lowpan: check on valid 802.15.4 frame Alexander Aring
2015-08-30 22:03   ` Stefan Schmidt [this message]
2015-09-01  7:57     ` Stefan Schmidt
2015-08-20 16:47 ` [RFCv2 bluetooth-next 15/16] ieee802154: 6lowpan: remove packet type to host Alexander Aring
2015-08-20 16:47 ` [RFCv2 bluetooth-next 16/16] ieee802154: 6lowpan: remove tx full-size calc workaround Alexander Aring
2015-08-30 22:06   ` Stefan Schmidt
2015-09-01  7:57     ` Stefan Schmidt
2015-08-30 21:45 ` [RFCv2 bluetooth-next 00/16] ieee802154: 6lowpan: cleanup and rework dispatch evaluation Stefan Schmidt

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=55E37DA5.5030604@osg.samsung.com \
    --to=stefan@osg.samsung.com \
    --cc=alex.aring@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-wpan@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).