From patchwork Tue Oct 8 16:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 833582 Delivered-To: patch@linaro.org Received: by 2002:adf:a1d9:0:b0:367:895a:4699 with SMTP id v25csp395221wrv; Tue, 8 Oct 2024 09:48:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVK3tZbzOzCJg17l1rMTT/JMEWZKTjpllaUSfJQ9Y8tCQXk2XfCnI878V6I5RDt8U6qR75/rA==@linaro.org X-Google-Smtp-Source: AGHT+IEbzVzCYzfQ8PGkja3hRiqNDKwb27KikfPP8dDAYxygjJO3QEJVqwij2WqIQgwSUUxhxrRe X-Received: by 2002:a05:622a:528c:b0:45f:874:e488 with SMTP id d75a77b69052e-45f0874ec21mr9689301cf.59.1728406110514; Tue, 08 Oct 2024 09:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728406110; cv=none; d=google.com; s=arc-20240605; b=RF4IIUvOdD68rCDTlb98nIymX+ED8O3EJwTtuniA0W1EXLmOL5XAwbkhtV5GB4QACJ ebv3QcKkv/H/M9btHtIz2JkSTu7J7G/zv6ZP/TcJx9QaY6snzmugGwqUL4xLGeQPMis8 5do448JwGQryj++sl1rRy3PuTpx0hNdtYNRhBK62PZ3ZZ6lOLpHins8bV9jJgyryPrQ5 iPq8VPdSyJDZS9Pq8kItYe8JOaZhXEiGWXdKLiglGQFjW7Rc0vHz3gkUticCghyVQxwG C0yQ7HIP86AqoO8F4KRI14qwsTgInhQ91IFzB0zXp6wKqo4X3Elec19Rxu5n6NEZlBwe a89w== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; fh=GeYAnZnQ/hHVwF5xM/bbpAEr03LDLLn0NlNLYifVRZ0=; b=H4EGRVdgjIZC6OXxHVVhMK6yZ/9G+paQmkjKMCYCwru9R4rv3uzZ90cUaS6kQmNAhU OGCaTESK9Z6eV28IPGi7LNiewAIdKyjFcy85Al8R9p4uDei5WnBage+OGavEkatVyBJb 3mpxXLD2xr2wR6wOxaC8VxKK34UDBQOe/+pGgLAnKOM/EN99xW3sjn7A9abPT9H8wwai 96VCHxSgLog2mz/O9hGGmXRo7WV93JE+7VTSN7nmr7mCl1SXqGvehd+jy9avXbG2zsAl HQRwi35WZNPhUlPS5u7r6h5CQE7PwxDTXbKWh+SLfFuwU1HSi+6gXD7wmyztsuVFszTx EdJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YNQGE7Zb; 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-45f01d28d74si12386741cf.438.2024.10.08.09.48.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Oct 2024 09:48:30 -0700 (PDT) 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=YNQGE7Zb; 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 1syDMi-0003C3-NL; Tue, 08 Oct 2024 12:47:16 -0400 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 1syDMh-0003B2-HQ for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syDMf-000390-Js for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-37d1eda8c7cso1638444f8f.3 for ; Tue, 08 Oct 2024 09:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728406032; x=1729010832; 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=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; b=YNQGE7Zbz67MiS/QVL2ytaCx7GyldhJe9dMQ4s+pcCAokwb4hgUGFzHC4c58bnDn0J JZ+vGUfjKr4quuIP7F7QGs0JBliSRSZRhNS4g2KVb2nLLVgt3A2mo+Va1hkgvZREABXU TqChSGruzc1mZcGwektoSC7tETQqX8uUVce7Mi33RIhbNnWadEqZVjj1BJoEAAeUWuIS VNwjQaWmvBPbimVXtPUDFtgp8sfNGE+RY8JtIkzCwB7AgWncV6dbn/YDuteZSPBBA7i6 h0gh/PvrUShHuwSBM6blqeQrstS8iH0mXk/grisn0z0QmuFyiJQ5htC5RAW91G4Qelxb DSsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406032; x=1729010832; 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=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; b=WKiIFgJsAIRA2q2oktAMYkQTSqAOEQKhc5q7GCWMv3oHD+u1b03ujGzvjZAfzMCjrv oDZJwQ44tkev9Sd1sd/ICDeFoqAml9Vcvf9c61pzaZs3JpYp/FLEOnHMooM0FFoIv4go MAPg2Ki3RAxOM8pQXKZp1kGWCDCjgAkEpf77b0UcdUJQF0W9llOkdYBrt7tzx9xmUAH0 s1QMW4bnb+Zwu+MtGZJklIlPNHYgDFeYUb5vvXHwP11Zc0woj2AlJkj1rV5lV2hiT+k1 9nILD7Nxht5buOGym24WyNW15jf33sQ5azmzoV5jHHnWQCruZxKshIxKC7Tff6616Mys 5LuA== X-Gm-Message-State: AOJu0YzyF4EBorzAEBPDkz0xnKwmFvxV5SfKxaU+K9aogA9DhCO1Kd/G LxcHSJbBdSZY0DAkXDp5Miji7veC2GnmauovZof/JQ4eH0cBgi4xDg2ORC0NZU6QhQcTc/LiEBK O X-Received: by 2002:a5d:5c87:0:b0:37d:2e78:8875 with SMTP id ffacd0b85a97d-37d2e78a2a4mr1470394f8f.56.1728406032104; Tue, 08 Oct 2024 09:47:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d32ea1d98sm1490936f8f.68.2024.10.08.09.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:47:11 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Stefan Weil Subject: [PATCH v2 4/4] block/vdi.c: Make SECTOR_SIZE constant 64-bits Date: Tue, 8 Oct 2024 17:47:08 +0100 Message-Id: <20241008164708.2966400-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008164708.2966400-1-peter.maydell@linaro.org> References: <20241008164708.2966400-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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=unavailable 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 Make the VDI SECTOR_SIZE define be a 64-bit constant; this matches how we define BDRV_SECTOR_SIZE. The benefit is that it means that we don't need to carefully cast to 64-bits when doing operations like "n_sectors * SECTOR_SIZE" to avoid doing a 32x32->32 multiply, which might overflow, and which Coverity and other static analysers tend to warn about. The specific potential overflow Coverity is highlighting is the one at the end of vdi_co_pwritev() where we write out n_sectors sectors to the block map. This is very unlikely to actually overflow, since the block map has 4 bytes per block and the maximum number of blocks in the image must fit into a 32-bit integer. So this commit is not fixing a real-world bug. An inspection of all the places currently using SECTOR_SIZE in the file shows none which care about the change in its type, except for one call to error_setg() which needs the format string adjusting. Resolves: Coverity CID 1508076 Suggested-by: Kevin Wolf --- v1->v2: v1 just added the (uint64_t) cast for the specific issue that Coverity was warning about; v2 is entirely different and takes the approach Kevin suggested in review on v1. --- block/vdi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 149e15c8314..26f7638f1fc 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -87,7 +87,7 @@ /* Command line option for static images. */ #define BLOCK_OPT_STATIC "static" -#define SECTOR_SIZE 512 +#define SECTOR_SIZE 512ULL #define DEFAULT_CLUSTER_SIZE 1048576 /* Note: can't use 1 * MiB, because it's passed to stringify() */ @@ -442,7 +442,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } else if (header.sector_size != SECTOR_SIZE) { error_setg(errp, "unsupported VDI image (sector size %" PRIu32 - " is not %u)", header.sector_size, SECTOR_SIZE); + " is not %llu)", header.sector_size, SECTOR_SIZE); ret = -ENOTSUP; goto fail; } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {