From nobody Sat May 4 19:52:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487248308656450.10352499700286; Thu, 16 Feb 2017 04:31:48 -0800 (PST) Received: from localhost ([::1]:46123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLDu-0003sE-60 for importer@patchew.org; Thu, 16 Feb 2017 07:31:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLCB-00030O-Qo for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceLCA-0007pU-QG for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:29:59 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceLCA-0007pI-J7 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:29:58 -0500 Received: by mail-wm0-x241.google.com with SMTP id v77so2902748wmv.0 for ; Thu, 16 Feb 2017 04:29:58 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id b51sm8827365wrd.39.2017.02.16.04.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 04:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8GnPpQyQatfZ6HZ5l4lUJOSaR/QPPqTAJjw7ByqtXSA=; b=hNsD2mYdimmKMjAoESow7+42wrgx0Y3WVQCYpOkCkHol33x4LcUGTZPWJ32XrO8mZU /UYD2p67rYcw8tzsAflVUjHhKT3M4vkdc132CaJu2ajyTJN0M67a4n3evRNfch7++h/1 AQdxZ9g6myv1pvWBFjnKbAXtBIkiQhFOgAscIza8jTiy2hYVeEZsSjSAf9CXOM2glWIb O71P0RzqL1imJcmeGuG/UEHQQYLsjrkdbCMjpAHRZkcqAriwZTJdshi8xOTZPmZW+ySE 2fAICSGmrgFMEYrx4SAW/KOiiG7gK/Snbn+dsPmhU2i0QqC0movepRMxtDgITtKFPmK1 6TIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8GnPpQyQatfZ6HZ5l4lUJOSaR/QPPqTAJjw7ByqtXSA=; b=OjnHlwtdajhWwbI1qOBsBRtDwniHcQyT4HhpOTLsAO5LO6KIUSyd0GUUiIBnlILwue BeXzQ76goMoOCQMnKXqBtRaBTsnypfcq2spPFN9/oytwQWiniyTTktE1oXzNQkV0HdIY k6St+oHynS3Al0NSjzf8iYT+J/fO91MEoncArviwzu2MLSXXf09T05ZgHLReW5HMcUdD biutc7EwueRxi7Za5SHD+dJJ8eaU/2xT0jNIKjfUk4TqnAYqDp6Rbl5pWmQWp+71nWW2 b56tgHSBmvKryv4I+iPM/U8nQYPboWlWSZObSLVjp7HmfHLdHqhXdUXsrJN65e+MijRh VmMA== X-Gm-Message-State: AMke39kndvWT1hZ6h4t6rcjw3umyEYO5ZHWkl+iipIcBb92hMgtJrgYSNDsg27Od/Rs+Vg== X-Received: by 10.28.203.6 with SMTP id b6mr11958607wmg.2.1487248197592; Thu, 16 Feb 2017 04:29:57 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 14:29:32 +0200 Message-Id: <1487248176-29602-2-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487248176-29602-1-git-send-email-dmitry@daynix.com> References: <1487248176-29602-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 1/5] eth: Extend vlan stripping functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Dmitry Fleytman , Jason Wang , P J P Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make VLAN stripping functions return number of bytes copied to given Ethernet header buffer. This information should be used to re-compose packet IOV after VLAN stripping. Signed-off-by: Dmitry Fleytman Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/eth.h | 4 ++-- net/eth.c | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/net/eth.h b/include/net/eth.h index 2013175..afeb45b 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -331,12 +331,12 @@ eth_get_pkt_tci(const void *p) } } =20 -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); =20 -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); diff --git a/net/eth.c b/net/eth.c index df81efb..5b9ba26 100644 --- a/net/eth.c +++ b/net/eth.c @@ -232,7 +232,7 @@ void eth_get_protocols(const struct iovec *iov, int iov= cnt, } } =20 -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -244,7 +244,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, siz= e_t iovoff, new_ehdr, sizeof(*new_ehdr)); =20 if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } =20 switch (be16_to_cpu(new_ehdr->h_proto)) { @@ -254,7 +254,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, siz= e_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 new_ehdr->h_proto =3D vlan_hdr.h_proto; @@ -268,18 +268,21 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, s= ize_t iovoff, PKT_GET_VLAN_HDR(new_ehdr), sizeof(vlan_hd= r)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 *payload_offset +=3D sizeof(vlan_hdr); + + return sizeof(struct eth_header) + sizeof(struct vlan_header); + } else { + return sizeof(struct eth_header); } - return true; default: - return false; + return 0; } } =20 -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -291,7 +294,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, new_ehdr, sizeof(*new_ehdr)); =20 if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } =20 if (be16_to_cpu(new_ehdr->h_proto) =3D=3D vet) { @@ -299,17 +302,17 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt= , size_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 new_ehdr->h_proto =3D vlan_hdr.h_proto; =20 *tci =3D be16_to_cpu(vlan_hdr.h_tci); *payload_offset =3D iovoff + sizeof(*new_ehdr) + sizeof(vlan_hdr); - return true; + return sizeof(struct eth_header); } =20 - return false; + return 0; } =20 void --=20 2.7.4 From nobody Sat May 4 19:52:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487248563254966.6415854434844; Thu, 16 Feb 2017 04:36:03 -0800 (PST) Received: from localhost ([::1]:46147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLI0-0008Bx-Un for importer@patchew.org; Thu, 16 Feb 2017 07:36:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLCN-0003BM-Il for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceLCK-0007uM-Fc for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:11 -0500 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:32792) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceLCK-0007td-9s for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:08 -0500 Received: by mail-wr0-x244.google.com with SMTP id i10so1881442wrb.0 for ; Thu, 16 Feb 2017 04:30:08 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id b51sm8827365wrd.39.2017.02.16.04.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 04:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RsxC5F76me4wK5EDizeUV3Sjei4uNLSQWKP08LxgAWs=; b=xiO2ISr/v1/8XHsS7GuI0QQaDD7jCervefioqh15b0+1PcbigXWTVB1Fukt7xGjBIf 4Ld0GDsAylJGQX7yG2L8CDezmqesKVr9/45tEEFUy8Bcli5GPuez/3iHV6bhGEPuKYFK H+QFnxuqxz7fU7wsmKf/r+uJtsxroDfpsVJbrWRtaC0t6pvWx5RcMM6Qv+yEg4LKKdDZ vAFxOyURhJRgkPZ/k57XBFaHaNzIY6ktiypt3DfrINUIj7TxTmwhMI2z8zBdviVLVlqD BuIBkU6p7oSuVMTZQLr+DxHmbxODC9hxey6D2GTCaHLsMtn9Fcjm/XyY/ronhJ78Fd0w Z+hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RsxC5F76me4wK5EDizeUV3Sjei4uNLSQWKP08LxgAWs=; b=mzhVV8ErYIa+rqaUCrQY/ZvmNr0n4zE69HWHmnKvG35U2w5iE1PzKluvq00bgV40dG 9pkkW7OpNsa1HRHKotMMOAjBqe+/zq1UPSs7ZycWmL8JloYohm8B5665DKiajhZocj0g 9toN5sBdneyO7i5JwaFyV8WsTcWxJc06IYQeb6BrymKTLApePyWdEIlQW4oxOcXFWfzy oZoLreQaqqTJeYy3cLDze+F8hOF+9uNuvsofgkLQ5k62kQD7sVMsqhoykarMsAhd0Swz CJAfY2kD9h9R+h+sK3pBGuxOMAz5X4jkZR8T7C95a3npDRAHR4BBp/fkjsc7R1iRvV/F NFbA== X-Gm-Message-State: AMke39loMNZMaVfYg9ygPyYocN07M11st9JmDMlPTLlbjjSPHhRDAaKGiCFdCRS+dMiRQQ== X-Received: by 10.223.133.68 with SMTP id 62mr2049345wrh.195.1487248207243; Thu, 16 Feb 2017 04:30:07 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 14:29:33 +0200 Message-Id: <1487248176-29602-3-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487248176-29602-1-git-send-email-dmitry@daynix.com> References: <1487248176-29602-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PATCH 2/5] NetRxPkt: Fix memory corruption on VLAN header stripping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Dmitry Fleytman , Jason Wang , P J P Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch fixed a problem that was introduced in commit eb700029. When net_rx_pkt_attach_iovec() calls eth_strip_vlan() this can result in pkt->ehdr_buf being overflowed, because ehdr_buf is only sizeof(struct eth_header) bytes large but eth_strip_vlan() can write sizeof(struct eth_header) + sizeof(struct vlan_header) bytes into it. Devices affected by this problem: vmxnet3. Reported-by: Peter Maydell Signed-off-by: Dmitry Fleytman --- hw/net/net_rx_pkt.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 1019b50..7c0beac 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -23,13 +23,13 @@ =20 struct NetRxPkt { struct virtio_net_hdr virt_hdr; - uint8_t ehdr_buf[sizeof(struct eth_header)]; + uint8_t ehdr_buf[sizeof(struct eth_header) + sizeof(struct vlan_header= )]; struct iovec *vec; uint16_t vec_len_total; uint16_t vec_len; uint32_t tot_len; uint16_t tci; - bool vlan_stripped; + size_t ehdr_buf_len; bool has_virt_hdr; eth_pkt_types_e packet_type; =20 @@ -88,15 +88,13 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, const struct iovec *iov, int iovcnt, size_t ploff) { - if (pkt->vlan_stripped) { + if (pkt->ehdr_buf_len) { net_rx_pkt_iovec_realloc(pkt, iovcnt + 1); =20 pkt->vec[0].iov_base =3D pkt->ehdr_buf; - pkt->vec[0].iov_len =3D sizeof(pkt->ehdr_buf); - - pkt->tot_len =3D - iov_size(iov, iovcnt) - ploff + sizeof(struct eth_header); + pkt->vec[0].iov_len =3D pkt->ehdr_buf_len; =20 + pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, iov, iovcnt, ploff, pkt->tot_len); } else { @@ -123,11 +121,12 @@ void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt, uint16_t tci =3D 0; uint16_t ploff =3D iovoff; assert(pkt); - pkt->vlan_stripped =3D false; =20 if (strip_vlan) { - pkt->vlan_stripped =3D eth_strip_vlan(iov, iovcnt, iovoff, pkt->eh= dr_buf, - &ploff, &tci); + pkt->ehdr_buf_len =3D eth_strip_vlan(iov, iovcnt, iovoff, pkt->ehd= r_buf, + &ploff, &tci); + } else { + pkt->ehdr_buf_len =3D 0; } =20 pkt->tci =3D tci; @@ -143,12 +142,13 @@ void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt, uint16_t tci =3D 0; uint16_t ploff =3D iovoff; assert(pkt); - pkt->vlan_stripped =3D false; =20 if (strip_vlan) { - pkt->vlan_stripped =3D eth_strip_vlan_ex(iov, iovcnt, iovoff, vet, - pkt->ehdr_buf, - &ploff, &tci); + pkt->ehdr_buf_len =3D eth_strip_vlan_ex(iov, iovcnt, iovoff, vet, + pkt->ehdr_buf, + &ploff, &tci); + } else { + pkt->ehdr_buf_len =3D 0; } =20 pkt->tci =3D tci; @@ -162,8 +162,8 @@ void net_rx_pkt_dump(struct NetRxPkt *pkt) NetRxPkt *pkt =3D (NetRxPkt *)pkt; assert(pkt); =20 - printf("RX PKT: tot_len: %d, vlan_stripped: %d, vlan_tag: %d\n", - pkt->tot_len, pkt->vlan_stripped, pkt->tci); + printf("RX PKT: tot_len: %d, ehdr_buf_len: %lu, vlan_tag: %d\n", + pkt->tot_len, pkt->ehdr_buf_len, pkt->tci); #endif } =20 @@ -426,7 +426,7 @@ bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt) { assert(pkt); =20 - return pkt->vlan_stripped; + return pkt->ehdr_buf_len ? true : false; } =20 bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt) --=20 2.7.4 From nobody Sat May 4 19:52:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487248345021741.6340372936139; Thu, 16 Feb 2017 04:32:25 -0800 (PST) Received: from localhost ([::1]:46124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLES-0004OO-MI for importer@patchew.org; Thu, 16 Feb 2017 07:32:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLCT-0003HN-9t for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceLCS-0007zO-Dt for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:17 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36835) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceLCS-0007z2-83 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:16 -0500 Received: by mail-wm0-x244.google.com with SMTP id r18so2881866wmd.3 for ; Thu, 16 Feb 2017 04:30:16 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id b51sm8827365wrd.39.2017.02.16.04.30.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 04:30:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tCZlilqh0GHaCg1XzpaecgYCYXUx95QpqUZMrujLl9A=; b=O+dp+RzTsViPh7w2u482gewmHGDb3J/drFXaavCeeYxQF1AA1oZh0OFqQEbwrlittd 3pBiDF5Jj9JoCa8n4C7yZ3NNNJOxCVVf4lkCxI32vXuPnr6FrGy3qr9hRjN/DSObiJCN 6HWx5TrBQuAdAsZfrBUx6CfjUnHRntRB6zJre9HZH0dMGBuP5N8KvL+QszxPz9aO99B0 pzc64UBGkU+3YbZFAjioL8uNO9bFnzMLlmSAU0r5JMWFCTdv80XtFqyfn8tGSPXVu179 v9MzubIHfjFZgsbDcqPabnMnYu80BkEXuh7cZqnYwaxkP3soJ+aEmZv6udahidvIj6iG mhqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tCZlilqh0GHaCg1XzpaecgYCYXUx95QpqUZMrujLl9A=; b=YW710u3+gFN4noWyBWgE/T0AG/EwjpywSXzi9p6VrByc6aRf7px8DkofnFd553eGcZ ZMpiv99kyELKOOHgAFEuXMtTciv7SSXw6ezD36FlbLuYLj7MSbrPxQKaoSLYPNrWKSCY IGwCir8sfmWpsVbIgKc20vIDQ1QxBZ7W0p3FcL5dHyFcYWRSS+P1TWLiavyc0BlWE3ms 2bQbQYp6J1HeUjuDX3j04qZtcLxV7bwSmgk8lZXGoyw1FeJM47SFApHyy3S/pGfSYJWi Bi3Zx4P3QnQAuvccgdyL/tkh4gH0K230XQ8z54Kit22LZYKC8qgOpTHlKLWGupZLQI4N KZzg== X-Gm-Message-State: AMke39leKjFX9EiX1KoIK+ZKPvkKUkzW76vyIVpUvREtFsbeoAZsmih8iYk4mxp+16NMMQ== X-Received: by 10.28.209.7 with SMTP id i7mr11808318wmg.115.1487248215215; Thu, 16 Feb 2017 04:30:15 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 14:29:34 +0200 Message-Id: <1487248176-29602-4-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487248176-29602-1-git-send-email-dmitry@daynix.com> References: <1487248176-29602-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH 3/5] NetRxPkt: Do not try to pull more data than present X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Dmitry Fleytman , Jason Wang , P J P Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In case of VLAN stripping, ETH header put into a separate buffer, therefore amont of data copied from original IOV should be smaller. Signed-off-by: Dmitry Fleytman Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/net_rx_pkt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 7c0beac..d38babe 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -96,7 +96,8 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, =20 pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, - iov, iovcnt, ploff, pkt->tot_len); + iov, iovcnt, ploff, + pkt->tot_len - pkt->ehdr_buf_len); } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 --=20 2.7.4 From nobody Sat May 4 19:52:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487248384109751.3011584991032; Thu, 16 Feb 2017 04:33:04 -0800 (PST) Received: from localhost ([::1]:46126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLF6-0005by-LG for importer@patchew.org; Thu, 16 Feb 2017 07:33:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLCz-0003gZ-J1 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceLCw-00087C-FS for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:49 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34561) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceLCw-00086u-5E for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:46 -0500 Received: by mail-wm0-x241.google.com with SMTP id c85so2903898wmi.1 for ; Thu, 16 Feb 2017 04:30:46 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id b51sm8827365wrd.39.2017.02.16.04.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 04:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NoWow3BvTiyTYA7PFStHxrLDWH5TGgkUiy92tWtujkU=; b=fjLF7U6G+VpL5mvGgljCz1IlFAL630FTKFUPc9vNemAwIVc2wzsH0WFjBlIrwAMrTn RP00oY3IdsDmhyC22AUxeo0yC2V8bKw5Y2ZJ8ZkhFB5YvyvZrwIph8XwTqYS1rfIrwyp imZS1jJx4qS4GvKCdkhUnFNs/TwpWSnZ6FyFbIJq3t638pUuF5oA1fhgzapVw5/5GLb+ 98A3CjQS5sF44vfw9Q95kVTRrpMfJBabshWeYFGfCqOUREszM6NTs1j2IBGFUEg+Jf/z K9JnGMzUMoXDS5t5aUP5dx3qU+4oZTpycJj4VxiCvQ8xz6gBwKbeVCHPCpiIVanaRY4U Fu6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NoWow3BvTiyTYA7PFStHxrLDWH5TGgkUiy92tWtujkU=; b=Bn593alnf9zALuD02toEfpDXH2i6RfuvuQRU1Lf7Igfsq8x2T68VOAwI5a/EqH17x3 1GXJDmkrbVAxNWloJKCVH9IEv56sDfikZFbyQq+FWvd6IYYkf4fE/HGUxsYiN/PDJ4ru mrMAZBRGkZpOQ1JqToD5c71qvybM9JaqTpy7DQtrSOtLYgviStuk7YaQh00cdJuJ/OGa vWlkc6ELqpYtToha93pAodSOMpgVN3BNvR5PoS1ohrNEUbATDvBv1+4AAdnuIzYEu9uN yS8AehS2CYz52TlSKKNKhndXNNlPl3k5FVfi05maZao8w+N+gXrMcydOQ+VQjc7jbd0a 2fiw== X-Gm-Message-State: AMke39n2Q3qjBDfL/N+KhtmuMzBozCLGrCtdDJRORosQUxfIj7qva63pIIfhq3EpI72iBw== X-Received: by 10.28.230.91 with SMTP id d88mr12008752wmh.129.1487248245237; Thu, 16 Feb 2017 04:30:45 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 14:29:35 +0200 Message-Id: <1487248176-29602-5-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487248176-29602-1-git-send-email-dmitry@daynix.com> References: <1487248176-29602-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 4/5] NetRxPkt: Account buffer with ETH header in IOV length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Dmitry Fleytman , Jason Wang , P J P Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In case of VLAN stripping ETH header is stored in a separate chunk and length of IOV should take this into account. This patch fixes checksum validation for RX packets with VLAN header. Devices affected by this problem: e1000e and vmxnet3. Signed-off-by: Dmitry Fleytman --- hw/net/net_rx_pkt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index d38babe..c7ae33d 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -97,7 +97,7 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, iov, iovcnt, ploff, - pkt->tot_len - pkt->ehdr_buf_len); + pkt->tot_len - pkt->ehdr_buf_len) + 1; } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 --=20 2.7.4 From nobody Sat May 4 19:52:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487248881930267.5899984648846; Thu, 16 Feb 2017 04:41:21 -0800 (PST) Received: from localhost ([::1]:46173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLNA-0005Ay-Jz for importer@patchew.org; Thu, 16 Feb 2017 07:41:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceLD1-0003hu-EE for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceLD0-00088X-Hk for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:51 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:34015) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceLD0-00088F-B2 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 07:30:50 -0500 Received: by mail-wr0-x241.google.com with SMTP id c4so1878589wrd.1 for ; Thu, 16 Feb 2017 04:30:50 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id b51sm8827365wrd.39.2017.02.16.04.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 04:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xCR8+AVqlW+fXaY/4OUYVvWyf9jLhpZuxpcZcqtYiIA=; b=RRd/vrs2Kc7R00mMNLE1aeRR7/aa3ffAkZ+vJOEsvViNJFrmNCT+7wkA2f1j/RweSg NZ1WtwcxWjJVJwa5jEK/2JXG66g0fZzFwSdqb8XyT3OIEpG7kTgAmeEX6lP5HyIciWdw tgUFKqzzqksNguJhDTXwFXHrDlQf0BAulYqJm/Ta8oPycDgrbjlI1d4Y/QG4KYg3Rg5m N5rnjtIH4vfSYGNxmyKTyBfaXPb1ovDctXA5k0to7HHvb91m40OnBl4dPKEd1DIC1q0a TolQLPxKxzujWx0iuknaAQevzoGKjVEHXgOGepbriaOpji1tiTo9KYAstNuqXg2aBCfb eAUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xCR8+AVqlW+fXaY/4OUYVvWyf9jLhpZuxpcZcqtYiIA=; b=Xvru2zdatIcYIFfx2JPM1qbn/MCgmFc0GHsvk7r/0QxODdGIWpFl1SErEog3EwrT3Y BtENnMimBfFEQWOlkfC7LEqsuqc1cGbEnEtKnLKve1P1uvXSq0HFYsK9pP0euZHgY6Pu wCEk3h75s3/jPBufV6oaToEAv+3Svmm6lTmUfamNsNirjcyS6dxFTCOfTqMgg966Kz2l GUQ+rkip+n8N//5RJckGBEEfVm99K+IloDMdfCBqXX9pD8d5GnlW0DRyA3mXLfemsErT NwUlwanXIBxh+glXGIPIxzSWaUb4nwcl/1KNn+rn9mdtlUYVCTdPyTuFGnoLzYyd86Gs svoQ== X-Gm-Message-State: AMke39nW2pobDlksdFnUnX2hBxiqU0ZiyaztnSaKvSqdjI6ZIRwWtdq+pvaW+lQI4AUiwA== X-Received: by 10.223.163.136 with SMTP id l8mr2281983wrb.42.1487248249352; Thu, 16 Feb 2017 04:30:49 -0800 (PST) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 14:29:36 +0200 Message-Id: <1487248176-29602-6-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487248176-29602-1-git-send-email-dmitry@daynix.com> References: <1487248176-29602-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH 5/5] NetRxPkt: Remove code duplication in net_rx_pkt_pull_data() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Dmitry Fleytman , Jason Wang , P J P Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is a refactoring commit that does not change behavior. Signed-off-by: Dmitry Fleytman Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/net_rx_pkt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index c7ae33d..3899211 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -88,20 +88,21 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, const struct iovec *iov, int iovcnt, size_t ploff) { + uint32_t pllen =3D iov_size(iov, iovcnt) - ploff; + if (pkt->ehdr_buf_len) { net_rx_pkt_iovec_realloc(pkt, iovcnt + 1); =20 pkt->vec[0].iov_base =3D pkt->ehdr_buf; pkt->vec[0].iov_len =3D pkt->ehdr_buf_len; =20 - pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; + pkt->tot_len =3D pllen + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, - iov, iovcnt, ploff, - pkt->tot_len - pkt->ehdr_buf_len) + 1; + iov, iovcnt, ploff, pllen) + 1; } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 - pkt->tot_len =3D iov_size(iov, iovcnt) - ploff; + pkt->tot_len =3D pllen; pkt->vec_len =3D iov_copy(pkt->vec, pkt->vec_len_total, iov, iovcnt, ploff, pkt->tot_len); } --=20 2.7.4