From nobody Sun Apr 12 04:23:11 2026 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=1770905537; cv=none; d=zohomail.com; s=zohoarc; b=Du9sz49Zp3i673ZUxRDyZljn2Q/3lQoXByah3jZUCIeG33gTqo5P5XnVAveotDUbVlEOA0V8WDOyOwC50kD8azOJAYpc8OtZInzZ5VYLDS1rm0f4rkC3PI2Nl+3LkDxAuXnmNrb05trUzjQ+MS82AcnsZT/tT8c3UH7CNOES1J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770905537; 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=2/c4UhHWbCQRd4FJDg3uOEjFMuAnPkaZruMWzUtSXGU=; b=loS/vNMClMaLn+M3kMTWvG5DYaUlT+PMgfGWNLT2Ou/w+Ome1cEzLScMupbX9So15ryLgVQKedcHi21g/g/HIq6bFMRT0FDdxA2R7I1kkWQFoSu78DpZJBuyxv962Eur7avL5qVWxfWtzJB7tyFwP16yhMuiF5kIWsgdwDCr5Wg= 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 1770905537244118.61743525779605; Thu, 12 Feb 2026 06:12:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXNt-0000hD-Ni; Thu, 12 Feb 2026 09:09:33 -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 1vqXNm-0000fw-6S for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:27 -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 1vqXNj-0006Pt-BO for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:24 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso30010775e9.1 for ; Thu, 12 Feb 2026 06:09:22 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835dd0e327sm123266885e9.14.2026.02.12.06.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770905362; x=1771510162; 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=2/c4UhHWbCQRd4FJDg3uOEjFMuAnPkaZruMWzUtSXGU=; b=lMqRprPcCVcRvDP9x8ucLSh6a6213H1EpsQUCLiSyeWTcRPUR0Oem2aa6/WtdSLDgn BS55wmL6dOaN2Ugedc+XWcm6Vg29cG1kCBdO8gc0eKesAukPyhjKR0HnMVKShu8yc0V5 QxBYGrYKcJv/RpntPHy7kBq65y1lCKu0+Jndg0H08BQlryOoCkFM0FmdZL36IfBXL72X wfmy0qn14gMTrXrvoSYog7kFCnrW/znSSruoxB4N+BZqog93qS4i0fD4mnRCkcgEyq4h YDBBUU9jcMSTOYNWPU0fd9MlCLqVpcIJ8cJiV+gs6nlZn927lsWX+A85z5fQZXcCLEMD 2FEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770905362; x=1771510162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2/c4UhHWbCQRd4FJDg3uOEjFMuAnPkaZruMWzUtSXGU=; b=sUxIWbvlisolpmBgElGCenq5NUIFwUMTVFWuOS0S8DKkdOA9sk4OvtZ1NGJGT6oNd3 ZK8dBkAQXD6h2cRVnNHUEZLbymOZjzMn/RI4XJwK73mXCDIlBOSCpb/tFTb40l295+Ob /jrqRuhcjKLOxQTMm/+hJTkxnmGzN2Rtk/P2JCBuHfnAjTXHkJWTI3PSrOomm+ocXzz7 +g6/ODaScSawXMG+ogKy1ZPmlOfRuMg9thxx/kP7kjVTcNz0dVp4er2TUJ7/A370zADp HKSTgPeSvkNOOyOS1qQqIPObF6aebhvrKGj1PwW46ktjTEquo/XvTS+ejP5CowN5V5rz AYQw== X-Gm-Message-State: AOJu0YxgWHmlILo4/r8CLfeDU7yMvQSP6Y3Jf4WvRiSAN5pVK+W7+uIC LXwG4ZKZ6KeKPK+Vw+vqDgcfz4Lp5zgxPQ65q7G+zCtaMbb//KnfX0W61FC7Ij0jKjKqY98mPKm B5m5F X-Gm-Gg: AZuq6aJ6/Kpc3cq81wkALJa3LPxZhM2IkVFJLWl6T1q8mhq5Pq1VL9XYcxt7Lh2365A RgQCKnQrDljcyw8EXNKSH08t3gDFgLeuMr41oy53+hwO/HPMnssrNDNdQ+auog0NdxEYlz7DZfA 6RCWDuQZzQ6xBXdkXo3i+SU5qgGgI8jN1Jyqrd6vVjd595ZrdChGYbZ1hgzaQ7oV7umOOG2Wbd5 X9ZQnxD6VhaGrFV72+CzCxr+sfcN826Q1EZZdAS23L153OnVJLnn3nks8fcZVB5m2ODg9KUvswZ CFTdh6WP3csZtDKaL4YOzbpR0weiDX+2fJljr7hH3LGpwwNgb4sjraaoole/iMdYsklUWPTbqiM fX5ahbPzdKFMsuFQvuxsKSVtsgBvry8pEemeYIFjZusWgga8UHQePH2SP4AHEArBv1+XZfUlKkl /CttAsr2a92+E+r8W8EpQELyE/gHO8rJEdctrwOnSZUd+YaenR9eaDcKvbfQ841SZFxcZiUSbSK rg85Jy2IMXaRhDfnu4O4y7EP3IQ+2A= X-Received: by 2002:a05:600c:4f41:b0:483:6f7c:19f4 with SMTP id 5b1f17b1804b1-4836f7c1ab9mr7020955e9.30.1770905361788; Thu, 12 Feb 2026 06:09:21 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Patrick Venture Subject: [PATCH 1/5] hw/net/rocker: Don't keep pointer to h_proto as uint16_t* in OfDpaFlowPktFields Date: Thu, 12 Feb 2026 14:09:13 +0000 Message-ID: <20260212140917.1443253-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212140917.1443253-1-peter.maydell@linaro.org> References: <20260212140917.1443253-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: qemu development 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: 1770905538695158500 Content-Type: text/plain; charset="utf-8" In rocker_of_dpa.c we assume that the h_proto field in an eth_header struct is aligned, and we copy its address into a uint16_t* in the OfDpaFlowPktFields struct which we then dereference later. This isn't a safe assumption; it will also result in compilation failures with gcc if we mark the eth_header struct as QEMU_PACKED because gcc will not let you take the address of an unaligned struct field. Make the h_proto field in OfDpaFlowPktFields a void*, and make all the places where we previously read through that pointer instead use a new accessor function which allows for the possible lack of alignment. (Compare commit 5814c084679 "hw/net/virtio-net.c: Don't assume IP length field is aligned" which fixed a similar problem elsewhere for an ip_header field.) Signed-off-by: Peter Maydell Reviewed-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/rocker/rocker_of_dpa.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c index 16b9bc7a4b..814f19afc5 100644 --- a/hw/net/rocker/rocker_of_dpa.c +++ b/hw/net/rocker/rocker_of_dpa.c @@ -143,7 +143,7 @@ typedef struct of_dpa_flow { typedef struct of_dpa_flow_pkt_fields { uint32_t tunnel_id; struct eth_header *ethhdr; - uint16_t *h_proto; + void *h_proto; /* pointer to unaligned uint16_t data */ struct vlan_header *vlanhdr; struct ip_header *ipv4hdr; struct ip6_header *ipv6hdr; @@ -196,6 +196,11 @@ typedef struct of_dpa_group { }; } OfDpaGroup; =20 +static uint16_t of_dpa_flow_pkt_h_proto(const OfDpaFlowPktFields *fields) +{ + return lduw_he_p(fields->h_proto); +} + static int of_dpa_mask2prefix(uint32_t mask) { return 32 - ctz32(ntohl(mask)); @@ -395,7 +400,7 @@ static void of_dpa_flow_pkt_parse(OfDpaFlowContext *fc, fields->ethhdr =3D iov->iov_base; fields->h_proto =3D &fields->ethhdr->h_proto; =20 - if (ntohs(*fields->h_proto) =3D=3D ETH_P_VLAN) { + if (ntohs(of_dpa_flow_pkt_h_proto(fields) =3D=3D ETH_P_VLAN)) { sofar +=3D sizeof(struct vlan_header); if (iov->iov_len < sofar) { DPRINTF("flow_pkt_parse underrun on vlan_header\n"); @@ -405,7 +410,7 @@ static void of_dpa_flow_pkt_parse(OfDpaFlowContext *fc, fields->h_proto =3D &fields->vlanhdr->h_proto; } =20 - switch (ntohs(*fields->h_proto)) { + switch (ntohs(of_dpa_flow_pkt_h_proto(fields))) { case ETH_P_IP: sofar +=3D sizeof(struct ip_header); if (iov->iov_len < sofar) { @@ -547,7 +552,7 @@ static void of_dpa_term_mac_build_match(OfDpaFlowContex= t *fc, { match->value.tbl_id =3D ROCKER_OF_DPA_TABLE_ID_TERMINATION_MAC; match->value.in_pport =3D fc->in_pport; - match->value.eth.type =3D *fc->fields.h_proto; + match->value.eth.type =3D of_dpa_flow_pkt_h_proto(&fc->fields); match->value.eth.vlan_id =3D fc->fields.vlanhdr->h_tci; memcpy(match->value.eth.dst.a, fc->fields.ethhdr->h_dest, sizeof(match->value.eth.dst.a)); @@ -643,7 +648,7 @@ static void of_dpa_unicast_routing_build_match(OfDpaFlo= wContext *fc, OfDpaFlowMatch *match) { match->value.tbl_id =3D ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING; - match->value.eth.type =3D *fc->fields.h_proto; + match->value.eth.type =3D of_dpa_flow_pkt_h_proto(&fc->fields); if (fc->fields.ipv4hdr) { match->value.ipv4.addr.dst =3D fc->fields.ipv4hdr->ip_dst; } @@ -672,7 +677,7 @@ of_dpa_multicast_routing_build_match(OfDpaFlowContext *= fc, OfDpaFlowMatch *match) { match->value.tbl_id =3D ROCKER_OF_DPA_TABLE_ID_MULTICAST_ROUTING; - match->value.eth.type =3D *fc->fields.h_proto; + match->value.eth.type =3D of_dpa_flow_pkt_h_proto(&fc->fields); match->value.eth.vlan_id =3D fc->fields.vlanhdr->h_tci; if (fc->fields.ipv4hdr) { match->value.ipv4.addr.src =3D fc->fields.ipv4hdr->ip_src; @@ -713,7 +718,7 @@ static void of_dpa_acl_build_match(OfDpaFlowContext *fc, sizeof(match->value.eth.src.a)); memcpy(match->value.eth.dst.a, fc->fields.ethhdr->h_dest, sizeof(match->value.eth.dst.a)); - match->value.eth.type =3D *fc->fields.h_proto; + match->value.eth.type =3D of_dpa_flow_pkt_h_proto(&fc->fields); match->value.eth.vlan_id =3D fc->fields.vlanhdr->h_tci; match->value.width =3D FLOW_KEY_WIDTH(eth.type); if (fc->fields.ipv4hdr) { --=20 2.43.0 From nobody Sun Apr 12 04:23:11 2026 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=1770905518; cv=none; d=zohomail.com; s=zohoarc; b=SK2+Vn621KQqlAdDeBhVBuvE5d/S2LuKUIiHM5dUZGmiJH8lUKqwJvyFsffwDW09SC26u0yxol3Ysks9mfVKDorcWOS7lAEXlxBd5qvmjjC7tPjKvTr8aaToRTq9jqfAkL2U2gPreEaKCk0k/PVudrncaI7i6uq1d/GMdESdV2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770905518; 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=b5ua7I8U2//YbkEEDizXTPRRQsakmeqQDlcwRr1J+aM=; b=WTpQjq7MfsWW6uh0i8O0Fzf6HmecZIhatQtlTSQNE5FQIhzsmpB7zTCL2WhWpq07DY39NdT1JIKZcPoaloR7FZrNYQofQq33kqr4obzkzD+sFvIb0JOd3fiVDCu+zt/1rah1vTVapqTRGP9VD+nw8kO7RLMwDC3z922h1bvPiIw= 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 1770905518810851.4648165424455; Thu, 12 Feb 2026 06:11:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXNx-0000ho-NR; Thu, 12 Feb 2026 09:09:39 -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 1vqXNo-0000gD-6t for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:29 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqXNm-0006Q6-1C for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:27 -0500 Received: by mail-wm1-x342.google.com with SMTP id 5b1f17b1804b1-48336a6e932so32424525e9.3 for ; Thu, 12 Feb 2026 06:09:24 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835dd0e327sm123266885e9.14.2026.02.12.06.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:09:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770905363; x=1771510163; 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=b5ua7I8U2//YbkEEDizXTPRRQsakmeqQDlcwRr1J+aM=; b=xhE2kO2E3rvAgOsiccnqDLtELQGjaWNkH7thSoCSkx4ZgdTtZjdqVE8E0ylHOv/0U5 SzjSqQJYWuPIuo3kZV//OqYj3Z78VzQDtliDq7W1nnaSEeKDm1eCH3dRO9ZjTKdYHCZ5 aTgyOfxpg1SDcUjj42K7WcIMA0EQatOWrtVF/lzaQaJztZlkDCTUnSgVlI/JQha3Pbrj W+raUQ6sjpe7X2vfcs3g2mqBq1Zg+KnRXNJ/b2I7+PzuXbofwgzeKgs2s1YtrXraacL4 5WFrRQVy49GLex0OOusYIurHgbATi1XGSgGAjgdcSM6pd/dYK8v30u+4SBm7QFP9mjuY FOiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770905363; x=1771510163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=b5ua7I8U2//YbkEEDizXTPRRQsakmeqQDlcwRr1J+aM=; b=NAZp+8LfLx891+4pkhQYg8oI3oUEOtjLmVSpVUg5vKyXSIUxuzH0/VurfexoT9ci/U uMA82XG2/w75liXD07hFbAwVJHUlOE0zvnB00gAbRlAgVAY+sHKGrahEdlWHox6bNFVe n7dlH9Ve5RtH9tiVJk6LGCoNo9EiqPvEXS5zEXkcGRBCfqz3EGOsa3PjYZteCrQxutWr 1WekREqOr0/D49lmVYejCoMHshl8SwNKGqq+UcL1ygiEIjmu1h/6KwpUyW19aK209QDh 8swwAbTsmHrD9qUT3cvS3Qq2mZ+1K1fIkoQYtYprEKwxb70uAGylIy0Kh4D1tUWC5YyD ztOw== X-Gm-Message-State: AOJu0Yx86MPAVuS36Dgn2AwbG8DW57fDu82ZPB4GzRHqVygrvjKxw65B SndFWzBUpM6AfjHQuTWz7JLw2RcEkePMBy8oj3Za25aOKYFMs++UDeJCI6XDYW8yplEsqqmKkO7 KtGjDYGg= X-Gm-Gg: AZuq6aKr3msxuzTFesS0KL5kSs4zZCjxSGy2Spvyjmu3iNzIXdZCxBuVPzIXPT6l1SJ Z2ZcGLFsY7xZGmIkfZQGqXTaoc0vXwhj6SxL767FqkQC5Dub27RQS3Ce40LDrdIHdvUvvnP4HY1 9TteytBmclZbI1gYg9/7yakAvJeKfvkrzOcXuNBFcgEqqtF+LOJIvoAoAd/TzxBLSoJHMQ1rSsE PRk+KpvYNNIdJ6KHYISwy0TPV5ZqLMIU5k1WCyDVmpGxn38QSgchB2epOWP2gSwHWz3/MxjVxjh e/LCysR9U/gVWO/ptZ6vCS0Tis83JkwtmVgBJdxrIslVyEeaEpryWMsD2V0GXRLj1gjOl/EsKfE IgWSIG24O0+Zz9mYxkdW0CzK1qi4Rt+sRsgfw94QPlEDFrsJAr/AgCnYAoOzaxusYzqldlNEUev cw5FYe/TgmFsNmeBabzykgX+y12cvs8p6ezhUFvuRUq3zCKYMi2hlvo59edFlfODnQOxCrw66Rx Usa6piGKcR6STR+9Ba0NDH834SwNsQ= X-Received: by 2002:a05:600c:3e0d:b0:47e:e20e:bbb2 with SMTP id 5b1f17b1804b1-483656ae35fmr43169275e9.7.1770905362982; Thu, 12 Feb 2026 06:09:22 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Patrick Venture Subject: [PATCH 2/5] hw/net/rocker: Don't assume h_proto is aligned in eth_strip_vlan_ex() Date: Thu, 12 Feb 2026 14:09:14 +0000 Message-ID: <20260212140917.1443253-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212140917.1443253-1-peter.maydell@linaro.org> References: <20260212140917.1443253-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::342; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x342.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: qemu development 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: 1770905521900154100 Content-Type: text/plain; charset="utf-8" In eth_strip_vlan_ex() we take a pointer to the eth_header h_proto field into a local uint16_t* variable, and then later in the function we dereference that pointer. This isn't safe, because the eth_header struct may not be aligned, and if we mark the struct as QEMU_PACKED then gcc will complain about taking the address of a field in a packed struct. Instead, make the local variable be a void* and use the appropriate functions for accessing 16 bits of possibly unaligned data through it. Signed-off-by: Peter Maydell Reviewed-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- net/eth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/eth.c b/net/eth.c index 3f680cc033..12ec316e24 100644 --- a/net/eth.c +++ b/net/eth.c @@ -274,7 +274,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, int index, uint16_t *payload_offset, uint16_t *tci) { struct vlan_header vlan_hdr; - uint16_t *new_ehdr_proto; + void *new_ehdr_proto; size_t new_ehdr_size; size_t copied; =20 @@ -298,7 +298,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, int index, return 0; } =20 - if (copied < new_ehdr_size || be16_to_cpu(*new_ehdr_proto) !=3D vet) { + if (copied < new_ehdr_size || lduw_be_p(new_ehdr_proto) !=3D vet) { return 0; } =20 @@ -308,7 +308,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, int index, return 0; } =20 - *new_ehdr_proto =3D vlan_hdr.h_proto; + stw_he_p(new_ehdr_proto, vlan_hdr.h_proto); *payload_offset =3D iovoff + new_ehdr_size + sizeof(vlan_hdr); *tci =3D be16_to_cpu(vlan_hdr.h_tci); =20 --=20 2.43.0 From nobody Sun Apr 12 04:23:11 2026 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=1770905598; cv=none; d=zohomail.com; s=zohoarc; b=nJ51uuf170Cn2/F0GBZK+rbwkOCFdb5vB1SQf52+o4jPm592haoaeeX19E4VecG3tPY/uIwCLwax7ML7xoQpaLkL8qKTfgpXBRPZ2U19xMZz3eHtqf5RIitxHHnhA4XcLvitUAcOKyBwnqTX1KkkBZ1MKZXvdtKAsWTAiYuH+lM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770905598; 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=R3cLi2JyUm8wKd97bhkRBOBT0oLXAVRHi0iTXd33KdY=; b=Kw1wsBgQXVWcBNvzfZ3IPF7kyP5t9/+ZDn6IKALAUqOX5AkVKDYTy3XGxi6ZTWurC+PVRbmIMu3pn/Zw+uuA3FXsrAVQfi152hjoU8OLUtwiHhVCW/ZOCWidFAxJAhc3KH/1i3JUsuA6as8ptsekKxeKAp7uObD9uV+gMQ7kVTo= 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 1770905598846945.5511402387676; Thu, 12 Feb 2026 06:13:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXNv-0000hY-PV; Thu, 12 Feb 2026 09:09:36 -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 1vqXNo-0000gC-6V for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:29 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqXNm-0006QC-Eo for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:27 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4801c2fae63so65897575e9.2 for ; Thu, 12 Feb 2026 06:09:26 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835dd0e327sm123266885e9.14.2026.02.12.06.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770905365; x=1771510165; 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=R3cLi2JyUm8wKd97bhkRBOBT0oLXAVRHi0iTXd33KdY=; b=ZweqdSaxwMnuxbs0GxNbZdZeGUI8d6h/xXdSFqsC6s93XzXckb59j4BJ/IsR6+84lb oVac8Fkcjp8Y2mzrRnZnHrj7DwEXzyO2sgSeUz42Gs8sdEAKEN+3tcpfEghFkKqu25+1 v77FdKmfoqSQQyuG5o8ZrGeKs3qAapzPf+Pkb2OxETFifMsjBgq99ANX6oyLFoZZq54f EVPQHvbz8+UiAT6lIlv7Jo5vi/Xlg7TYCS/wujAuqjCE6TVOFc2DOfxx0lUTLSV3P8kI arYKFJfKKRyv95lOz2wj95ZzF8caRdRS9R4pQrl5n1PwUWn2KlH1BjmskhpJc60hiVHv 7dmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770905365; x=1771510165; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R3cLi2JyUm8wKd97bhkRBOBT0oLXAVRHi0iTXd33KdY=; b=wF6EutAqcJjvRykIxTUqVLxdgPECGFdsEHolLA1AGiO7zb/7CadF0oatLiT2FTNCyH XcbegAgbKqULCc9D8dUWo53ssJ5bg9yD2pfqNt+fAhP08r8hlhZqvevWe1Bd9/plv2V0 xx00+JKzcXMn+vazeKa0MpHJfOx3zmZUyni6EpKIaPxhqG+DhpFdZ+KhiBOSMvJCEfLy +gRhpL5GbywHgfvpyBt7YXZefE0b8Rk2hiV2SPSH9Yn9/+WQhx3w2jDYcanQlru0HQYD dTs4PCITjuMsiab62drwqORdJPmsjnphYNARDBMiB5yTDZJ2xDrTQoar9fdfXsM03GPR b5WQ== X-Gm-Message-State: AOJu0YylwVma2ObcXvpy2fp/rv5DgE34GXBp+UAtugVrovVDnwrWhNcI P+y+La6R8KcPNkk7OMBXPTAfk6xX1Wl91hSZ/ZYZNs5rB8VDjcIowjAHQ0v14f4te21nhNZzlwd /j/8w X-Gm-Gg: AZuq6aK1ju8tnEAEvcHI6lMfggD+2Ud4tj1VYQ0XSPZK6bLpUbpbGkwrC4+3N6n7YUy fWqMwEQIR6jp6Kih01xwHkLVD1ngT0gQbJNSSQthPsE6E8cTAVnz7pp4H7rISLYVjnWbgb6tXcj ACK5C9r3d6T1lFrhTbXcYvPHssvtNssMnDfZKOZasjLE2/YWTiMTeWBWqeJfeMb41tVZx1JFb5p 1fI+jebhBwe79/Ru4OlmpUkXjwQ+MyAk0StyQfDz0B3MwP4KIeNMnrC01mszUs0FdIdpjP8d76Q 8sMdEiRUTr75zZFB7Oc63j5LlMbuvewDpbxv4RtX0eHEuIWUParULLyHBsaWbCgVcbrZK+67gIt 0eshipP/jqs5xLaFf+tQ84WatfobDqPMB4X0q8Ha2RIBd9dCIkgtrUB0M4Msetdr0K9Ib8z0YvJ ZPJeQyLG71+wfUSWgrPjBCKJaFrgivD/UcZZeIQElptLPn8YwLvTuQ5OM6EhzGW44SNn2/jbmSL JoOUsPh7zQ7OUI5cZvdrXtWmxsO9Mw= X-Received: by 2002:a05:600c:8b2e:b0:471:14af:c715 with SMTP id 5b1f17b1804b1-483656ae449mr37134725e9.3.1770905364554; Thu, 12 Feb 2026 06:09:24 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Patrick Venture Subject: [PATCH 3/5] net: mark struct eth_header as QEMU_PACKED Date: Thu, 12 Feb 2026 14:09:15 +0000 Message-ID: <20260212140917.1443253-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212140917.1443253-1-peter.maydell@linaro.org> References: <20260212140917.1443253-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::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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: qemu development 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: 1770905601604158500 Content-Type: text/plain; charset="utf-8" The eth_header is not actually guaranteed to be aligned. We attempt to deal with this in some places such as net_checksum_calculate() by using lduw_be_p() and so on to access the fields, but this is not sufficient to be correct, because even accessing a byte member within a misaligned struct is undefined behaviour. The clang sanitizer will emit an error like this if you run the sifive_u_mmc functional test with sanitizers enabled: ../../net/checksum.c:78:47: runtime error: member access within misaligned = address 0x561f52f35011 for type 'struct eth_header', which requires 2 byte = alignment 0x561f52f35011: note: pointer points here 00 00 00 00 33 33 00 00 00 16 52 54 00 12 34 56 86 dd 60 00 00 00 00 24= 00 01 00 00 00 00 00 00 ^ #0 0x561f20608459 in net_checksum_calculate /home/pm215/qemu/build/clan= g/../../net/checksum.c:78:47 #1 0x561f20117bfa in gem_transmit /home/pm215/qemu/build/clang/../../hw= /net/cadence_gem.c:1386:21 #2 0x561f20115c61 in gem_write /home/pm215/qemu/build/clang/../../hw/ne= t/cadence_gem.c:1650:13 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../net/checksum.= c:78:47 Fix this by marking the eth_header struct as QEMU_PACKED, so that the compiler knows it might be unaligned and will generate the right code for accessing fields. This is similar to commit f8b94b4c520 ("net: mark struct ip_header as QEMU_PACKED") where we fixed this for a different struct defined in this file. Signed-off-by: Peter Maydell Reviewed-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- This came up back at the beginning of last year: https://lore.kernel.org/qemu-devel/CAFEAcA-gyMTz-KpmamyXcKX9QOL=3DyYHDMPRF2= Xji_uJbG02WpA@mail.gmail.com/ but we never got around to making the fix. --- 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 14c34f530f..63f598d7cd 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -39,7 +39,7 @@ struct eth_header { uint8_t h_dest[ETH_ALEN]; /* destination eth addr */ uint8_t h_source[ETH_ALEN]; /* source ether addr */ uint16_t h_proto; /* packet type ID field */ -}; +} QEMU_PACKED; =20 struct vlan_header { uint16_t h_tci; /* priority and VLAN ID */ --=20 2.43.0 From nobody Sun Apr 12 04:23:11 2026 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=1770905526; cv=none; d=zohomail.com; s=zohoarc; b=iVrBPKiOLldoD9dMCeNuKHKgXwfD/SL40lOiEQKZAnNnKMdGDqvtLDF+vcJB55+mGrblnJLwW4SC383m8AAj4Tdn6VBqVxSxJ3JTEkWHwF8+TtF7aE8Ijg7K//AQzkBN79InJCcINJocBPg+OMItgxci3052GRq+TM6V/3s1fkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770905526; 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=w7/HOOx+I4w67JP8F45Y9oVZsaYEEhfC+iicHDh+kCk=; b=U8cWbGnTIXjUEVF2HfaQ0sRYSdWOvlRPLCkxiN4N4WugSsWgNKibxeSrCGida6j3bImu28qhT+VEDU5YqATQaK0dsSvS4v/lfd/hKKOvHgxsLuw5E6OwAJS2gdWLclbiim+dtYqyv8sjaTn2LfMwGdheke/fwSyTOuYH3ZsGD+E= 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 1770905526196969.5459741036548; Thu, 12 Feb 2026 06:12:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXO3-0000iX-Ga; Thu, 12 Feb 2026 09:09:43 -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 1vqXNp-0000gN-Gj for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:29 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqXNn-0006QK-VN for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:29 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4806dffc64cso69380395e9.1 for ; Thu, 12 Feb 2026 06:09:27 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835dd0e327sm123266885e9.14.2026.02.12.06.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770905366; x=1771510166; 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=w7/HOOx+I4w67JP8F45Y9oVZsaYEEhfC+iicHDh+kCk=; b=t+cJ19PHe34CB2lXOxf7cAlhABsUJhyBQudJyWVWG4+3XwXRabRJLjKph8o5aE6J2R fox8v0HuK92U0r6dmwSnN/OVbXWpmPY8btTIFTF16dZ8qxpwJNcKIT/ZfZASLmD3m4fh zmCGGuP0p5MpxOC7GLpT+2kh2ArBTIBeBdB1JJksfD+xwsm8PQSB7J53eNDL/3EJqQ6t Pyg6m7dtQ8PvyEGLhXKMlfWbG1vUBDxdQ/b52LsPMSeN4F70m5cA8deS/48MOFbbvxWo /plOFRDbV4qbGqtWf/ODsVdu2NMiL/IaGSogAS7lrF/rtJcOzNyVCA8reDbbOk57eTUi QEuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770905366; x=1771510166; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=w7/HOOx+I4w67JP8F45Y9oVZsaYEEhfC+iicHDh+kCk=; b=orADnXY2Hd6rK1tgbgbNMHSNoJ9b+EzFlONN1wcNoGISfz9a/xuN2ERirFHkKlGTSp 5qkrljMMr6GWCztSc66GCFETtjd0POKQuz195scqNwnlgqNmxw/jSgFLvkjRL+EalNdU zF5uVX9kyqdSHYezmxVe5sNAVxq9cCgFM4CxZUCjJCFlIYg/bLlUxWocgS4r9eps04Hz F0NwMofEN02mE0xecCzLRJ5Dr7R+QwXOTHTf/drlKnfQM4KW2LvW01GZuxi/X+9tByVC QWWSnq/o1EZ2OQG/i7SDDTissoKwn9UnhBogH1oEh6+dwSHkZNiFp83qD9S+NH/vSYR5 +DQA== X-Gm-Message-State: AOJu0Yz8KpLQ7tBrKYVlZrkgPw3AKptPJP3nCC6GM7N8UXNKdb06O2lH xEct5rbUHu3SiITmxjKETd01nLgLElybkCkfGbMEdIk5QiccMu3WB3WhD2/uEtU9FVWaA6hIZZ7 kHrAu X-Gm-Gg: AZuq6aLyONfw2WEa5QeZzxRqidESyIDvPuOiVCYt1T1S2+DQBAOn6uRy7WkudiOM7kS 6V49Gfo94B9G7jrDMHFLpXFsAgDS+Un7JLjW5fIUEukxJHkKgDUcSnGofDHOq7cpnYUOek9ywnL sBRtgGQx7LEJPjbiFV7B3fznNECCFaFeuZ8ebGey3tWNrR1pIjymoltQq8CqR5zrCthmigTI3Ia 9LhR8310r0LO6uVArCllgMLniwGeid5accF5bkGKS1DccCHA0yhswuT5eL3vZWYAKbbTMdAlrq9 dP71ryYw39u/HAzXda4f1Q39xqQ0tBx6aecGwe3l/9SsDXGa/mZhmHIV38eJv7f7h0D8kTtWRTK AlgRzGcHO5u1c1QcAMlE/iuwnHoh6DIJ7p/0ab852h15BzXEdSmqvlyXDn/hXYMkL7gvYSBMzn0 0sAVOY0pHXEs3A2ASr3nc2cmqADdxg+TkhS6/rusBFVjwMrERs7Hnk86xnGgQmgtGFjon3hEY0H h47ht/JvZlDHH6inaFyQ8dIEZF+IkM= X-Received: by 2002:a05:600c:8b64:b0:480:1e40:3d2 with SMTP id 5b1f17b1804b1-483657181edmr36506925e9.29.1770905365699; Thu, 12 Feb 2026 06:09:25 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Patrick Venture Subject: [PATCH 4/5] net: mark struct udp_header as QEMU_PACKED Date: Thu, 12 Feb 2026 14:09:16 +0000 Message-ID: <20260212140917.1443253-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212140917.1443253-1-peter.maydell@linaro.org> References: <20260212140917.1443253-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::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.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: qemu development 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: 1770905527976154100 Content-Type: text/plain; charset="utf-8" The eth_header is not actually guaranteed to be aligned. We attempt to deal with this in some places such as net_checksum_calculate() by using lduw_be_p() and so on to access the fields, but this is not sufficient to be correct, because even accessing a byte member within a misaligned struct is undefined behaviour. The clang sanitizer will emit an error like this if you run the sifive_u_mmc functional test with sanitizers enabled: ../../net/checksum.c:168:24: runtime error: member access within misaligned= address 0x5b7a7f829033 for type 'udp_header' (aka 'struct udp_header'), wh= ich requires 2 byte alignment 0x5b7a7f829033: note: pointer points here ff ff ff ff 00 44 00 43 01 34 58 54 01 01 06 00 85 95 80 60 00 00 00 00= 00 00 00 00 00 00 00 00 ^ #0 0x5b7a71a5887e in net_checksum_calculate /home/pm215/qemu/build/clan= g/../../net/checksum.c:168:24 #1 0x5b7a7156819a in gem_transmit /home/pm215/qemu/build/clang/../../hw= /net/cadence_gem.c:1386:21 #2 0x5b7a71566201 in gem_write /home/pm215/qemu/build/clang/../../hw/ne= t/cadence_gem.c:1650:13 Fix this by marking the udp_header struct as QEMU_PACKED, so that the compiler knows it might be unaligned and will generate the right code for accessing fields. Signed-off-by: Peter Maydell Reviewed-by: Akihiko Odaki 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 63f598d7cd..df90ff0837 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -85,7 +85,7 @@ typedef struct udp_header { uint16_t uh_dport; /* destination port */ uint16_t uh_ulen; /* udp length */ uint16_t uh_sum; /* udp checksum */ -} udp_header; +} QEMU_PACKED udp_header; =20 typedef struct ip_pseudo_header { uint32_t ip_src; --=20 2.43.0 From nobody Sun Apr 12 04:23:11 2026 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=1770905519; cv=none; d=zohomail.com; s=zohoarc; b=kq2RIQCvLCoO7i6AVg/ULykGjjLhYQZ3XQiM2keXbFTIiiYsO9jGUU5wZoGqQibO6EKbMqPescfGjydSGA5heEQSQO0so1leiMT+/Jk7WddqDVab1izrkdzZt5YfOoYxh3lfOoxjDzyjnGXSOmCYv5RJ3vsABeTm8oZuEO0tstY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770905519; 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=umz9FaOJkrxhBScr7QTLwHMuZF/7lh+gWKhwaBjbmJE=; b=UB/SMSP0T48c5NjG9hReWQ+YOAz5SeedkJV+UCRDDtws9OsMw/4qcaWebup7PXPaSUvnPl/qg8KbJ6ovzcEDTzvSgJfQnlPjyr0oo+C07kSCxpdMhRg9O69CoGZAB6gRS9ILWDiC/8kirjbHQ7+hQ1tDP/j8OzdFrluc8usFQIM= 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 177090551962233.01555788406188; Thu, 12 Feb 2026 06:11:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqXO5-0000mF-Fl; Thu, 12 Feb 2026 09:09:45 -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 1vqXNq-0000h0-5Y for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:31 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqXNo-0006QR-Kc for qemu-devel@nongnu.org; Thu, 12 Feb 2026 09:09:29 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4806dffc64cso69380555e9.1 for ; Thu, 12 Feb 2026 06:09:28 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4835dd0e327sm123266885e9.14.2026.02.12.06.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 06:09:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770905367; x=1771510167; 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=umz9FaOJkrxhBScr7QTLwHMuZF/7lh+gWKhwaBjbmJE=; b=YixYzT5gaIROnH5xBxumfeSwjqI+mTH+0HZb8QhcyQAgrgNDjTLCwfmqGpTF4QtVOB 3fXvKJzVn7VV/gOoJGnuUlldmRYJnD/MH8nOWhG63mNcI2QTUS48dfZd8SaiQiYMgdv3 LLtVfagaLSbMiZ84zEscBYc5Sm5YrXTI9Ee/pTU3Xt6iNac1/QbRSv5PhkKxq7woZd6B KeqpPmO3w53AahF5B/sWhFIl2Qe3IYkJBnn+GQpI8D96UiC95g4qkAT9J17Eh3ba0JUS odvadU2qUhS30YW1VVENQd1yEe2bm6R0V6kZuY5t7zEDD0PIzqz/GahSekIq/CVqIf35 1MIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770905367; x=1771510167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=umz9FaOJkrxhBScr7QTLwHMuZF/7lh+gWKhwaBjbmJE=; b=mFWD3qGiV1HBqeCZEvWiUkB0ZCFVg1QyytV46IyoXgERZ93q5wlcyu3nT6Ptb5Q6hZ 03VbQwRYqfA06MYf5a2YHewm9t9VcFbzntIIQRUi0bT0Enc0CCXP/r28BAhKVI8fPIVv 6BWa7dg/LY9uSPZyZcjEOfppU06BP+3rDzUg51DewtnKAWS2VnQOFBI/eYtTtm/yMqQt oT0oH5pOLrumRFBhfwW3TdL9b57O1LRhS3jTG0EHzhNVrBp/MXJ+Jkc2a13aRJ+EemRA a18zM3EAdDZdjLHJMRHX227G1Js3+Xjof1j/NGECxVWWIiXmIe2Kyy5My4Oo4NXffE8o JVHA== X-Gm-Message-State: AOJu0YzFdlIt/OgPrY/nCkCQ8LOtjMlL6HC3oPkBhA7QS5VQfgwqJjkZ KHGuFH0z3w4VkGVhFuGdl5Izm7RubY+/hqSWPBtf0xMKfnz2UsrDrASGEZUujGMHxXoFRHKHKDo dOY62 X-Gm-Gg: AZuq6aJj2uSv3CfyXGPhWi7cjlhHdXRsr/HL/U4heRWqaXmXe12xGIuhNKgSbplyug2 8PDfGyYAyiObPPc3F31kKXtugwL41yporTSq+vbn4F6gZljuLKJe627Dsbni2gNFkmX4zr7D2cY AOsxtCD/gTViydsRouYHzVzSUpxUBV1bdDNyzjIYZi0JjJ5PMBrrWHTqadffB+AqmUO5wy/vUQK SKzT3jI2kg6l1/Z5og/MOT26wkcCh58+xipWqBzgUk0f+ZI+SIHOFAGUO1f+quSVpQtzU/WrZNn 8r9CWW4LItLTpkjrgwlihsR7ekiIFPKSFLHhQHRL/BcV3YMV/mnan8O1B1s2GhlUfTEDJPpMmG2 PfTA+J7RaiNO9Z/j99fGbOVKNhFRrf2gRTL+UHDrzE4VXS+fSehh/v2z8iMQonD2wTtuexh6QVc aSts1ohMzhUeO1ZKuJ6zAwgDpZfy8PTyhFoWHROcqnPsOSkjs4/3FM7mem0i+REtjSukQLGRTfZ tFOQRxKwBHd072tJU4SZeJJ8XXdMNM= X-Received: by 2002:a05:600c:4584:b0:47e:e2eb:bc22 with SMTP id 5b1f17b1804b1-483656b08cdmr44367035e9.5.1770905366947; Thu, 12 Feb 2026 06:09:26 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jiri Pirko , Jason Wang , Dmitry Fleytman , Akihiko Odaki , Patrick Venture Subject: [PATCH 5/5] net: mark struct tcp_header as QEMU_PACKED Date: Thu, 12 Feb 2026 14:09:17 +0000 Message-ID: <20260212140917.1443253-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212140917.1443253-1-peter.maydell@linaro.org> References: <20260212140917.1443253-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::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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: qemu development 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: 1770905521149158500 Content-Type: text/plain; charset="utf-8" The eth_header is not actually guaranteed to be aligned. We attempt to deal with this in some places such as net_checksum_calculate() by using lduw_be_p() and so on to access the fields, but this is not sufficient to be correct, because even accessing a byte member within a misaligned struct is undefined behaviour. The clang sanitizer will emit an error like this if you run the sifive_u_mmc functional test with sanitizers enabled: ../../net/checksum.c:144:24: runtime error: member access within misaligned= address 0x619a74c32033 for type 'tcp_header' (aka 'struct tcp_header'), wh= ich requires 4 byte alignment 0x619a74c32033: note: pointer points here 0a 00 02 02 86 aa 00 16 52 c1 d3 70 00 00 00 00 a0 02 fa f0 00 00 00 00= 02 04 05 b4 04 02 08 0a ^ #0 0x619a6ba84794 in net_checksum_calculate /home/pm215/qemu/build/clan= g/../../net/checksum.c:144:24 #1 0x619a6b5940da in gem_transmit /home/pm215/qemu/build/clang/../../hw= /net/cadence_gem.c:1386:21 #2 0x619a6b592141 in gem_write /home/pm215/qemu/build/clang/../../hw/ne= t/cadence_gem.c:1650:13 Fix this by marking the tcp_header struct as QEMU_PACKED. Signed-off-by: Peter Maydell Reviewed-by: Akihiko Odaki 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 df90ff0837..efe270dbfe 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -68,7 +68,7 @@ typedef struct tcp_header { uint16_t th_win; /* window */ uint16_t th_sum; /* checksum */ uint16_t th_urp; /* urgent pointer */ -} tcp_header; +} QEMU_PACKED tcp_header; =20 #define TCP_FLAGS_ONLY(flags) ((flags) & 0x3f) =20 --=20 2.43.0