Skip to content

Commit 276f798

Browse files
Or Cohenanthraxx
Or Cohen
authored andcommitted
backport: net/packet: fix overflow in tpacket_rcv
Using tp_reserve to calculate netoff can overflow as tp_reserve is unsigned int and netoff is unsigned short. This may lead to macoff receving a smaller value then sizeof(struct virtio_net_hdr), and if po->has_vnet_hdr is set, an out-of-bounds write will occur when calling virtio_net_hdr_from_skb. The bug is fixed by converting netoff to unsigned int and checking if it exceeds USHRT_MAX. This addresses CVE-2020-14386 Fixes: 8913336 ("packet: add PACKET_RESERVE sockopt") Signed-off-by: Or Cohen <[email protected]> Signed-off-by: Eric Dumazet <[email protected]>
1 parent 9a6936a commit 276f798

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/packet/af_packet.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,8 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
21702170
int skb_len = skb->len;
21712171
unsigned int snaplen, res;
21722172
unsigned long status = TP_STATUS_USER;
2173-
unsigned short macoff, netoff, hdrlen;
2173+
unsigned short macoff, hdrlen;
2174+
unsigned int netoff;
21742175
struct sk_buff *copy_skb = NULL;
21752176
struct timespec64 ts;
21762177
__u32 ts_status;
@@ -2239,6 +2240,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
22392240
}
22402241
macoff = netoff - maclen;
22412242
}
2243+
if (netoff > USHRT_MAX) {
2244+
atomic_inc(&po->tp_drops);
2245+
goto drop_n_restore;
2246+
}
22422247
if (po->tp_version <= TPACKET_V2) {
22432248
if (macoff + snaplen > po->rx_ring.frame_size) {
22442249
if (po->copy_thresh &&

0 commit comments

Comments
 (0)