Skip to contentSkip to conversation

mac802154: llsec: fix device deletion from list

PATCH In review Alexander Aring 1 participant 3 messages Sep 9, 2015 – Sep 10, 2015

Subsystems (2)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/2 mac802154: llsec: fix device deletion from list

This patch adds a missing list_del when a device description will be deleted.

Cc Phoebe Buckheister <[email protected]>
---
 net/mac802154/llsec.c | 1 +
 1 file changed, 1 insertion(+)
net/mac802154/llsec.c +1 -0
index 985e939..7799d3c 100644
@@ -401,6 +401,7 @@ int mac802154_llsec_dev_del(struct mac802154_llsec *sec, __le64 device_addr)
 
 	hash_del_rcu(&pos->bucket_s);
 	hash_del_rcu(&pos->bucket_hw);
+	list_del_rcu(&pos->dev.list);
 	call_rcu(&pos->rcu, llsec_dev_free_rcu);
 
 	return 0;
Signature · 1 line
2.5.1
author maintainer
#1 lore raw

PATCH 2/2 ieee802154: iface: fix header parse buffer overflow

This patch fixes a buffer overflow for header_parse callback. This callback is used by net/packet/af_packet.c which calls:

sll->sll_halen = dev_parse_header(skb, sll->sll_addr);

The "sll->sll_addr" is an array of eight bytes, but the size of struct ieee802154_addr is more than eight bytes long. I got funny mac header overwrites while dumping with wireshark/tcpdump.

I suppose with this function we can do filtering stuff by source address, so we do if extended address then copy the full address and "sll->sll_addr" is eight bytes long. If short address we copy a combination with "pan_id+short_addr", the "sll->sll_addr" should be four then. In case of none, we do nothing and "sll->sll_addr" returns zero. This should provide some unique address matching mechanism.

---
 include/linux/ieee802154.h |  2 ++
 net/mac802154/iface.c      | 26 +++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)
include/linux/ieee802154.h +2 -0
index db01492..7b1a28a 100644
@@ -37,6 +37,8 @@
 #define IEEE802154_ADDR_SHORT_UNSPEC	0xfffe
 
 #define IEEE802154_EXTENDED_ADDR_LEN	8
+#define IEEE802154_SHORT_ADDR_LEN	2
+#define IEEE802154_PAN_ID_LEN		2
 
 #define IEEE802154_LIFS_PERIOD		40
 #define IEEE802154_SIFS_PERIOD		12
net/mac802154/iface.c +23 -3
index ed26952..87e4183 100644
@@ -427,15 +427,35 @@ static int
 mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
 {
 	struct ieee802154_hdr hdr;
-	struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
+	int pos = 0;
 
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
 		pr_debug("malformed packet\n");
 		return 0;
 	}
 
-	*addr = hdr.source;
-	return sizeof(*addr);
+	switch (hdr.source.mode) {
+	case IEEE802154_ADDR_LONG:
+		memcpy(haddr + pos, &hdr.source.extended_addr,
+		       IEEE802154_EXTENDED_ADDR_LEN);
+		pos += IEEE802154_EXTENDED_ADDR_LEN;
+		break;
+	case IEEE802154_ADDR_SHORT:
+		memcpy(haddr + pos, &hdr.source.pan_id,
+		       IEEE802154_PAN_ID_LEN);
+		pos += IEEE802154_PAN_ID_LEN;
+		memcpy(haddr + pos, &hdr.source.short_addr,
+		       IEEE802154_SHORT_ADDR_LEN);
+		pos += IEEE802154_SHORT_ADDR_LEN;
+		break;
+	case IEEE802154_ADDR_NONE:
+		/* fall-through */
+
+	default:
+		break;
+	}
+
+	return pos;
 }
 
 static struct header_ops mac802154_header_ops = {
Signature · 1 line
2.5.1
author maintainer
#2 lore raw

Re: [PATCH bluetooth-next 2/2] ieee802154: iface: fix header parse buffer overflow

Hi,

Quoted 68 lines · Alexander Aring

This patch fixes a buffer overflow for header_parse callback. This callback is used by net/packet/af_packet.c which calls:

sll->sll_halen = dev_parse_header(skb, sll->sll_addr);

The "sll->sll_addr" is an array of eight bytes, but the size of struct ieee802154_addr is more than eight bytes long. I got funny mac header overwrites while dumping with wireshark/tcpdump.

I suppose with this function we can do filtering stuff by source address, so we do if extended address then copy the full address and "sll->sll_addr" is eight bytes long. If short address we copy a combination with "pan_id+short_addr", the "sll->sll_addr" should be four then. In case of none, we do nothing and "sll->sll_addr" returns zero. This should provide some unique address matching mechanism.

---
 include/linux/ieee802154.h |  2 ++
 net/mac802154/iface.c      | 26 +++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)
