linux/net/ieee802154
Lennert Buytenhek 45c24a7401 ieee802154: Fix sockaddr_ieee802154 implicit padding information leak.
commit 8a70cefa30 upstream.

The AF_IEEE802154 sockaddr looks like this:

	struct sockaddr_ieee802154 {
		sa_family_t family; /* AF_IEEE802154 */
		struct ieee802154_addr_sa addr;
	};

	struct ieee802154_addr_sa {
		int addr_type;
		u16 pan_id;
		union {
			u8 hwaddr[IEEE802154_ADDR_LEN];
			u16 short_addr;
		};
	};

On most architectures there will be implicit structure padding here,
in two different places:

* In struct sockaddr_ieee802154, two bytes of padding between 'family'
  (unsigned short) and 'addr', so that 'addr' starts on a four byte
  boundary.

* In struct ieee802154_addr_sa, two bytes at the end of the structure,
  to make the structure 16 bytes.

When calling recvmsg(2) on a PF_IEEE802154 SOCK_DGRAM socket, the
ieee802154 stack constructs a struct sockaddr_ieee802154 on the
kernel stack without clearing these padding fields, and, depending
on the addr_type, between four and ten bytes of uncleared kernel
stack will be copied to userspace.

We can't just insert two 'u16 __pad's in the right places and zero
those before copying an address to userspace, as not all architectures
insert this implicit padding -- from a quick test it seems that avr32,
cris and m68k don't insert this padding, while every other architecture
that I have cross compilers for does insert this padding.

The easiest way to plug the leak is to just memset the whole struct
sockaddr_ieee802154 before filling in the fields we want to fill in,
and that's what this patch does.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Acked-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
[ luis: backported to 3.16:
  - file rename: net/ieee802154/socket.c -> net/ieee802154/dgram.c ]
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
History 2015-07-15 10:00:19 +01:00
..
6lowpan_iphc.c 6lowpan: move 6lowpan header to include/net 2014-03-06 17:21:38 -05:00
6lowpan_rtnl.c 6lowpan_rtnl: fix off by one while fragmentation 2014-06-02 10:39:42 -07:00
af802154.h mac802154: use header operations to create/parse headers 2014-03-14 22:15:26 -04:00
af_ieee802154.c af_ieee802154: fix check on broadcast address 2014-03-20 17:19:45 -04:00
dgram.c ieee802154: Fix sockaddr_ieee802154 implicit padding information leak. 2015-07-15 10:00:19 +01:00
header_ops.c ieee802154: add definitions for link-layer security and header functions 2014-05-15 15:51:42 -04:00
ieee802154.h ieee802154: add netlink interfaces for llsec 2014-05-16 17:23:41 -04:00
Kconfig ieee802154: fix whitespace issues in Kconfig 2014-03-04 20:12:44 -05:00
Makefile ieee802154: add header structs with endiannes and operations 2014-03-14 22:15:26 -04:00
netlink.c ieee802154: add netlink interfaces for llsec 2014-05-16 17:23:41 -04:00
nl-mac.c ieee802154: missing put_dev() on error 2014-05-22 15:54:45 -04:00
nl-phy.c mac802154: make csma/cca parameters per-wpan 2014-04-01 16:25:51 -04:00
nl_policy.c ieee802154: add netlink interfaces for llsec 2014-05-16 17:23:41 -04:00
raw.c ieee802154: properly unshare skbs in ieee802154 *_rcv functions 2014-03-18 15:59:25 -04:00
reassembly.c 6lowpan: make lowpan_cb static 2014-04-20 18:18:55 -04:00
reassembly.h ieee802154: use ieee802154_addr instead of *_sa variants 2014-03-14 22:15:26 -04:00
wpan-class.c mac802154: make csma/cca parameters per-wpan 2014-04-01 16:25:51 -04:00