linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
To: Alexander Aring <alex.aring@gmail.com>
Cc: linux-bluetooth@vger.kernel.org, linux-wpan@vger.kernel.org,
	kernel@pengutronix.de, marcel@holtmann.org,
	werner@almesberger.net, mkl@pengutronix.de
Subject: Re: [RFC bluetooth-next 1/2] af_ieee802154: fix struct ieee802154_addr_sa size
Date: Tue, 13 Jan 2015 13:33:39 +0100	[thread overview]
Message-ID: <20150113133339.0272b42f@zoidberg> (raw)
In-Reply-To: <1420929206-5771-2-git-send-email-alex.aring@gmail.com>

Hi,

On Sat, 10 Jan 2015 23:33:25 +0100
Alexander Aring <alex.aring@gmail.com> wrote:

> The structure "ieee802154_addr_sa" need to fit into the u8 sa_data[14]
> from struct sockaddr, because there is a casting of "struct sockaddr"
> and "struct ieee802154_sockaddr".
> 
> I tested a compiling with a 32 bit system and detected that the
> "struct ieee802154_sockaddr", which contains the ieee802154_addr_sa
> structure, has a size of 20 bytes. The "struct sockaddr" has a size
> of 16 bytes. This doesn't fit together and some buffers are
> overflows. This patch changes the "addr_type" type definition from
> "int" to "u8". After this change it will be fits together.

Do look at how Unix domain sockets handle the problem. Also, IPv6
addresses exceed sizeof(struct sockaddr) quite significantly. Casting
pointers isn't a problem, only if we *ever* store our addrs to a struct
sockaddr will we have a problem.

Perhaps I am missing something, but from what I can tell, i think the
code is safe at least in that regard.

> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
>  include/net/af_ieee802154.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net/af_ieee802154.h b/include/net/af_ieee802154.h
> index 7d38e2f..3652269 100644
> --- a/include/net/af_ieee802154.h
> +++ b/include/net/af_ieee802154.h
> @@ -33,7 +33,7 @@ enum {
>  #define IEEE802154_ADDR_LEN	8
>  
>  struct ieee802154_addr_sa {
> -	int addr_type;
> +	u8 addr_type;
>  	u16 pan_id;
>  	union {
>  		u8 hwaddr[IEEE802154_ADDR_LEN];

  reply	other threads:[~2015-01-13 12:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-10 22:33 [RFC bluetooth-next 0/2] ieee802154: socket: fix buffer overflow Alexander Aring
2015-01-10 22:33 ` [RFC bluetooth-next 1/2] af_ieee802154: fix struct ieee802154_addr_sa size Alexander Aring
2015-01-13 12:33   ` Phoebe Buckheister [this message]
2015-01-10 22:33 ` [RFC bluetooth-next 2/2] ieee802154: socket: add BUILD_BUG_ON for cast check Alexander Aring

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=20150113133339.0272b42f@zoidberg \
    --to=phoebe.buckheister@itwm.fraunhofer.de \
    --cc=alex.aring@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=mkl@pengutronix.de \
    --cc=werner@almesberger.net \
    /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).