diff options
author | Glenn Ruben Bakke <glennrubenbakke@nordicsemi.no> | 2016-04-22 12:06:11 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2016-04-25 19:08:25 -0400 |
commit | 55441070ca1cbd47ce1ad2959bbf4b47aed9b83b (patch) | |
tree | 520b1520d798b485a4fafcda388331ac23c65027 /net/bluetooth/6lowpan.c | |
parent | 5c0e03cd9f10d541b69b667a2b1b8980f196f432 (diff) |
Bluetooth: 6lowpan: Fix memory corruption of ipv6 destination address
The memcpy of ipv6 header destination address to the skb control block
(sbk->cb) in header_create() results in currupted memory when bt_xmit()
is issued. The skb->cb is "released" in the return of header_create()
making room for lower layer to minipulate the skb->cb.
The value retrieved in bt_xmit is not persistent across header creation
and sending, and the lower layer will overwrite portions of skb->cb,
making the copied destination address wrong.
The memory corruption will lead to non-working multicast as the first 4
bytes of the copied destination address is replaced by a value that
resolves into a non-multicast prefix.
This fix removes the dependency on the skb control block between header
creation and send, by moving the destination address memcpy to the send
function path (setup_create, which is called from bt_xmit).
Signed-off-by: Glenn Ruben Bakke <glenn.ruben.bakke@nordicsemi.no>
Acked-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Cc: stable@vger.kernel.org # 4.5+
Diffstat (limited to 'net/bluetooth/6lowpan.c')
-rw-r--r-- | net/bluetooth/6lowpan.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 38e82ddd7ccd..780089d75915 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c | |||
@@ -434,15 +434,18 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev, | |||
434 | bdaddr_t *peer_addr, u8 *peer_addr_type) | 434 | bdaddr_t *peer_addr, u8 *peer_addr_type) |
435 | { | 435 | { |
436 | struct in6_addr ipv6_daddr; | 436 | struct in6_addr ipv6_daddr; |
437 | struct ipv6hdr *hdr; | ||
437 | struct lowpan_btle_dev *dev; | 438 | struct lowpan_btle_dev *dev; |
438 | struct lowpan_peer *peer; | 439 | struct lowpan_peer *peer; |
439 | bdaddr_t addr, *any = BDADDR_ANY; | 440 | bdaddr_t addr, *any = BDADDR_ANY; |
440 | u8 *daddr = any->b; | 441 | u8 *daddr = any->b; |
441 | int err, status = 0; | 442 | int err, status = 0; |
442 | 443 | ||
444 | hdr = ipv6_hdr(skb); | ||
445 | |||
443 | dev = lowpan_btle_dev(netdev); | 446 | dev = lowpan_btle_dev(netdev); |
444 | 447 | ||
445 | memcpy(&ipv6_daddr, &lowpan_cb(skb)->addr, sizeof(ipv6_daddr)); | 448 | memcpy(&ipv6_daddr, &hdr->daddr, sizeof(ipv6_daddr)); |
446 | 449 | ||
447 | if (ipv6_addr_is_multicast(&ipv6_daddr)) { | 450 | if (ipv6_addr_is_multicast(&ipv6_daddr)) { |
448 | lowpan_cb(skb)->chan = NULL; | 451 | lowpan_cb(skb)->chan = NULL; |
@@ -492,15 +495,9 @@ static int header_create(struct sk_buff *skb, struct net_device *netdev, | |||
492 | unsigned short type, const void *_daddr, | 495 | unsigned short type, const void *_daddr, |
493 | const void *_saddr, unsigned int len) | 496 | const void *_saddr, unsigned int len) |
494 | { | 497 | { |
495 | struct ipv6hdr *hdr; | ||
496 | |||
497 | if (type != ETH_P_IPV6) | 498 | if (type != ETH_P_IPV6) |
498 | return -EINVAL; | 499 | return -EINVAL; |
499 | 500 | ||
500 | hdr = ipv6_hdr(skb); | ||
501 | |||
502 | memcpy(&lowpan_cb(skb)->addr, &hdr->daddr, sizeof(struct in6_addr)); | ||
503 | |||
504 | return 0; | 501 | return 0; |
505 | } | 502 | } |
506 | 503 | ||