include/linux/ieee802154.h +2 -0
index db01492..7b1a28a 100644
@@ -37,6 +37,8 @@
 #define IEEE802154_ADDR_SHORT_UNSPEC	0xfffe
 
 #define IEEE802154_EXTENDED_ADDR_LEN	8
+#define IEEE802154_SHORT_ADDR_LEN	2
+#define IEEE802154_PAN_ID_LEN		2
 
 #define IEEE802154_LIFS_PERIOD		40
 #define IEEE802154_SIFS_PERIOD		12
net/mac802154/iface.c +16 -3
index ed26952..87e4183 100644
@@ -427,15 +427,35 @@ static int
 mac802154_header_parse(const struct sk_buff *skb, unsigned char *haddr)
 {
 	struct ieee802154_hdr hdr;
-	struct ieee802154_addr *addr = (struct ieee802154_addr *)haddr;
+	int pos = 0;
 
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0) {
 		pr_debug("malformed packet\n");
 		return 0;
 	}
 
-	*addr = hdr.source;
-	return sizeof(*addr);
+	switch (hdr.source.mode) {
+	case IEEE802154_ADDR_LONG:
+		memcpy(haddr + pos, &hdr.source.extended_addr,
+		       IEEE802154_EXTENDED_ADDR_LEN);
+		pos += IEEE802154_EXTENDED_ADDR_LEN;
+		break;
+	case IEEE802154_ADDR_SHORT:
+		memcpy(haddr + pos, &hdr.source.pan_id,
+		       IEEE802154_PAN_ID_LEN);
+		pos += IEEE802154_PAN_ID_LEN;
+		memcpy(haddr + pos, &hdr.source.short_addr,
+		       IEEE802154_SHORT_ADDR_LEN);
+		pos += IEEE802154_SHORT_ADDR_LEN;
+		break;
+	case IEEE802154_ADDR_NONE:

net/mac802154/iface.c static int · line 461

Quoted 10 lines
net/mac802154/iface.c +7 -0
+		/* fall-through */
+
+	default:
+		break;
+	}
+
+	return pos;
 }
 
 static struct header_ops mac802154_header_ops = {

Maybe it's better to replace the full mac802154_header_ops structure, see [0] to:

static struct header_ops mac802154_header_ops = {
	.create         = mac802154_header_create,
};

The API for the "parse" callback simple doesn't fit into 802.15.4 address cases. The above solution "might" work to get an unique source address information, for whatever libpcap uses that, but requires that libpcap knows the format what we meaning there:

len -> addr_type
8 -> extended_addr (le64)
4 -> pan_id+short_addr (le16+le16)
0 -> none

This requires some userspace api changes and "maybe" also applications which uses libpcap.

We can "simple" remove this callback and I suppose that we simple doesn't provide the source address then. See [1] and [2].

For the "create" callback we should replace it with a function which returns simple "-EOPNOTSUPP". It's is also used by af_packet.c and horrible broken, because this callback assumes the "right" information inside "skb->cb". There are only given by 802.15.4 upper layer protocols and not for net core api upper layer foo like af_packet.

Also we should not do .create = NULL, because af_packet.c thinks that the mac header will be created "somehow" afterwards. Then simple forbid this option for now. For sending DGRAM packets it should use af_802154 then.

What we should provide are own "ieee802154_header_ops" for the wpan_dev which contains header creation function pointers which are 802.15.4 specific. Upper layers can call them then like dev_hard_header. And of course remove of skb->cb information.

- Alex

[0] http://lxr.free-electrons.com/source/net/mac802154/iface.c#L430
[1] http://lxr.free-electrons.com/source/include/linux/netdevice.h#L2421
[2] http://lxr.free-electrons.com/source/net/packet/af_packet.c#L1919