From nobody Mon Nov 23 22:39:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1792772284; cv=none; d=zohomail.com; s=zohoarc; b=MW8Zczkf1ttKVvyNJujO+5tt/FMti518Mm9XR/qjWK+uX9SM5bGPHdVrrizUntn3rMrhTzvo+jHZUz6rucNjK7AHw/9TgsDA9Mk4+Svkg36XuG5DYVmacQxWh0FJvqqymAfBbT4nMSgKS6HCyHRBcHaWdwp7MhmxbOTckMcxg+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792772284; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=91d6mOvZPpjsKDXzz8mQfsrDndJawH+XacKy+EAZdP8=; b=SO95h7ujTtZIjbsTHgP4eYF+Hg2Btg4gg0TITmf6mtHPe2Zu0cLJQL+3ABnk3PLo6hTKT1kW5IrZaYNuxU01aaOw70qh0BarUxZMh8uyac6kw+KviZrvJABv6uvY1XTnFexE9ZD//45GApiQ3ZhIYg0DcU6PX1Ko1UXc6NswcXw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1792772284550641.7708651667804; Fri, 23 Oct 2026 09:18:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1459512.1671392 (Exim 4.92) (envelope-from ) id 1xKHxi-00038o-BQ; Fri, 23 Oct 2026 16:17:46 +0000 Received: by outflank-mailman (output) from mailman id 1459512.1671392; Fri, 23 Oct 2026 16:17:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xKHxi-00038h-8x; Fri, 23 Oct 2026 16:17:46 +0000 Received: by outflank-mailman (input) for mailman id 1459512; Fri, 23 Oct 2026 16:17:45 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xKHxh-00038b-FN for xen-devel@lists.xenproject.org; Fri, 23 Oct 2026 16:17:45 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKHxh-00000009FoG-1Z8t; Fri, 23 Oct 2026 16:17:45 +0000 Received: from 224.pool85-54-217.dynamic.orange.es ([85.54.217.224] helo=localhost) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKHxg-0000000HIWo-4AeE; Fri, 23 Oct 2026 16:17:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From; bh=91d6mOvZPpjsKDXzz8mQfsrDndJawH+XacKy+EAZdP8=; b=aFtz1MquU1dz62WgL0+1e4gSP1 yitzo4r62om5+mbal2Lky8BiNnPmGrGXZ24wy3P/RH6KmUcsqMgXa8+TVKOqw7MuhsTR5YVjfrWKf gM0CcmSEZGBB8Ncs3aUa1KVzqTBppTiQ7uniR9GTQda0asdCgzwXvEdlYpahcqgHfFUc=; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Teddy Astie , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [PATCH v2] xen/vcpu: ensure no write when runstate handler is NULL Date: Fri, 23 Oct 2026 18:17:42 +0200 Message-ID: <20261023161742.67329-1-roger@xenproject.org> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xenproject.org) X-ZM-MESSAGEID: 1792772286300158500 The VCPUOP_register_runstate_memory_area hypercall tries to update the newly registered area, even when NULL is being registered.=C2=A0 If the gue= st happens to have memory mapped at 0 in the address space, this write will succeed. Ever since it's introduction in Xen 3.0, NULL is the initial state of the pointer, and guards the update of the runstate area in context_switch(). NULL has also been accepted as an input to the hypercall. It is unclear whether de-registration of the area was considered at the time, but the behaviour of the hypercall has always supported. De-registering using NULL is a common pattern for other hypercalls, so formally make this the case for VCPUOP_register_runstate_memory_area by skipping the update if the area has been de-registered. Fixes: 705ea2b54c35 ("New VCPUOP_register_runstate_memory_area hypercall.") Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Andrew Cooper Reviewed-by: Jan Beulich --- Changes since v1: - Reword commit message. - Comment on the runstate update attempt done in common_vcpu_op(). - Notice in the public headers that passing NULL deregisters any previous region. --- xen/arch/x86/x86_64/domain.c | 5 +++++ xen/common/domain.c | 5 +++++ xen/include/public/vcpu.h | 1 + 3 files changed, 11 insertions(+) diff --git a/xen/arch/x86/x86_64/domain.c b/xen/arch/x86/x86_64/domain.c index a02d4f569ee5..533b0b21a00e 100644 --- a/xen/arch/x86/x86_64/domain.c +++ b/xen/arch/x86/x86_64/domain.c @@ -58,6 +58,11 @@ compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_H= ANDLE_PARAM(void) arg) rc =3D 0; guest_from_compat_handle(v->runstate_guest.compat, area.addr.h); =20 + /* NULL handle is deregistering the address. */ + if ( compat_handle_is_null(area.addr.h) ) + break; + + /* Update the newly-registered runstate area, best-effort. */ if ( v =3D=3D current ) { XLAT_vcpu_runstate_info(&info, &v->runstate); diff --git a/xen/common/domain.c b/xen/common/domain.c index 6b52713518da..a1e4cb80871c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -2330,6 +2330,11 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUE= ST_HANDLE_PARAM(void) arg) rc =3D 0; runstate_guest(v) =3D area.addr.h; =20 + /* NULL handle is deregistering the address. */ + if ( guest_handle_is_null(area.addr.h) ) + break; + + /* Update the newly-registered runstate area, best-effort. */ if ( v =3D=3D current ) { __copy_to_guest(runstate_guest(v), &v->runstate, 1); diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h index f7445ac0b08a..403b81457c82 100644 --- a/xen/include/public/vcpu.h +++ b/xen/include/public/vcpu.h @@ -112,6 +112,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t); * VCPU was last scheduled to run. * 3. New code wants to prefer VCPUOP_register_runstate_phys_area, and on= ly * fall back to the operation here for backwards compatibility. + * 4. Passing a NULL handle will deregister the region. * @extra_arg =3D=3D pointer to vcpu_register_runstate_memory_area structu= re. */ #define VCPUOP_register_runstate_memory_area 5 --=20 2.55.0