From nobody Sat Nov 23 20:51:53 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=1731934239; cv=none; d=zohomail.com; s=zohoarc; b=XpWZY3fN7KuJL6E8VukhpJN7kr7aegYWSv7R+IWd/sZK4Gp1GLdpQv9r2rVZDHZo++pVCgikYAf4qTOMnp3ENbnorOSL209GHb35EurmpiSQHjHtzNPOeJwYxetDhHUTu7i1kTYVc9/GgsvfKxQUcTHXeAVOLZ77FiXPBAlOMY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731934239; h=Content-Type: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=Imru/ZUlyc0vwa6lGwgvhqK0h2OrYCXvH3UhgPN1YaY=; b=S18jOiVkCjLYC/wAbhSYdP10krmHOVfo4nIexPsh1Fz4Hnw35hYcnconbdzsI+Jv19Wgv+crgoPn4SMWkKlu2KLRdB2b+95OW6cv9N90k9Stp1zgZf2qRw0oZ2CQ1oW/IkjZRgWndJJHa0TDB9aubPPn+vNXjt0lFyxPRjqragY= 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 1731934239056594.2597598430054; Mon, 18 Nov 2024 04:50:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD1Ba-0006Wv-Rw; Mon, 18 Nov 2024 07:48:59 -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 1tD1BB-0004c0-3I for qemu-devel@nongnu.org; Mon, 18 Nov 2024 07:48:37 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tD1Az-0005Rs-56 for qemu-devel@nongnu.org; Mon, 18 Nov 2024 07:48:27 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4314fa33a35so34219485e9.1 for ; Mon, 18 Nov 2024 04:48:06 -0800 (PST) Received: from localhost.localdomain ([176.187.198.1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dab72141sm154245905e9.1.2024.11.18.04.48.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 04:48:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731934085; x=1732538885; 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=Imru/ZUlyc0vwa6lGwgvhqK0h2OrYCXvH3UhgPN1YaY=; b=ul6KecDMMCUlCu1h5BcA/gCzcaGqJc+zYcJvQvXUEynJjDj+tmybmzxhbMLkZhxVpU CAVaK4iflU2QmrSvMdqoEdzggZUiYT0EP9CJiPiu1kTah+aR9+tDG2dAWhIrG9HbQq3M YnDhXpsaTIBADwqoz2JcgeMGYnEP50GKTP/3pY9aJt2R1QsrL81Paiww2Fq2AjInlcVN wISgGA4kLzE8klHgeJEF7u80WMsRq+6VLt9Q4yej79b9pyEWoTxSQHUN+/540pt/uTlk TTiUPK2emhQhPYDNFsYKtv+uSmN5BiqBxlofdyb/t9fIPv4jjDrZZqAu7prlZus7FU5j 0WkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731934085; x=1732538885; 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=Imru/ZUlyc0vwa6lGwgvhqK0h2OrYCXvH3UhgPN1YaY=; b=fQtcXqQ8tOyaV2uI02yq8xfJBjGkaB2skyMe7eK4gS9cWIDerMhfJIc8nJE8P8ssOP lJQ9LjhZzxmlQEiDHVfqp5WZbjYZwCvsuE/SUUodxnd8xBOmeULGMVOiPnIqJIs83GaU zZIs8gKpe804stHyPW+L0E3La0HxdRIGc8+VuPKT3bEhV7VuJwXEXn5KuLeiHCHbOkUs cA1Z+QxqXyzhvFti61spCiJTuxxCuV/C0htD9n1hrCskBHOYjL1kTaK+CZ7aEgSgxkAh 5VTwW7Xv79Wpu3m37Fp3v7PsC8dijpMIXmO303q7x4aWeCtk7KTKED2OUhlmwCjV7OII RWcg== X-Gm-Message-State: AOJu0YzhxXKzf34DSUyqTfT+9Ex6HYg/JIKdM384DOAxt8ZKw/MIc1jN iUD8YfrBzVHyWqzOsZJX/eJHBMvPbQEaT5mwlXZ1cvM9md8xJHt9S1MW/u1TuJzoM54bi7oH+97 i X-Google-Smtp-Source: AGHT+IEWCCUlyMcimPNU7anHnu8XpmnyGwClGKjSup9I94AA0iZGPXcqmIerMVh4OpiXovD0o1Q+YA== X-Received: by 2002:a05:600c:1d90:b0:42c:a905:9384 with SMTP id 5b1f17b1804b1-432df791f39mr93347075e9.20.1731934085128; Mon, 18 Nov 2024 04:48:05 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 14/15] net: mark struct ip_header as QEMU_PACKED Date: Mon, 18 Nov 2024 13:46:41 +0100 Message-ID: <20241118124643.6958-15-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118124643.6958-1-philmd@linaro.org> References: <20241118124643.6958-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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: 1731934241103116600 From: Peter Maydell 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 Message-ID: <20241114141619.806652-3-peter.maydell@linaro.org> Signed-off-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 3b80b6e07f..14c34f530f 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.45.2