From patchwork Wed Jul 31 14:36:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 815650 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp773115wrs; Wed, 31 Jul 2024 07:37:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXA6xyTzxgwwDmpZd+qxH03AGYZbt+ESo4XU7d7C4TbtmcaLgWNaubs8DVWq+BZVzdNbHB48Rwwgq8lv7rIk3zr X-Google-Smtp-Source: AGHT+IF+dsJJ++JqEi0s90hJ4bU/H6JmkluVTjthX8IcQPcTi1fwwZxF16I8fqeZGrMgOcTz66r2 X-Received: by 2002:a05:6214:d88:b0:6b5:44e4:eb3f with SMTP id 6a1803df08f44-6bb55ac9a7amr159262416d6.47.1722436631027; Wed, 31 Jul 2024 07:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722436631; cv=none; d=google.com; s=arc-20160816; b=PohmsrPTLCRo3maKwYn/BYj6bHsR0Jqj7a610BKIclLbV5rrrWo1Q97HyqnXw+Z/9J ioFOQLmb+bQyuEtIpAlIBkmKB3hRvZFcU11zM1eIQ8+A/7uu0TLmKsuhuC1sZ6sIboCG ngDUBrZe025egfcAee6UFmfO/EuB6OOxgMnUICZjivSgLUkPBvkqVWTRFAqZ9GnlRYr1 fb+t2TxVHo/Jd3X0KCcqdtLRjpcygCtTkOLtrHXSmjWH3xKKMMaq2GoMmZFE1s2DgcNG cAhxBipn0LtB5NtminCFwIPBmmIRlm2uTgV0igYd6/zji9XRCDK8yFXZF08zoQJrRTR1 qc3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=S/NRApmVNAaLyyg+o5au71Qdmh5VzyMeuC289IBc2d8=; fh=5quBhmNe3tsEAdid5ZAgwbHv9gtP/oew6yvM24yBrbo=; b=yEMcehffney3h1twf5Qc4UTkshvG86hhN3itFDtOlnPWjBXAwQ2gZVcgas/gXw5Pkh HK69Pt0B9RxK23/I2sTmnS46aN1AGC1QVFhWDznxfFDwd0qgerQiTO8DJo5HMPQl4v8N BUKiZPA8N1x+9kc6Haf4awstPICkG6jUgtEdSfwXsm/ckL9U1JYg0XlX5yEw0LE5ubgg V53/oXmWay1nd+vhdLiiY/GD1b7ufcXu5IKhJHO+Dana8++Ta8u3PZtU+OKAeIb/cDGz KzsE35UdUwezpPgDDoouWTkS6gSv2NQjmphY+k9Kr3LTAFeEiADtbMhSYxaNnzK/hVHj koeA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SVOx+D2r; 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 6a1803df08f44-6bb3f8cbcf5si149311956d6.27.2024.07.31.07.37.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2024 07:37:10 -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=SVOx+D2r; 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 1sZARL-0004cv-PX; Wed, 31 Jul 2024 10:36:31 -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 1sZARE-0004Q4-1i for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:24 -0400 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 1sZARB-0002dr-Q9 for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:23 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4266f3e0df8so36152345e9.2 for ; Wed, 31 Jul 2024 07:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722436579; x=1723041379; 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=S/NRApmVNAaLyyg+o5au71Qdmh5VzyMeuC289IBc2d8=; b=SVOx+D2rLsj2MpTsOItsfhDCFQSbOJYPlJy700gyDVG0/FnHCVTJBwfDPalwpgMY+u P4Rp2tEUV8XxPshxn/ppqtWniau6FSpayYCPLyl/QQo0yX+HjurXe5HuAZSyzFYK7gH0 ZHFPU/Ymog4taYR52LLCS2Mh8ngfJJ8w1bdbjBZnHJ7GkGh1nDcb08m4INAGb+/pJ84G Gfpp9rKMFLj2SzjN0q20V7DfzQ2P9dM+cNjXINb/fsNrYMUGv6P2wmLfAJwVGaA6wSje TAAHgpJGX2EzLET4/Wr1BFDLbitS04K2S90ml3rE3sFr7EmDmogdI6QSLnSUuDjG/JlS ESMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722436579; x=1723041379; 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=S/NRApmVNAaLyyg+o5au71Qdmh5VzyMeuC289IBc2d8=; b=VKGSrMsEjDglL24AZ6OtEvQKQJIgqL8i28JwLBzPN2aQ1BjH/X6plFZKzW59muniJS gSq/znrZRzzQ3Kk273YuvwmQzv79ujz5C8gABLd+ukwtMsV6SRCyNGH1aV+yoqhWcgev 1VDPtj2UDijxdRylPW+C65CLBFIAV+rUvqfIpj5jfzn3Z9EuMLREfKl3sSxnlmTWRzzC wwvKMl0CCNwoeMxR/L1dX/mk23gwt3lu+70GSAC8wjlPMziCpowb39U1MKxB9BY9d5tQ EbI5qFz67bJPgLfFJu5j4wCd2hNruPGsP7ap4xjmummSkfCmFFSbqduKCoh1I7TRwi2u 8JfQ== X-Gm-Message-State: AOJu0Yy0Z2VGoWdzaswMRH5It6BKp5qQA/CtLs4+inJyYbVLR7Y4nd1w 1v4bj6av9C7WpX2b/db4Axz9rvfzeaSTAqf+Pq1Jr9V01OdmwsKPhDhofzzIhL/jGxmUo9cit6+ I X-Received: by 2002:a05:600c:4ec6:b0:428:1eff:78ec with SMTP id 5b1f17b1804b1-4281eff7a44mr69278435e9.18.1722436579541; Wed, 31 Jul 2024 07:36:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4282b89a86dsm23976025e9.1.2024.07.31.07.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 07:36:19 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , John Snow , Stefan Weil , "Richard W.M. Jones" , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org Subject: [PATCH 1/7] block/vdi.c: Avoid potential overflow when calculating size of write Date: Wed, 31 Jul 2024 15:36:11 +0100 Message-Id: <20240731143617.3391947-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731143617.3391947-1-peter.maydell@linaro.org> References: <20240731143617.3391947-1-peter.maydell@linaro.org> MIME-Version: 1.0 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=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 In vdi_co_pwritev() we multiply a sector count by SECTOR_SIZE to get the size to write in bytes. Coverity notes that this means that we do the multiply as a 32x32->32 multiply before converting to 64 bits, which has the potential to overflow. This is very unlikely to happen, 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. But we can keep Coverity happy by including a cast so we do a 64-bit multiply here. Resolves: Coverity CID 1508076 Signed-off-by: Peter Maydell Reviewed-by: Stefan Weil --- block/vdi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/vdi.c b/block/vdi.c index 6363da08cee..27c60ba18d0 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -728,7 +728,7 @@ nonallocating_write: logout("will write %u block map sectors starting from entry %u\n", n_sectors, bmap_first); ret = bdrv_co_pwrite(bs->file, bmap_offset * SECTOR_SIZE, - n_sectors * SECTOR_SIZE, base, 0); + n_sectors * (uint64_t)SECTOR_SIZE, base, 0); } return ret;