From nobody Sun May 5 12:10:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1579113908; cv=none; d=zohomail.com; s=zohoarc; b=NOMXibcmUHbRItS4F1cAaPNVO5KPblWExT1TnH3HMwgouvEVDuOmRHxAioP1BblNi8M5+FlmGtr1sNGrjwYIvaja0YoW/PONrkmZqdqcma95iQ1ri8fmJ1LImZVnSXiG2d+qnU4ziT+AZO8k7Oz5xdKl8rxwH1Q7Sa2Q6juOqNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579113908; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9GWJYFF0Osdnh6pQc/SmAi+3NM80w4UDeyqr7AgIH+M=; b=YzLofqn9jnhhDTaymI7/LqUdebj+SaBFKIx+qvq84/Yver3T3X/QBQLtkF48d7Hcsfw5W+SjSW8koCcEGXGGJnTSMZPR3tvZO4Ywqm2Ab7TlH1NaOO5XxvFWOc30Rnf6PQuEULeC+jguSvuQGyWbeP77BMsk53tj9KfnjD9WCEw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1579113908669468.2860896079019; Wed, 15 Jan 2020 10:45:08 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1irneS-0001P5-Rk; Wed, 15 Jan 2020 18:44:24 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1irneR-0001Ow-NT for xen-devel@lists.xenproject.org; Wed, 15 Jan 2020 18:44:23 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0b6dd1fc-37c7-11ea-85e7-12813bfff9fa; Wed, 15 Jan 2020 18:44:22 +0000 (UTC) X-Inumbo-ID: 0b6dd1fc-37c7-11ea-85e7-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1579113862; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=r/ggpehdLKgSaftd0qaf+dm4Eaqs1+yXf/zW9P9T9dw=; b=LfBPVDVk6+7HqcsTCvc1C8GA6/VGq/ik46SfoLuDrWFFG6kTi0EMKv9s 6WkskCaW922bnc8ToaFMOUNms5l2X8UVvUmsPSFLFrSd6qFU8lHh/YM3o ophSlg10ABdOr+75Ardl5hx0eAwOrQ6ZBc4UVmIT+pnJ9K7wCj8bxHj9Y s=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: PxPYgF+JdwxJr6bJL5nqPxiDjRsfGp6oDakz4ZvUcTefXlrzzRk3l8FGJVsDNwUKUjjtymvP0l +l4r/vNhbp9dM7eo9njyM7u9VQcL0hDvw+zIWGkDO4NerysPdatnaQ0+Wka1JTKMpNpUiuoAI3 0aQDT0ghvylWDMHsmh6mAra6EZts3rw2OfiRxzdrrABRN/GSyN+gqM7VtHjIvBr2vNjrsHKHoY LJWzD9Ip2sASgX0aSUwpRjmLwM1OH4bjduO22Kdk4ymvx7h4XsAIltF10+KKbVuAIa1tybQAbH wY0= X-SBRS: 2.7 X-MesageID: 11393005 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,323,1574139600"; d="scan'208";a="11393005" From: Andrew Cooper To: Xen-devel Date: Wed, 15 Jan 2020 18:44:18 +0000 Message-ID: <20200115184418.21365-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Jan Beulich , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The BUG_ON() is confusing to follow. The (!is_idle_domain(d) || vcpu_id) p= art is a vestigial remnant of architectures poisioning idle_vcpu[0] with non-NU= LL pointers. Now that idle_vcpu[0] is NULL on all architectures, and d->max_vcpus specif= ied before vcpu_create() is called, we can properly range check the requested vcpu_id. Signed-off-by: Andrew Cooper Acked-by: Julien Grall Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk --- xen/common/domain.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 0b1103fdb2..ee3f9ffd3e 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -139,7 +139,19 @@ struct vcpu *vcpu_create(struct domain *d, unsigned in= t vcpu_id) { struct vcpu *v; =20 - BUG_ON((!is_idle_domain(d) || vcpu_id) && d->vcpu[vcpu_id]); + /* + * Sanity check some input expectations: + * - vcpu_id should be bounded by d->max_vcpus, and not previously + * allocated. + * - VCPUs should be tightly packed and allocated in ascending order, + * except for the idle domain which may vary based on PCPU numbering. + */ + if ( vcpu_id >=3D d->max_vcpus || d->vcpu[vcpu_id] || + (!is_idle_domain(d) && vcpu_id && !d->vcpu[vcpu_id - 1]) ) + { + ASSERT_UNREACHABLE(); + return NULL; + } =20 if ( (v =3D alloc_vcpu_struct(d)) =3D=3D NULL ) return NULL; --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel