From patchwork Thu Nov 14 14:16:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 843124 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcc:0:b0:382:184f:390f with SMTP id e12csp301836wrc; Thu, 14 Nov 2024 06:17:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW7UX3eMRjygVkmDV5steT4eTXgYHFvFfjVM/NBFaT8FBT51ZPYwlmadb+xwUygXoHnqEkVig==@linaro.org X-Google-Smtp-Source: AGHT+IFyId5oWwfd3QFb9DBy1cxmPoW49/Ha4e1MvKLsFw86vBUKDDDI3CGWzeKd8pE+RjRUDKV5 X-Received: by 2002:a05:622a:1310:b0:461:148b:188b with SMTP id d75a77b69052e-46358f1d14fmr28320301cf.12.1731593849685; Thu, 14 Nov 2024 06:17:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731593849; cv=none; d=google.com; s=arc-20240605; b=FP7APh3yg1hKXgMJfa9IeK5Z2XZaqXinpCT0cG6/E8R6CTSpFENU2JhwK6jOlprhMk Hgq7DjJurj2zaxSCgoPuOxpIJILhPkl9rOx/4mW1kfV0uq5PAkxNlC9IpdD30PtJz9B+ P/xfSNsiItcfTINTKVOf5j98ldSCWmJmLdzgKLaY+2Yg65iMgzZyWSPnkjtsAgTt7BA5 p268olq1MqNkxvYImR0VlPLP7tkSM3fDAwJVPD7Lys1Ga/KSlz99JInen3ixM5XlXD7E hRjeNWTloABRt2KLKaWKyy5iMGSXRXdDRcx4elaXZtZoXdqm/o/iwg0+jxb3a8I48oYh O64w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=rQtG2DTe69xRGS5IpoB1b9+fEhQPKqrD0dUp2eVwI90=; fh=Xv3tgv6XlaNAfzuwDULeg8Ugba1x/wq+cAw7U5F/8pM=; b=fVWCk9QJ99VPfTzRK81twRcOXspsLpXmfdb5YuyXLZRTudjPz7YYZvfHrygPBwDDzI N84hOAZmh7+/JbNF3MRkK3wEAJJfiusgnn2JsdLZ0P5AJDUdmIWkcMaqjdI55+lAn+NA LMDYt27nmXyWSX44FFLJS5K3bJWoGeZ396cDhr7GZAyQhOr9KB83m3SnTIjMn5x8EKgM RGPvmNMnt9m646ojFTS44IInsXHIy7/RVaMqRLuZP9DE8JgYs9Tk875M+4Ty3tENo6G2 tX4HhTtpNWDeZMJ7DWVMAJwyXTv6bjjYs7gX3ky7BXkfsnoldSm+nFl0ie0TWbekyY7y Ftrg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fDLFl6cR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4635ab3d492si11660211cf.567.2024.11.14.06.17.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Nov 2024 06:17:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fDLFl6cR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBae4-0000fy-1F; Thu, 14 Nov 2024 09:16:28 -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-0000fI-Qo for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:25 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBae0-0005gx-0S for qemu-devel@nongnu.org; Thu, 14 Nov 2024 09:16:25 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43158625112so6467355e9.3 for ; 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=1731593781; x=1732198581; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rQtG2DTe69xRGS5IpoB1b9+fEhQPKqrD0dUp2eVwI90=; b=fDLFl6cRgb0vnWle7PBluA8dbjo0rBKN8tWGNFZtj30mPzW5HV5qU57j8X5trssQ6g G9wkDRbSAsVzlV2K1AuPysMdqA/PxczskBl9CuM1QDYYbX5LBJkfpRitjsFGNLKm3lP3 3N3R87BO/vVnRLMRlejzPTxpNl/pErSgTs8S0pmQ9x4zgLROeua4PzKHOWdRRo/s1jOU 6Dj+iq3eipI8+easRXhWU/T7eISP6uGTfX4OW2h5TV65Pwezh3yo+ie2pX9efFaDHGjJ Ymv1zat35w3V67FpzSW8wCjWXp6DXbm/8DL2gRCUtGCL/iYVA0tl7JLnJ4B159bMwxp3 BPKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731593781; x=1732198581; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rQtG2DTe69xRGS5IpoB1b9+fEhQPKqrD0dUp2eVwI90=; b=pdetolXyOM3oSPNJf0mWWkL5YtDPAlYaTiVJYAHy1X+Xma+QAs9eUohYj+dvqhqVBS 2ghRM7y0N5xKCfiRImsEV1xqmG6npuzvbfZtd24mqRitjwsBYw3H/X4sRFCCXNd1Yngo heOcwoy9aTMaZT05s522DcrjiSKF+C4W9KDLpQGzQSxhZK/00Mmcjhy7JtWqQSljSlzA UgQA3KtflNXpsB+jy9nRtWQpZWUSe6s+hVjkg1ChDuWD7xy/IMpXQWGMuhdlNMRx8+7l YbcShBioJPzHtnyobUQSYeWRhqjHldQ9SCLklseE9319meHQRy6coekBo1y35mP+DOoN 1ARg== X-Gm-Message-State: AOJu0Yy2kWjtVKMqFa2EwCnKv1odyfdcpe7CMjMlBPbaMhmHBfTWyzdi HsZCd7khz+jqUK8LB/Kzg/bGe4nTYRPgDRRcu9NRghwm7L2FlynYDQv/xwzgSvycKUoN7Yj92Yb l X-Received: by 2002:a05:600c:4e08:b0:431:44fe:fd9f with SMTP id 5b1f17b1804b1-432da7cb853mr18090585e9.23.1731593781203; Thu, 14 Nov 2024 06:16:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 06:16:20 -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 0/2] net: Make ip_header struct QEMU_PACKED Date: Thu, 14 Nov 2024 14:16:17 +0000 Message-Id: <20241114141619.806652-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This patchset aims to fix some clang undefined-behavior sanitizer warnings that you see if you run the arm functional-tests: Stopping network: ../../net/checksum.c:106:9: runtime error: member access 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 02 02 00 44 00 43 01 34 19 56 ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../net/checksum.c:106:9 in ../../net/checksum.c:106:9: runtime error: load of misaligned address 0x556aad9b502e for type 'uint8_t' (aka 'unsigned char'), 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 02 02 00 44 00 43 01 34 19 56 ^ These result from the net_checksum_calculate() function creating a 'struct ip_header *' from an unaligned address. We try to handle the non-alignment by using functions like lduw_be_p(), but this is insufficient because even accessing a byte member within an unaligned struct is UB. This patchset fixes this by marking 'struct ip_header' as QEMU_PACKED, which tells the compiler that it might be at an unaligned address. For that to work, we need to first fix the places in virtio-net.c which take the address of a field within an ip_header: the compiler will warn/error if we try to do that for a field in a struct which is marked QEMU_PACKED. Probably other structs in eth.h should be marked packed too, but I am here only addressing the case that produces warnings that I have seen. v1->v2 changes: * patch 1 now uses the correct lduw_be_p/stw_be_p thanks -- PMM Peter Maydell (2): hw/net/virtio-net.c: Don't assume IP length field is aligned net: mark struct ip_header as QEMU_PACKED include/hw/virtio/virtio-net.h | 2 +- include/net/eth.h | 2 +- hw/net/virtio-net.c | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-)