sharkcz / rpms / kernel

Forked from rpms/kernel 6 years ago
Clone
9dd5b58
From 4d6fa57b4dab0d77f4d8e9d9c73d1e63f6fe8fee Mon Sep 17 00:00:00 2001
9dd5b58
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
9dd5b58
Date: Fri, 21 Apr 2017 23:14:48 +0200
9dd5b58
Subject: macsec: avoid heap overflow in skb_to_sgvec
9dd5b58
9dd5b58
While this may appear as a humdrum one line change, it's actually quite
9dd5b58
important. An sk_buff stores data in three places:
9dd5b58
9dd5b58
1. A linear chunk of allocated memory in skb->data. This is the easiest
9dd5b58
   one to work with, but it precludes using scatterdata since the memory
9dd5b58
   must be linear.
9dd5b58
2. The array skb_shinfo(skb)->frags, which is of maximum length
9dd5b58
   MAX_SKB_FRAGS. This is nice for scattergather, since these fragments
9dd5b58
   can point to different pages.
9dd5b58
3. skb_shinfo(skb)->frag_list, which is a pointer to another sk_buff,
9dd5b58
   which in turn can have data in either (1) or (2).
9dd5b58
9dd5b58
The first two are rather easy to deal with, since they're of a fixed
9dd5b58
maximum length, while the third one is not, since there can be
9dd5b58
potentially limitless chains of fragments. Fortunately dealing with
9dd5b58
frag_list is opt-in for drivers, so drivers don't actually have to deal
9dd5b58
with this mess. For whatever reason, macsec decided it wanted pain, and
9dd5b58
so it explicitly specified NETIF_F_FRAGLIST.
9dd5b58
9dd5b58
Because dealing with (1), (2), and (3) is insane, most users of sk_buff
9dd5b58
doing any sort of crypto or paging operation calls a convenient function
9dd5b58
called skb_to_sgvec (which happens to be recursive if (3) is in use!).
9dd5b58
This takes a sk_buff as input, and writes into its output pointer an
9dd5b58
array of scattergather list items. Sometimes people like to declare a
9dd5b58
fixed size scattergather list on the stack; othertimes people like to
9dd5b58
allocate a fixed size scattergather list on the heap. However, if you're
9dd5b58
doing it in a fixed-size fashion, you really shouldn't be using
9dd5b58
NETIF_F_FRAGLIST too (unless you're also ensuring the sk_buff and its
9dd5b58
frag_list children arent't shared and then you check the number of
9dd5b58
fragments in total required.)
9dd5b58
9dd5b58
Macsec specifically does this:
9dd5b58
9dd5b58
        size += sizeof(struct scatterlist) * (MAX_SKB_FRAGS + 1);
9dd5b58
        tmp = kmalloc(size, GFP_ATOMIC);
9dd5b58
        *sg = (struct scatterlist *)(tmp + sg_offset);
9dd5b58
	...
9dd5b58
        sg_init_table(sg, MAX_SKB_FRAGS + 1);
9dd5b58
        skb_to_sgvec(skb, sg, 0, skb->len);
9dd5b58
9dd5b58
Specifying MAX_SKB_FRAGS + 1 is the right answer usually, but not if you're
9dd5b58
using NETIF_F_FRAGLIST, in which case the call to skb_to_sgvec will
9dd5b58
overflow the heap, and disaster ensues.
9dd5b58
9dd5b58
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
9dd5b58
Cc: stable@vger.kernel.org
9dd5b58
Cc: security@kernel.org
9dd5b58
Signed-off-by: David S. Miller <davem@davemloft.net>
9dd5b58
---
9dd5b58
 drivers/net/macsec.c | 2 +-
9dd5b58
 1 file changed, 1 insertion(+), 1 deletion(-)
9dd5b58
9dd5b58
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
9dd5b58
index ff0a5ed..dbab05a 100644
9dd5b58
--- a/drivers/net/macsec.c
9dd5b58
+++ b/drivers/net/macsec.c
9dd5b58
@@ -2716,7 +2716,7 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
9dd5b58
 }
9dd5b58
 
9dd5b58
 #define MACSEC_FEATURES \
9dd5b58
-	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
9dd5b58
+	(NETIF_F_SG | NETIF_F_HIGHDMA)
9dd5b58
 static struct lock_class_key macsec_netdev_addr_lock_key;
9dd5b58
 
9dd5b58
 static int macsec_dev_init(struct net_device *dev)
9dd5b58
-- 
9dd5b58
cgit v1.1
9dd5b58