From c5ae2f746c1ba42f9c84fa02442434e83a7c1df5 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 1 Aug 2015 08:39:30 -0400 Subject: [PATCH 4/7] rtl8139: check IP Header Length field (CVE-2015-5165) RH-Author: Stefan Hajnoczi Message-id: <1438418373-7324-5-git-send-email-stefanha@redhat.com> Patchwork-id: 67261 O-Subject: [virt-devel] [RHEL-6.7.z qemu-kvm EMBARGOED PATCH 4/7] rtl8139: check IP Header Length field (CVE-2015-5165) Bugzilla: 1248761 RH-Acked-by: Dr. David Alan Gilbert RH-Acked-by: Xiao Wang RH-Acked-by: Laszlo Ersek The IP Header Length field was only checked in the IP checksum case, but is used in other cases too. Signed-off-by: Stefan Hajnoczi Signed-off-by: Jeff E. Nelson --- hw/rtl8139.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/hw/rtl8139.c b/hw/rtl8139.c index f4a983b..e3f0d3c 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -2180,6 +2180,10 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) } hlen = IP_HEADER_LENGTH(ip); + if (hlen < sizeof(ip_header) || hlen > eth_payload_len) { + goto skip_offload; + } + ip_protocol = ip->ip_p; ip_data_len = be16_to_cpu(ip->ip_len) - hlen; @@ -2187,16 +2191,9 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) { DEBUG_PRINT(("RTL8139: +++ C+ mode need IP checksum\n")); - if (hleneth_payload_len) {/* min header length */ - /* bad packet header len */ - /* or packet too short */ - } - else - { - ip->ip_sum = 0; - ip->ip_sum = ip_checksum(ip, hlen); - DEBUG_PRINT(("RTL8139: +++ C+ mode IP header len=%d checksum=%04x\n", hlen, ip->ip_sum)); - } + ip->ip_sum = 0; + ip->ip_sum = ip_checksum(ip, hlen); + DEBUG_PRINT(("RTL8139: +++ C+ mode IP header len=%d checksum=%04x\n", hlen, ip->ip_sum)); } if ((txdw0 & CP_TX_LGSEN) && ip_protocol == IP_PROTO_TCP) -- 2.1.0