From nobody Thu May 2 12:37:25 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518203516936880.1555332491519; Fri, 9 Feb 2018 11:11:56 -0800 (PST) Received: from localhost ([::1]:58273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekE5S-0000mw-3t for importer@patchew.org; Fri, 09 Feb 2018 14:11:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekDxs-0003Js-6e for qemu-devel@nongnu.org; Fri, 09 Feb 2018 14:04:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekDxp-0005j5-1x for qemu-devel@nongnu.org; Fri, 09 Feb 2018 14:04:04 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56060 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekDxo-0005ij-Tr for qemu-devel@nongnu.org; Fri, 09 Feb 2018 14:04:00 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CFE940FB630; Fri, 9 Feb 2018 19:03:50 +0000 (UTC) Received: from localhost (ovpn-112-62.ams2.redhat.com [10.36.112.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04BDC100F9E9; Fri, 9 Feb 2018 19:03:43 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 20:03:40 +0100 Message-Id: <20180209190340.19516-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 19:03:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 09 Feb 2018 19:03:50 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] net: fix misaligned member access 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Jason Wang , Dmitry Fleytman Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Fixes the following ASAN warnings: /home/elmarco/src/qemu/hw/net/net_tx_pkt.c:201:27: runtime error: member ac= cess within misaligned address 0x631000028846 for type 'struct ip_header', = which requires 4 byte alignment 0x631000028846: note: pointer points here 01 00 00 00 45 00 01 a9 01 00 00 00 40 11 78 45 00 00 00 00 ff ff ff ff= 00 00 00 00 00 00 00 00 ^ /home/elmarco/src/qemu/hw/net/net_tx_pkt.c:208:63: runtime error: member ac= cess within misaligned address 0x631000028846 for type 'struct ip_header', = which requires 4 byte alignment 0x631000028846: note: pointer points here 01 00 00 00 45 00 01 a9 01 00 00 00 40 11 78 45 00 00 00 00 ff ff ff ff= 00 00 00 00 00 00 00 00 ^ /home/elmarco/src/qemu/hw/net/net_tx_pkt.c:210:13: runtime error: member ac= cess within misaligned address 0x631000028846 for type 'struct ip_header', = which requires 4 byte alignment 0x631000028846: note: pointer points here 01 00 00 00 45 00 01 a9 01 00 00 00 40 11 78 45 00 00 00 00 ff ff ff ff= 00 00 00 00 00 00 00 00 Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Peter Maydell --- include/net/eth.h | 4 +++- hw/net/net_tx_pkt.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/net/eth.h b/include/net/eth.h index 09054a506d..e6dc8a7ba0 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -194,7 +194,9 @@ struct tcp_hdr { #define PKT_GET_IP_HDR(p) \ ((struct ip_header *)(((uint8_t *)(p)) + eth_get_l2_hdr_length(p))) #define IP_HDR_GET_LEN(p) \ - ((((struct ip_header *)(p))->ip_ver_len & 0x0F) << 2) + ((ldub_p(p + offsetof(struct ip_header, ip_ver_len)) & 0x0F) << 2) +#define IP_HDR_GET_P(p) \ + (ldub_p(p + offsetof(struct ip_header, ip_p))) #define PKT_GET_IP_HDR_LEN(p) \ (IP_HDR_GET_LEN(PKT_GET_IP_HDR(p))) #define PKT_GET_IP6_HDR(p) \ diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index e29c881bc2..162f802dd7 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -205,7 +205,7 @@ static bool net_tx_pkt_parse_headers(struct NetTxPkt *p= kt) return false; } =20 - pkt->l4proto =3D ((struct ip_header *) l3_hdr->iov_base)->ip_p; + pkt->l4proto =3D IP_HDR_GET_P(l3_hdr->iov_base); =20 if (IP_HDR_GET_LEN(l3_hdr->iov_base) !=3D sizeof(struct ip_header)= ) { /* copy optional IPv4 header data if any*/ --=20 2.16.1.73.g5832b7e9f2