From: Andrew Cooper Subject: [PATCH] xsm/evtchn: Never pretend to have successfully created a Xen event channel Date: Mon, 19 Jan 2015 10:45:52 +0000 Message-ID: <1421664352-9488-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Keir Fraser , Ian Campbell , Andrew Cooper , Tim Deegan , Jan Beulich , Daniel De Graaf , Ian Jackson List-Id: xen-devel@lists.xenproject.org Xen event channels are not internal resources. They still have one end in a domain, and are created at the request of privileged domains. This logic which "successfully" creates a Xen event channel opens up undesirable failure cases with ill-specified XSM policies. If a domain is permitted to create ioreq servers or memevent listeners, but not to create event channels, the ioreq/memevent creation will succeed but attempting to bind the returned event channel will fail without any indication of a permission error. Signed-off-by: Andrew Cooper Acked-by: Daniel De Graaf CC: Keir Fraser CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell CC: Ian Jackson --- I have tested this with and without XSM compiled into Xen, with an all-powerful dom0. I have not experimented with a semi-privileged domain builder or stub qemu domain. --- xen/common/event_channel.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 7d6de54..eece46b 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -1155,21 +1155,25 @@ int alloc_unbound_xen_event_channel( spin_lock(&d->event_lock); - if ( (port = get_free_port(d)) < 0 ) + rc = get_free_port(d); + if ( rc < 0 ) goto out; + port = rc; chn = evtchn_from_port(d, port); rc = xsm_evtchn_unbound(XSM_TARGET, d, chn, remote_domid); + if ( rc ) + goto out; chn->state = ECS_UNBOUND; chn->xen_consumer = get_xen_consumer(notification_fn); chn->notify_vcpu_id = local_vcpu->vcpu_id; - chn->u.unbound.remote_domid = !rc ? remote_domid : DOMID_INVALID; + chn->u.unbound.remote_domid = remote_domid; out: spin_unlock(&d->event_lock); - return port; + return rc < 0 ? rc : port; } -- 1.7.10.4