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; }