From patchwork Wed Jan 15 18:44:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11335557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8615092A for ; Wed, 15 Jan 2020 18:45:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 622FB20728 for ; Wed, 15 Jan 2020 18:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="LfBPVDVk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 622FB20728 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 0b6dd1fc-37c7-11ea-85e7-12813bfff9fa 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) 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 (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_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The BUG_ON() is confusing to follow. The (!is_idle_domain(d) || vcpu_id) part is a vestigial remnant of architectures poisioning idle_vcpu[0] with non-NULL pointers. Now that idle_vcpu[0] is NULL on all architectures, and d->max_vcpus specified before vcpu_create() is called, we can properly range check the requested vcpu_id. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Acked-by: Julien Grall --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné 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 int vcpu_id) { struct vcpu *v; - 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 >= d->max_vcpus || d->vcpu[vcpu_id] || + (!is_idle_domain(d) && vcpu_id && !d->vcpu[vcpu_id - 1]) ) + { + ASSERT_UNREACHABLE(); + return NULL; + } if ( (v = alloc_vcpu_struct(d)) == NULL ) return NULL;