Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp803486pxb; Tue, 3 Nov 2020 13:00:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7cF6M/vpDnoVs5qpX0qrbYXtMUlBiFcLlLYV7kTl1ymXBTbrPAWeFseFL/WQZmhHLpVg+ X-Received: by 2002:a63:389:: with SMTP id 131mr6474269pgd.128.1604437216159; Tue, 03 Nov 2020 13:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437216; cv=none; d=google.com; s=arc-20160816; b=BPDTjNv3JCwSH4Szp72XrjRde0APx9gBuChdmGEJdlBxHimgw83fNs5Mw2clyqlsfb 5rS54U/G5fnptUU/UpvXVY93lS2ynZmumpvNrH/QVk8WesN3/SvuAK/fjNm5+kQdGoXl NG9CBzgYY5pb2zWI/xwh9idQ4lkrxltXWEAA3TMlYjcuj+Es6kcVDoLFAS+AbrKYWO7X 0aAVqYCgc8cCiXihs80xPqhU2mzDxxa3fqWxxfh1sisovfVmhFvVFDGE/b4bo0WbCPiD GtfSlQUAp8yWzM35S/Qylv269hzXcJlg8/4eGIJootnAroapgfjfe9RpzoK+fmO19G2k KgYg== 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=atHYozOiPJlp45WHHHXAav6C4qgCEzleEi2dW+Humco=; b=RH13kxlgHmgb7HqTP3ZCpns22gBMAz4JdsJjhjZHw62urhEHy5PUT7FElH0CnYAgDG VGpzTlM0kFJRonCaRmZ0SU068X7ikoVWjILgxh9hM+Aea7tJTXWY+IBs86emly04x7o3 aGYIlWQq8gzP+2IFaDPOiC3ic+x/X/6bON4w0F8ifgI2QEGQR6TQ8tnkuaTVub5TETJ7 rrADl7tRFFkeWf+eypw24AIBlwMyx9EoSuYlm3haW5TfE+n06CIrAARhrfdyQuKf3PcY S9/CvLhqInToX3+oWrIrn4kr4fKT9vZLjNlwAdZRSVgUTGacMEzxA1x+mZQTWI3vAy98 Cl6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x8jZaGp7; 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 x4si6378870pln.320.2020.11.03.12.59.31; Tue, 03 Nov 2020 13:00:16 -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=x8jZaGp7; 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 S1732524AbgKCUyE (ORCPT + 99 others); Tue, 3 Nov 2020 15:54:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:52376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731320AbgKCUxw (ORCPT ); Tue, 3 Nov 2020 15:53:52 -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 C1E01223AC; Tue, 3 Nov 2020 20:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436832; bh=wi0aNJS4t9cijB/GMdL2NsV7IO6FsukuHpXIFapDTYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x8jZaGp7DHY0kj8+pA6DuJoo7NwdY4Rux5VM6pYOxkmsk1kwB+HRgwowHg50d/05y R0HPwn1eOg3S3a9Vis7kQuLDoZPuiYZjwODdunAy+WJWvnRFcccHvUpU3YA1QNy8tv 0ouYSjW03ANeyMCRTkFCviHeoZL01USos9rPlKoY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juergen Gross , Jan Beulich Subject: [PATCH 5.4 003/214] xen/events: fix race in evtchn_fifo_unmask() Date: Tue, 3 Nov 2020 21:34:11 +0100 Message-Id: <20201103203249.832354885@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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); }