From nobody Mon May 13 05:02:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602473791; cv=none; d=zohomail.com; s=zohoarc; b=HVQc7e5jPNQqpa9SWPg7Bw4tGD2F0npFKXEOCGLydbUScy1vfhV8KYXcGAe//jteq4X9rWf8Bm4jTNpAZ4rGgwuX8kv4ZffTgsHfBcKo1FGHIWOICG8pzQ9IPS6JmjDqXyjv+TL9DINdqzYwKM1kVB3yjipH9NF1Nf9TMOWSFWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602473791; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fpHisvGdMfu2rLolCV/TUlcZ1mNSmd8f85VTiCWgp/8=; b=NeYruKYZrPEJpBrojbHOVj09VLtzMC4/92vDQRYrdCF+ItEAxCpMdd+///aFpTIvsXJ5oke30A8TvMjZ6Ky57V+8gcUgXLZYNOYiWe3PiOx3+FWnu6pb4V86HT66vOdJPPq1/BRhXjUs3eQAei44+spnjzpfmtyhGrJ6MNwrAyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602473791542664.7364330543118; Sun, 11 Oct 2020 20:36:31 -0700 (PDT) Received: from localhost ([::1]:40070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kRodS-0002kK-4Z for importer@patchew.org; Sun, 11 Oct 2020 23:36:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kRocO-0001tl-K3 for qemu-devel@nongnu.org; Sun, 11 Oct 2020 23:35:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kRocM-0001u5-7r for qemu-devel@nongnu.org; Sun, 11 Oct 2020 23:35:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466--JjOiOXdM0aSYkLBP-Jx_w-1; Sun, 11 Oct 2020 23:35:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F930425D5; Mon, 12 Oct 2020 03:35:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-119-55.rdu2.redhat.com [10.10.119.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB449709BB; Mon, 12 Oct 2020 03:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602473721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fpHisvGdMfu2rLolCV/TUlcZ1mNSmd8f85VTiCWgp/8=; b=Fk/HSFS6rrR3/i3niqdrGTww19oqJgcfikmrxpCAjYpqz8c7KSJzqWQC2Bsb1QG/rhFzca tcrbbOp62rBVDJ4kF1N4FNerosCo4rbR9oYkUnwq+H8xA9tgO/fbuuoOB++StUvpWgmMzC /zPk2bqHdmVKdGmi9AU73ZEbaRyGiZc= X-MC-Unique: -JjOiOXdM0aSYkLBP-Jx_w-1 From: Cleber Rosa To: qemu-devel@nongnu.org Subject: [PATCH 1/1] hw/i386: prevent crash when an invalid number of dies is given Date: Sun, 11 Oct 2020 23:35:07 -0400 Message-Id: <20201012033507.906096-2-crosa@redhat.com> In-Reply-To: <20201012033507.906096-1-crosa@redhat.com> References: <20201012033507.906096-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=crosa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=crosa@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/11 21:16:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.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_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Beraldo Leal , "Michael S. Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Wainer dos Santos Moschetta , Willian Rampazzo , Cleber Rosa , Paolo Bonzini , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When parsing the topology, the right default value of 1 is given to dies, but if an invalid number such as 0 is given, QEMU will crash with a floating point exception. The alternative approach is to silently set dies to a valid value, as it's done with cores and threads. Signed-off-by: Cleber Rosa Reviewed-by: Willian Rampazzo --- hw/i386/pc.c | 5 +++++ tests/acceptance/cpu_topology_dies.py | 31 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/acceptance/cpu_topology_dies.py diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e87be5d29a..209e44663d 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -713,6 +713,11 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); =20 + if (dies <=3D 0) { + error_report("Invalid CPU topology: dies must be 1 or greater"= ); + exit(1); + } + /* compute missing values, prefer sockets over cores over threads = */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; diff --git a/tests/acceptance/cpu_topology_dies.py b/tests/acceptance/cpu_t= opology_dies.py new file mode 100644 index 0000000000..d73b7b30a2 --- /dev/null +++ b/tests/acceptance/cpu_topology_dies.py @@ -0,0 +1,31 @@ +# Check for crash when using invalid dies value for -smp +# +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Cleber Rosa +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. +from avocado_qemu import Test + +class CPUTolopogyDies(Test): + """ + :avocado: tags=3Darch:x86_64 + :avocado: tags=3Dmachine:pc + """ + def test_invalid(self): + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=3D0') + self.vm.set_qmp_monitor(enabled=3DFalse) + self.vm.launch() + self.vm.wait() + self.assertEquals(self.vm.exitcode(), 1, "QEMU exit code should be= 1") + self.assertRegex(self.vm.get_log(), + r'Invalid CPU topology: dies must be 1 or greater= ') + + def test_valid(self): + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=3D1') + self.vm.launch() + self.vm.command('quit') + self.vm.wait() + self.assertEquals(self.vm.exitcode(), 0, "QEMU exit code should be= 0") --=20 2.25.4