Skip to content

Commit 5544107

Browse files
Glenn Ruben Bakkeholtmann
authored andcommitted
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 <[email protected]> Acked-by: Jukka Rissanen <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Cc: [email protected] # 4.5+
1 parent 5c0e03c commit 5544107

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

net/bluetooth/6lowpan.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,18 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
434434
bdaddr_t *peer_addr, u8 *peer_addr_type)
435435
{
436436
struct in6_addr ipv6_daddr;
437+
struct ipv6hdr *hdr;
437438
struct lowpan_btle_dev *dev;
438439
struct lowpan_peer *peer;
439440
bdaddr_t addr, *any = BDADDR_ANY;
440441
u8 *daddr = any->b;
441442
int err, status = 0;
442443

444+
hdr = ipv6_hdr(skb);
445+
443446
dev = lowpan_btle_dev(netdev);
444447

445-
memcpy(&ipv6_daddr, &lowpan_cb(skb)->addr, sizeof(ipv6_daddr));
448+
memcpy(&ipv6_daddr, &hdr->daddr, sizeof(ipv6_daddr));
446449

447450
if (ipv6_addr_is_multicast(&ipv6_daddr)) {
448451
lowpan_cb(skb)->chan = NULL;
@@ -492,15 +495,9 @@ static int header_create(struct sk_buff *skb, struct net_device *netdev,
492495
unsigned short type, const void *_daddr,
493496
const void *_saddr, unsigned int len)
494497
{
495-
struct ipv6hdr *hdr;
496-
497498
if (type != ETH_P_IPV6)
498499
return -EINVAL;
499500

500-
hdr = ipv6_hdr(skb);
501-
502-
memcpy(&lowpan_cb(skb)->addr, &hdr->daddr, sizeof(struct in6_addr));
503-
504501
return 0;
505502
}
506503

0 commit comments

Comments
 (0)