Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3884051pxb; Tue, 17 Nov 2020 06:10:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3CVQkNJnZ9QD6V1d1O1CYvCdMN45LoSKA02qUlDAN1sK+rbCc/4iuGNHBgAb89SfW6u5c X-Received: by 2002:adf:f385:: with SMTP id m5mr26396527wro.296.1605622205649; Tue, 17 Nov 2020 06:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622205; cv=none; d=google.com; s=arc-20160816; b=VfPezrsmwfUohoTH1v72D5pwHxGQ8LJyasvRnfSsrTX1st74OL+quRVBZ+/sfj+e44 54hTaPZjxMJql8Znfx/30eHLYqrBSDrsAPfboRhuaLKa7FU1YjcUDrJzsuJDZXndQ34W w4BhtFkdLlKc+ZxKhbV90RP+6aOglNDkFyfSiYVl9pL4ufraTJZ44cl0U/H/SQigyW6C ll2BK5d8aREJKMnr/bQuyJRHyK0+eoDRg6h74vZLt/DKUAeeYKLVquMIsBKbLOLD/7k8 i7+W4VhfYiOFzWyB8A4NIpFO/O5DQvEMr6AxUz1Q4uc5C8jUQmrVOOA5SZQKshLBhFcT oacQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AuvlJ1KnY2pira115HIBtVY0Sso3xAfkgnJrbFNR15k=; b=egQX52E6gE51svCriQLTOU5RHXUbuvKcdzd76YSJc4FfdyCv7kGj1gOyD8y0kjUqSF 50suVdjQf+f3k7cQJVQA2D71uRZ+dpVCmQZ7NELpYYW+s8KgeIJBTKpNiEOB5ZxnnZAx pfn+B4Jhb2ddgURED0XfgIbwTOgAO+bxVRtpK7oTEC15rKFVtQhu3WUn6wf/GZV0+g5h yuTDgVi9gTnsABYdGmFe2w5ksfL4dSEKuR9QAsUT2VbYytXWCVmO4dCFiRsoxvbPQf65 ZkL4P/FFsrUqo8/IIVASxGnn/akt8vIDhwgXQBG98z3m03xiMgjMywvOj0OnaHEYTtM9 390g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VoZkGbAS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si13605600eje.302.2020.11.17.06.09.41; Tue, 17 Nov 2020 06:10:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VoZkGbAS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729257AbgKQNIR (ORCPT + 99 others); Tue, 17 Nov 2020 08:08:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:36684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729242AbgKQNIL (ORCPT ); Tue, 17 Nov 2020 08:08:11 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15414238E6; Tue, 17 Nov 2020 13:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618490; bh=cFm+X33idwFBFy3k9VmCTbLnVijn82oAwo+YDVz0Upk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VoZkGbASsPu2rkn5bWMJ8LhQfgBjzSjoX0AFfUUiefoGdxaDsEDNHKkYPwiToD9Ko dgvh3q/EGBPA1ukHEtIyKigHoi1LFHhz+WIq/glpiLvm+cxsJgdFkvq8GPThEIBbzg aKmD+0WB9qLoROmrqJVnbHxdP3NE4BR4NdOtsduY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Juergen Gross , Jan Beulich Subject: [PATCH 4.4 50/64] xen/events: fix race in evtchn_fifo_unmask() Date: Tue, 17 Nov 2020 14:05:13 +0100 Message-Id: <20201117122108.636669729@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122106.144800239@linuxfoundation.org> References: <20201117122106.144800239@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross commit f01337197419b7e8a492e83089552b77d3b5fb90 upstream. Unmasking a fifo event channel can result in unmasking it twice, once directly in the kernel and once via a hypercall in case the event was pending. Fix that by doing the local unmask only if the event is not pending. This is part of XSA-332. Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Signed-off-by: Greg Kroah-Hartman --- drivers/xen/events/events_fifo.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/drivers/xen/events/events_fifo.c +++ b/drivers/xen/events/events_fifo.c @@ -227,19 +227,25 @@ static bool evtchn_fifo_is_masked(unsign return sync_test_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word)); } /* - * Clear MASKED, spinning if BUSY is set. + * Clear MASKED if not PENDING, spinning if BUSY is set. + * Return true if mask was cleared. */ -static void clear_masked(volatile event_word_t *word) +static bool clear_masked_cond(volatile event_word_t *word) { event_word_t new, old, w; w = *word; do { + if (w & (1 << EVTCHN_FIFO_PENDING)) + return false; + old = w & ~(1 << EVTCHN_FIFO_BUSY); new = old & ~(1 << EVTCHN_FIFO_MASKED); w = sync_cmpxchg(word, old, new); } while (w != old); + + return true; } static void evtchn_fifo_unmask(unsigned port) @@ -248,8 +254,7 @@ static void evtchn_fifo_unmask(unsigned BUG_ON(!irqs_disabled()); - clear_masked(word); - if (evtchn_fifo_is_pending(port)) { + if (!clear_masked_cond(word)) { struct evtchn_unmask unmask = { .port = port }; (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask); }