From nobody Wed Nov 27 16:58:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1697575220; cv=none; d=zohomail.com; s=zohoarc; b=d+DHB9Oai177ieHKZ5sQCVQApQHeRMqNOaHpX50zwdfjT8Bc5pG2y8aWpQN3yRKVMWh2WDgpeOGer3mhI9nKWbDFBL7DfpbeVjFuwH6Bncmw16bPCCNuPrav5u0M9beGoYOsrI+Y/tsdSX6v/4Aof8Rsa6O6nUwOp/fXOApWzuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697575220; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h6k+g0B0Vg+QIBJMjs/o4gmlz5GREYx4idsrMCdF43s=; b=NLkzx3bbXpmLXdPke0r4zxyQCgKR7kTbg4uMSLX2hVXKzkoLqqZw+3ieKPV8WwB4+N7pSGZ+rPEgVXzcSyaa0kmOlx+KVYPxq4OoGZD4+UHVXmcP92n5NmK7mXJxKuACmpCxrtQ2xTAI2cedxWpb8Xi90nRwES18Vr7juK3H8XE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697575220227962.5436507076377; Tue, 17 Oct 2023 13:40:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsqqY-0007od-SW; Tue, 17 Oct 2023 16:39:22 -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 1qsqqX-0007oQ-JN for qemu-devel@nongnu.org; Tue, 17 Oct 2023 16:39:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsqqW-0003Nm-7x for qemu-devel@nongnu.org; Tue, 17 Oct 2023 16:39:21 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-sQ_NgseiPKKJG-v6tR9aOg-1; Tue, 17 Oct 2023 16:38:57 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7756d0fb11dso103480585a.0 for ; Tue, 17 Oct 2023 13:38:57 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id f9-20020a05620a408900b007677347e20asm940487qko.129.2023.10.17.13.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697575159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=h6k+g0B0Vg+QIBJMjs/o4gmlz5GREYx4idsrMCdF43s=; b=Z2uApEo9VPSUn0UHZPlg3Bce2+OkJc/zMeJ1Ixrxoj5wWwRSVgxqQZDPRsyXJYiCHCkiKG tehHLhsUQkqIC8mCbF/K4lsNZhidoBXnQBD6fVuZu8+aNrLnOykXRifH4PgVSEpoMasnOr /zBPSwTT1r5VqXf9jmrBzMQqdSzuHag= X-MC-Unique: sQ_NgseiPKKJG-v6tR9aOg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575137; x=1698179937; 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=h6k+g0B0Vg+QIBJMjs/o4gmlz5GREYx4idsrMCdF43s=; b=G52dkPQsAIS8a1BW80Y0BsshQ3UjNOOW+KSPs6sucYL2CZgE+y2bziJbAOMEg9aTLL 5wIpezxjUbFvv0YqbwnHsh12JvPh6NwS3l1JyBc3nj61EQi2+QWl7YVDZYLbF1gbeti7 hYySZqcrRS/CC4LGNlTzDeLH68faekCe5jOZrTmx153pTMEKiG0d1jKGPPDnxp2Kydib +CtLqVJJrs+DDiC4dgK4T3geCYrfB2re3ygU473Ahx1QRioc2GWSnyKqQSw43k7V3n22 aknTjobjnw+6WMt4JSY/s/QnKT8zm61cVBBKz2UOV1YV3TOfeOTYZBQuJU3uPt6zRkL7 VvsQ== X-Gm-Message-State: AOJu0YyfVDAIKW4bts/6VkcPQTy2t+1kbnQOhB952k/Qg17i42/ZQatv HAgbarbuziAQNmFp+RpcsVBNZ6sgm86uP/D1d5UNtPWBdLi5wIIFstvt0dyndKinAvOCxaiZu9W +qaQ8RWQe9oodp11d0hg9naPZ52UB/BTvSx/ogdLBrITFwTV7xXtRCMzME7b4jdJ22sIm05CL X-Received: by 2002:a05:620a:488a:b0:76e:f686:cad5 with SMTP id ea10-20020a05620a488a00b0076ef686cad5mr3517124qkb.5.1697575136998; Tue, 17 Oct 2023 13:38:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi7j8k4uZfk5/FemQxyBrcixsVxxOrCeCE2qwEy5b8VlOiT1nMp9NWaMTyIJOVU7pHER5fag== X-Received: by 2002:a05:620a:488a:b0:76e:f686:cad5 with SMTP id ea10-20020a05620a488a00b0076ef686cad5mr3517113qkb.5.1697575136687; Tue, 17 Oct 2023 13:38:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Fabiano Rosas , peterx@redhat.com Subject: [PATCH] migration: Fix parse_ramblock() on overwritten retvals Date: Tue, 17 Oct 2023 16:38:55 -0400 Message-ID: <20231017203855.298260-1-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697575220659100003 Content-Type: text/plain; charset="utf-8" It's possible that some errors can be overwritten with success retval later on, and then ignored. Always capture all errors and report. Reported by Coverity 1522861, but actually I spot one more in the same function. Fixes: CID 1522861 Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas Reviewed-by: Juan Quintela --- migration/ram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c844151ee9..d8bdb53a8f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *bloc= k, ram_addr_t length) ret =3D qemu_ram_resize(block, length, &local_err); if (local_err) { error_report_err(local_err); + assert(ret < 0); + return ret; } } /* For postcopy we need to check hugepage sizes match */ @@ -3898,7 +3900,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *bloc= k, ram_addr_t length) error_report("Mismatched RAM page size %s " "(local) %zd !=3D %" PRId64, block->idstr, block->page_size, remote_page_size); - ret =3D -EINVAL; + return -EINVAL; } } if (migrate_ignore_shared()) { @@ -3908,7 +3910,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *bloc= k, ram_addr_t length) error_report("Mismatched GPAs for block %s " "%" PRId64 "!=3D %" PRId64, block->idstr, (uint64_t)addr, (uint64_t)block->mr->addr); - ret =3D -EINVAL; + return -EINVAL; } } ret =3D rdma_block_notification_handle(f, block->idstr); --=20 2.41.0