From patchwork Thu Jul 21 11:52:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 592132 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp387388mab; Thu, 21 Jul 2022 04:53:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tvd0e0TnR1G6CiQdAWJKtWqh/XAM1sG8E5Sf9BVWjPPQi7j2IajpDGFdE3Stt39BebYk7q X-Received: by 2002:a37:a9d1:0:b0:6b5:e060:7098 with SMTP id s200-20020a37a9d1000000b006b5e0607098mr16150288qke.585.1658404399998; Thu, 21 Jul 2022 04:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658404399; cv=none; d=google.com; s=arc-20160816; b=0CgcEU9niQfpS/VhFqOXJHxVNR3z2sHic/LD6wepssGeHpRZ2+raQZ4ybi5m59BSqh RGGhOPzSGZGAcfuNDjsOIzTnnCW8sy8QW8Mi4IzoEyd2cOHSS8VsqcbylLbC5f7zWV8r 5WxdwS8gu6LEZK96tlxkEkpZO0KHxpKW8wlW/stx4Ao/CnfcXv3H1BVRazny2f78RO54 c/5UXyQ/6puAI+myZk4u9+uT8LG6sJY9AlhCaIkz4qxVJseHtAwJ6c1F33eZqcZhRz3w wqF90ZFINbn8b4YXvlJi9quKfU21T+TGqApRUVeHt1v2ra86Wp84vMtTrprmBIUHqZzm c50Q== 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=R4+PLxWALGlxDrGlf+LhFDgNwdQnyQgdmck8BMB4PZY=; b=wcdDqx/F1t2emlzmR4xd5iZeVFgFjoRQ7b2pGIowA73tLfRyOU0u552sHXfnQUSdih TtU4K4z19vM2adr2d8zuihnFdZ6aZ8gR2cWlYmcZKW9VX7ll3/ueOHXOU4h+VtlDJQC9 u22cuynB2XJ3jrhzmxnymyM5dJBp2s/BXeghcGUHk2D4cKiAmhSv/jobVJ6MQmyLkzbU ZmJpAPB0WPRzIcPb4YaGMnnawMQF8OpsoQ8TKmMqwU/tFpSLdWiLcpeaRSCEhnr+W4zJ mhQYGNuD9A2ySzSRJjb9w7sEuj0xLxKGQ6SK7tEE8v/T4Yw5UQV6yD/rYTFusyvdV6RG 9mkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qGO7YMhD; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t14-20020a05620a450e00b006b575adb2easi1255599qkp.60.2022.07.21.04.53.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Jul 2022 04:53:19 -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=qGO7YMhD; 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 Received: from localhost ([::1]:36710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEUk3-0005uu-Kw for patch@linaro.org; Thu, 21 Jul 2022 07:53:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEUj2-0005uT-Hg for qemu-devel@nongnu.org; Thu, 21 Jul 2022 07:52:16 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:33428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oEUiz-0006Y4-Oj for qemu-devel@nongnu.org; Thu, 21 Jul 2022 07:52:15 -0400 Received: by mail-wr1-x42d.google.com with SMTP id h9so1944366wrm.0 for ; Thu, 21 Jul 2022 04:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R4+PLxWALGlxDrGlf+LhFDgNwdQnyQgdmck8BMB4PZY=; b=qGO7YMhDnW/pVmXM91IpEi11rTA8TZrtP56SZwz4NOgEmGnvWHGeleZV4bU1+vAaVQ XfgsaBxvi7+Gn04ctoLXVMrfJWMuYMrtHQPJAgvlpr1qsk/Q5pn1hDHzVwxu1UJKGutI LGwruyMUV/fkMelrMRudmXOBNPAAEzQS5Ra5XSII+pPcVxEtwZ+AD5mTN+6erxNRSxqM bU+AsMvMRKfYcoImp95M6WSXgf3wh2ABJh7Nrw2GiDAd4r49CoOsGhaW2OepXMX6bxWF a7T3Elvx5ZrDt95QXHkYtixIhCh20Vcw2LZARfUyUkYWcQ8bs+wH2yXsg0ptoge7rf/L Bz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4+PLxWALGlxDrGlf+LhFDgNwdQnyQgdmck8BMB4PZY=; b=R1L3d5rivJzYQoJikVkKks3odj621y5BzYgjV3G6igoMbWHaHxP81nHWYS7m0y0Nay Ky0lqRuG3Ctw3PGNPaTf7mRsslReys0VvXRGyXnoowP2RXiOnvGybvHLk0bR7St6rtMg csb8AKI+editx8JLsW3yCc5ZbF6zcxcOu9Kp8n3zjrJjYqCKvPFAbWSbD/8rEhmyY3mR DT5xOA5/g9VYcGLvpxnlZ/I0LIjw55l1g05iZSpD7VvK0fUO9zuM3ReJy0zvRNg8kqDR WN4dmkDBw1GarQ8nOGfRBvA7P/1h3Au9XKUpJFh8Ao5eTotb840siGFsz5QAWepW/Nmc AT6w== X-Gm-Message-State: AJIora//ttYa5+TgQsJtKQPO1UyEPfrQzxAD6+Qjczmik0UUm4+6GEt6 AvFGSN10sNQ6WF7vS3JxwRSDzXbb6EESBw== X-Received: by 2002:a05:6000:702:b0:21d:7f65:f1b5 with SMTP id bs2-20020a056000070200b0021d7f65f1b5mr34092781wrb.555.1658404332023; Thu, 21 Jul 2022 04:52:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l18-20020a05600c1d1200b003a04d19dab3sm11772745wms.3.2022.07.21.04.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 04:52:11 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Juan Quintela , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 1/2] migration: Assert that migrate_multifd_compression() returns an in-range value Date: Thu, 21 Jul 2022 12:52:06 +0100 Message-Id: <20220721115207.729615-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721115207.729615-1-peter.maydell@linaro.org> References: <20220721115207.729615-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.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, T_SCC_BODY_TEXT_LINE=-0.01 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" Coverity complains that when we use the return value from migrate_multifd_compression() as an array index: multifd_recv_state->ops = multifd_ops[migrate_multifd_compression()]; that this might overrun the array (which is declared to have size MULTIFD_COMPRESSION__MAX). This is because the function return type is MultiFDCompression, which is an autogenerated enum. The code generator includes the "one greater than the maximum possible value" MULTIFD_COMPRESSION__MAX in the enum, even though this is not actually a valid value for the enum, and this makes Coverity think that migrate_multifd_compression() could return that __MAX value and index off the end of the array. Suppress the Coverity error by asserting that the value we're going to return is within range. Resolves: Coverity CID 1487239, 1487254 Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- migration/migration.c | 1 + 1 file changed, 1 insertion(+) diff --git a/migration/migration.c b/migration/migration.c index e03f698a3ca..befd4c58a69 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2617,6 +2617,7 @@ MultiFDCompression migrate_multifd_compression(void) s = migrate_get_current(); + assert(s->parameters.multifd_compression < MULTIFD_COMPRESSION__MAX); return s->parameters.multifd_compression; } From patchwork Thu Jul 21 11:52:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 592130 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp387287mab; Thu, 21 Jul 2022 04:53:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sEYfcLfpHVIYoWfHv2yW+zmqXU9zxCHKUNUhFUu26dX9T70THmheyOWw+5XkrCGJKxvoPb X-Received: by 2002:a05:6214:cac:b0:474:7d2:3d41 with SMTP id s12-20020a0562140cac00b0047407d23d41mr5177049qvs.98.1658404390362; Thu, 21 Jul 2022 04:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658404390; cv=none; d=google.com; s=arc-20160816; b=MLWSl6KtRpBglvRRHhDYcb1cowtgn1FR3Y7ayYe9E22otQuJAaseG5CmCyGMi7lax7 YPQUnnjI91s2dwzjva9FRVnAQfujUVD3H2llIJeSOYDewL4cfdaE6tCycBGEr0hWslLv E0oE+ncgjDgxGiAKTaBMsPLnvoJjtk4GccncAfL0ykckj3UAGzxGLLN8deU/ZqUkcp3V 5sbVSwXCKbFJPneJc9TEFbEgD0jAcNGhuYnPPd9VYdQ5pLGJwhLMF995HZWoNHfQVMK5 slyIQn2EDoQ8K8AX8L/T+YlLMGJxoXY45ozv6iXeju14plSpU+gEgL/M1rsi/prUlXM9 WzDg== 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=PxJwjVAzbS0o6r9Gh4EM7dFWlXeZcq5sXf7+Lmnjej4=; b=JgzsvLj0UBp9KetrXPjYjNFhuTRbmo+Yav0vBUWGaT11Vz5WQcK14ih+V/hZc+Jlp9 PJaSYjrpX+jfjytxoBgWsp52Q9hc8ME2AqA7kvJnbr0FctJWiwgBDaWK6Rfucg99TwcZ f9sNVTWdhMmS4hmnTaXnFY3KA3yvBIS1MlkJLNIadwM7dGYjfZ3Ij4H5Zht1Fcr35S7+ KEoW3S7WLUJE7H+hru73h9wjRojdX6au4eMUcjOVYneGa1/7hII9mIoFVF4jOPBEuF5B +UJMgCQp35fEzFcNa77hECu2xUBbsQYdZXnw23FriQ3siHmLgbz4YkiZ7r7Ci3XKGjP6 ohQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JAlrrGIh; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k14-20020ac8140e000000b00318e15694fcsi955207qtj.619.2022.07.21.04.53.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Jul 2022 04:53: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=JAlrrGIh; 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 Received: from localhost ([::1]:36758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEUjt-0005wV-T3 for patch@linaro.org; Thu, 21 Jul 2022 07:53:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEUj3-0005uk-79 for qemu-devel@nongnu.org; Thu, 21 Jul 2022 07:52:17 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:47085) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oEUj0-0006YS-BV for qemu-devel@nongnu.org; Thu, 21 Jul 2022 07:52:16 -0400 Received: by mail-wr1-x434.google.com with SMTP id z13so1869787wro.13 for ; Thu, 21 Jul 2022 04:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PxJwjVAzbS0o6r9Gh4EM7dFWlXeZcq5sXf7+Lmnjej4=; b=JAlrrGIhijtxWfz2ZGXU1tU9NQqC6Mus2tb/9erwjDra90zriFK4jWhHTRa8f0RR18 6xFcD/uNm1xjwRDVKym0toUF21QunzYNcR8/EBQ/iYLDNVFvaT6Fs5I0bIfjzmFT1EHB HFe8x5I9CS4PlvF+mT+U3E8AMN5dcoD45m+/ld1MEbJN9ZQTjXbMo3J4hEqd7O5jCxjM Mo+mRHohEqPJs4WfTEOa1txasr7u02DsIj0k7KmAMJa+odhgT29962XTLeZ54IcgZmVo UHVbqZ3ZM5H9axyMtfJ6NiXQZtaz1KfWAhaArTHY0p5aKVohHqPYtYx5CKfJ8aBIcky2 Xwfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PxJwjVAzbS0o6r9Gh4EM7dFWlXeZcq5sXf7+Lmnjej4=; b=S6TuTMJsbaOo92khFXn29vqCEJRgxKnanHQdYs8APOnGuU+5xxRY/slOWxD3QDzYsg PYiCYGfqtta3RB2LMFHOXxOtjNHMJtxIfANiwe43b4aln9IqxXZW7rqrz4otgUX0B9P0 TVyQST47vmoXKYIGnOGzh25hPp0uMlCSWToKApgUso/Snm2Gy5yiENn5PbHI+vpm67U7 iO9dwOK4lPfp7ogYEKFb2J8joQTXacfxh+i72M726EQQmoFQY2mcqo5pf9bG+lG9+te2 j+ID2VRGq0dAq76vmae87K3YdemY1ofzLW4RniKwYpMCgi5g8leTo63CgS5X+YyZSfHW Sy3w== X-Gm-Message-State: AJIora9cLqk7yeFh7A88TsGgSxgABkhOp9DLGvlE448fOq/HdkNDPzwx XRqjHB4XG966y4XlgUuJuHTjnMtoZg/5Aw== X-Received: by 2002:a5d:64c2:0:b0:21e:2e1b:d031 with SMTP id f2-20020a5d64c2000000b0021e2e1bd031mr10664854wri.8.1658404332957; Thu, 21 Jul 2022 04:52:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id l18-20020a05600c1d1200b003a04d19dab3sm11772745wms.3.2022.07.21.04.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 04:52:12 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Juan Quintela , Fam Zheng , Stefan Hajnoczi Subject: [PATCH 2/2] migration: Define BLK_MIG_BLOCK_SIZE as unsigned long long Date: Thu, 21 Jul 2022 12:52:07 +0100 Message-Id: <20220721115207.729615-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721115207.729615-1-peter.maydell@linaro.org> References: <20220721115207.729615-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.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, T_SCC_BODY_TEXT_LINE=-0.01 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" When we use BLK_MIG_BLOCK_SIZE in expressions like block_mig_state.submitted * BLK_MIG_BLOCK_SIZE, this multiplication is done as 32 bits, because both operands are 32 bits. Coverity complains about possible overflows because we then accumulate that into a 64 bit variable. Define BLK_MIG_BLOCK_SIZE as unsigned long long using the ULL suffix. The only two current uses of it with this problem are both in block_save_pending(), so we could just cast to uint64_t there, but using the ULL suffix is simpler and ensures that we don't accidentally introduce new variants of the same issue in future. Resolves: Coverity CID 1487136, 1487175 Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- I haven't tried to analyse the code to see if the multiplications could ever actually end up overflowing, but I would assume probably not. migration/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/block.c b/migration/block.c index 9e5aae58982..3577c815a94 100644 --- a/migration/block.c +++ b/migration/block.c @@ -28,7 +28,7 @@ #include "sysemu/block-backend.h" #include "trace.h" -#define BLK_MIG_BLOCK_SIZE (1 << 20) +#define BLK_MIG_BLOCK_SIZE (1ULL << 20) #define BDRV_SECTORS_PER_DIRTY_CHUNK (BLK_MIG_BLOCK_SIZE >> BDRV_SECTOR_BITS) #define BLK_MIG_FLAG_DEVICE_BLOCK 0x01