From nobody Sat Nov 23 17:05:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1731593841; cv=none; d=zohomail.com; s=zohoarc; b=QBnUTwPHjfBzSz+Sv+RNwiZveoGpVpsRaRSiBoE4ig1WJSSpQktgYLfhJRu2r/1dyeFQU6LSzWWkRIpK9UVSsn4ofoDY0q1gE/aFArYKSPN5+IiO1xjGKXXG87h7twgUGgV79XY3eurTrXa7Nm0zKdgx2kwfMamMb5jN9nWTXqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731593841; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BP3yRitiC3pe96tPWKI8bHmTbvYnrh2UEaDGL8a02GI=; b=ecepDB6SO6E/+Q1SDqHhKWGeqUXoQY3Ty/MnaojmlblLiHNR6Z6vO0xiAoHa4dtjD/fEnpOUZ6xPoR3dBzV3YS5vtaLRCcUmSBP0BpzH8PIIEH8KMDbfMLbABSJssq81b91aAeYKti+JtFyG7yM1SaJCpvGVCT6dxBSed6qseOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731593841347134.1412017879635; Thu, 14 Nov 2024 06:17:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBae3-0000fc-2m; Thu, 14 Nov 2024 09:16:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBae1-0000fJ-Qz for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:25 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBadz-0005hA-Qf for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:25 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43162cf1eaaso8193665e9.0 for ; Thu, 14 Nov 2024 06:16:22 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da244915sm24941655e9.3.2024.11.14.06.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:16:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731593782; x=1732198582; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BP3yRitiC3pe96tPWKI8bHmTbvYnrh2UEaDGL8a02GI=; b=VnHl4LVZtFWDZOgvoW+E7KErD8Yb2zwFskDPSsA43qAwhp1LDzyXx+aJSiZ4enhy3N drY2YpB8hX9fe0WwM7lMEW5faRCuTNs5zzoTNEJl97o37alsyhLKPWN08ad987zRbnu7 qQKDZlsk2dzgSvDqd7NdPkHol3kaMVQ//i3ykUPy4vPnPqybc4xsJs5XwfBOe1xtccUY QKFRNlkB08wyWuFVgw84PYfEhVHypl7autdnQeGxF8lkSwkiMTEn9zfAdkPTUwSSMmSv slClb/UHpc69teMAycXVYXiFnbyqJuk0QLFfszrPRTp7puOqYZCw2Z0T5LnM4ZKQ/W8N MX6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731593782; x=1732198582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BP3yRitiC3pe96tPWKI8bHmTbvYnrh2UEaDGL8a02GI=; b=KT6AmNsk0iD7SAltRLhjVlY9gWQv+6pw2CdC5U+o+xJlGzFFM2nDybSG3C4Yxki9FD YPBve8DQ+8ZYMEGPLf71UP2y++Dj45uCMOKfeCr53Fl0zKZrY6MvArVlu40NPi7+OBVa rQItP92V6mAuhWLbcu0gKup1/2/pnfgWqOHxi1DLtidjBNgWqSjx4Ccb/J4Wzwzgqy/7 UBwMHLIav39XJ1bwbBSwNb8fRQ3HHnUso2bvl/pjyIDAAPgbfXiRE8RrKKhpsuPt1Oih ZOkesP8ygXPHjEn2nXAV/Xkxi+NkXPoFsEdjE0FxbzamedMgj3vKqgMf2YnZ0Fhz1eG+ Z3LA== X-Gm-Message-State: AOJu0Yxl0OGg16ZBBSmEwTr52ImwGhJBAVKZKIX4gi6P7FyUTqv3SM5o EIUh85pO3H5nQtSxZTtVWpF5d7zjs4BBi78kRUS9HMpl0E9+wlRc7LzRoikKbLGvXHoUIq8DV1H x X-Google-Smtp-Source: AGHT+IHKFGmv3tKZkRgxO6hUXQBd6EUtrwYraHwVPQWZDQJlFxsBtOvmdiHPhS3YOX1unJUKadz4Jg== X-Received: by 2002:a05:600c:1f89:b0:42c:bae0:f05f with SMTP id 5b1f17b1804b1-432da77eee9mr26182455e9.13.1731593781807; Thu, 14 Nov 2024 06:16:21 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Yuri Benditovich Subject: [PATCH v2 1/2] hw/net/virtio-net.c: Don't assume IP length field is aligned Date: Thu, 14 Nov 2024 14:16:18 +0000 Message-Id: <20241114141619.806652-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114141619.806652-1-peter.maydell@linaro.org> References: <20241114141619.806652-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1731593842963116600 Content-Type: text/plain; charset="utf-8" In virtio-net.c we assume that the IP length field in the packet is aligned, and we copy its address into a uint16_t* in the VirtioNetRscUnit struct which we then dereference later. This isn't a safe assumption; it will also result in compilation failures if we mark the ip_header struct as QEMU_PACKED because the compiler will not let you take the address of an unaligned struct field. Make the ip_plen field in VirtioNetRscUnit a void*, and make all the places where we read or write through that pointer instead use some new accessor functions read_unit_ip_len() and write_unit_ip_len() which account for the pointer being potentially unaligned and also do the network-byte-order conversion we were previously using htons() to perform. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/virtio/virtio-net.h | 2 +- hw/net/virtio-net.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 060c23c04d2..b9ea9e824e3 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -102,7 +102,7 @@ typedef struct VirtioNetRscStat { /* Rsc unit general info used to checking if can coalescing */ typedef struct VirtioNetRscUnit { void *ip; /* ip header */ - uint16_t *ip_plen; /* data len pointer in ip header field */ + void *ip_plen; /* pointer to unaligned uint16_t data len in ip header = */ struct tcp_header *tcp; /* tcp header */ uint16_t tcp_hdrlen; /* tcp header len */ uint16_t payload; /* pure payload without virtio/eth/ip/tcp */ diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f2104ed364a..75b4a28fb3a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2049,6 +2049,21 @@ static ssize_t virtio_net_do_receive(NetClientState = *nc, const uint8_t *buf, return virtio_net_receive_rcu(nc, buf, size, false); } =20 +/* + * Accessors to read and write the IP packet data length field. This + * is a potentially unaligned network-byte-order 16 bit unsigned integer + * pointed to by unit->ip_len. + */ +static uint16_t read_unit_ip_len(VirtioNetRscUnit *unit) +{ + return lduw_be_p(unit->ip_plen); +} + +static void write_unit_ip_len(VirtioNetRscUnit *unit, uint16_t l) +{ + stw_be_p(unit->ip_plen, l); +} + static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, const uint8_t *buf, VirtioNetRscUnit *unit) @@ -2063,7 +2078,7 @@ static void virtio_net_rsc_extract_unit4(VirtioNetRsc= Chain *chain, unit->ip_plen =3D &ip->ip_len; unit->tcp =3D (struct tcp_header *)(((uint8_t *)unit->ip) + ip_hdrlen); unit->tcp_hdrlen =3D (htons(unit->tcp->th_offset_flags) & 0xF000) >> 1= 0; - unit->payload =3D htons(*unit->ip_plen) - ip_hdrlen - unit->tcp_hdrlen; + unit->payload =3D read_unit_ip_len(unit) - ip_hdrlen - unit->tcp_hdrle= n; } =20 static void virtio_net_rsc_extract_unit6(VirtioNetRscChain *chain, @@ -2082,7 +2097,7 @@ static void virtio_net_rsc_extract_unit6(VirtioNetRsc= Chain *chain, =20 /* There is a difference between payload length in ipv4 and v6, ip header is excluded in ipv6 */ - unit->payload =3D htons(*unit->ip_plen) - unit->tcp_hdrlen; + unit->payload =3D read_unit_ip_len(unit) - unit->tcp_hdrlen; } =20 static size_t virtio_net_rsc_drain_seg(VirtioNetRscChain *chain, @@ -2231,7 +2246,7 @@ static int32_t virtio_net_rsc_coalesce_data(VirtioNet= RscChain *chain, VirtioNetRscUnit *o_unit; =20 o_unit =3D &seg->unit; - o_ip_len =3D htons(*o_unit->ip_plen); + o_ip_len =3D read_unit_ip_len(o_unit); nseq =3D htonl(n_unit->tcp->th_seq); oseq =3D htonl(o_unit->tcp->th_seq); =20 @@ -2267,7 +2282,7 @@ coalesce: o_unit->payload +=3D n_unit->payload; /* update new data len */ =20 /* update field in ip header */ - *o_unit->ip_plen =3D htons(o_ip_len + n_unit->payload); + write_unit_ip_len(o_unit, o_ip_len + n_unit->payload); =20 /* Bring 'PUSH' big, the whql test guide says 'PUSH' can be coales= ced for windows guest, while this may change the behavior for linux --=20 2.34.1 From nobody Sat Nov 23 17:05:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1731593841; cv=none; d=zohomail.com; s=zohoarc; b=Q+H2QGkfp4l/q+SgsK3bsmy8bvplKW3mAXp/tHxcLfK8WK9jlgV0iO8S8u6c37NRnau32CnvlKRwWPywLKjNg2HPOX6vfSLJ1nOPY4aPTU7oF5GShqeAzBL5lx+8f7km6/3pfLf3At1gTfRfA+oBiVDkuXkXYBTMtsN3lRKegiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731593841; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3cl4ZO8ew2BAiajP9BAvW5+7ZXDojU8B2khh55fONv8=; b=WtMevNEYRHEcR/JgO3Mr/Nqq+mrQCMwLis5YhUGJRWBqPjKDZ6x+8Ntd0AZpJ/H6Q8DxcEdbb1LAg2d18Uz7yG721YkXk6Hm3KJnAYrt+VnbnjBNBWNYe71MwQmfrIL0Xdh8GtNPcm2KZ3BhvRgMO0zWSAmi6Ha6uvOquM0n4Ss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731593841351297.51797650958724; Thu, 14 Nov 2024 06:17:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBae5-0000gQ-Ho; Thu, 14 Nov 2024 09:16:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBae2-0000fY-OF for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:26 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBae0-0005hS-HS for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:26 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-431ac30d379so6201885e9.1 for ; Thu, 14 Nov 2024 06:16:23 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432da244915sm24941655e9.3.2024.11.14.06.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:16:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731593782; x=1732198582; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3cl4ZO8ew2BAiajP9BAvW5+7ZXDojU8B2khh55fONv8=; b=lY4oVxKQQPKtfjWHd4ITfc66T4qH8fKdEFfYCrHoIcOetEPWg3vwc6X0AG/ZyJPHCg a2+C91b5iCoWXskYGAHYhM9RdBhht2KVbh9BSleuF9+cdgforsDSQnOBGD1v81zwgN28 FxlcMr1H3Gg52WCXuu/HCGYDIWV7uvCizAX7LbSxhHTLflnPm1OPRWLEfJuGefZYA3AX OexDWzUmfavQ/1SEs/1GWE7l5rQLi7dSWC+8vXX6qxJzgvpYVc/OZdGV3+uxqVaLqcqU KQxyQqks7Kjw6FrPJo85kvrbjWa2omFGv7BeAu7+7rNJP4YcS8BWTkaNg+h/DwIZbWnR k6RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731593782; x=1732198582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3cl4ZO8ew2BAiajP9BAvW5+7ZXDojU8B2khh55fONv8=; b=oo0lO9FJu0iftJPj+SQZudCjGeWBhsblqi56K+C23q8iP3Gyy/whITKvm6Woj156nO 9nma0bWR+DfG7JU8OEGuFl/RcoWmLI4JHtPm1rJSTwjkVhry6UX0l9oqtczRuyNHXoZK mY0r2OmZoGUdai8spN248BMDQYaBMEHJNE4ubY98c4OiExS+rMCdf8Qwr1vGjFll9Gx+ Bkupk37tLUAq2mbUvpsSJWfgRKyZ+kf0zVL/6kLZr8Mni+eA0fJMctW3UUjFmI0qX5bh 7K13D/p2loXbG6Gsq93pPHbSBzRe+UKIne+kdqIgbW5n9joX79x/fBgcUVxXU7kDvIxG ivoQ== X-Gm-Message-State: AOJu0YxeanaQ0ZVZchYm0XvRSr+G6AcjfVBgz1As3/+FO8eMpwoOcLi2 xkQIzwbMKNNE8Cjhf5WngZog4rSZYnaCX8/BrqYoxkiNs7AGiBNOOhcRMZgZrFz0gzSWJtK3wbb U X-Google-Smtp-Source: AGHT+IG2wrca8tT5UP+FOUeYBpZwDEq02SsCuJUhW3cWRZ2h/jdFyAlv32bApVEqAxX+uBjLp1tySw== X-Received: by 2002:a05:600c:4f04:b0:42e:d4a2:ce67 with SMTP id 5b1f17b1804b1-432b7505d19mr234484085e9.17.1731593782490; Thu, 14 Nov 2024 06:16:22 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Yuri Benditovich Subject: [PATCH v2 2/2] net: mark struct ip_header as QEMU_PACKED Date: Thu, 14 Nov 2024 14:16:19 +0000 Message-Id: <20241114141619.806652-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241114141619.806652-1-peter.maydell@linaro.org> References: <20241114141619.806652-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1731593843013116600 Content-Type: text/plain; charset="utf-8" The ip_header is not actually guaranteed to be aligned. We attempt to deal with this in some places such as net_checksum_calculate() by using stw_be_p and so on to access the fields, but this is not sufficient to be correct, because even accessing a byte member within an unaligned struct is undefined behaviour. The clang sanitizer will emit warnings like these if net_checksum_calculate() is called: Stopping network: ../../net/checksum.c:106:9: runtime error: member ac= cess within misaligned address 0x556aad9b502e for type 'struct ip_header', = which requires 4 byte alignment 0x556aad9b502e: note: pointer points here 34 56 08 00 45 00 01 48 a5 09 40 00 40 11 7c 8b 0a 00 02 0f 0a 00 0= 2 02 00 44 00 43 01 34 19 56 ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../net/check= sum.c:106:9 in ../../net/checksum.c:106:9: runtime error: load of misaligned address 0= x556aad9b502e for type 'uint8_t' (aka 'unsigned char'), which requires 4 by= te alignment 0x556aad9b502e: note: pointer points here 34 56 08 00 45 00 01 48 a5 09 40 00 40 11 7c 8b 0a 00 02 0f 0a 00 0= 2 02 00 44 00 43 01 34 19 56 ^ Fix this by marking the ip_header struct as QEMU_PACKED, so that the compiler knows that it might be unaligned and will generate the right code for accessing fields. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/eth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/eth.h b/include/net/eth.h index 3b80b6e07f3..14c34f530fe 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -56,7 +56,7 @@ struct ip_header { uint8_t ip_p; /* protocol */ uint16_t ip_sum; /* checksum */ uint32_t ip_src, ip_dst; /* source and destination address */ -}; +} QEMU_PACKED; =20 typedef struct tcp_header { uint16_t th_sport; /* source port */ --=20 2.34.1