Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3892714pxb; Tue, 17 Nov 2020 06:20:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBPaYCLMR0RKQjv30XfUOLnQmQN5HePOyZcsotqdIg1kWkVgnW91oY6NagiVQFA3e66ZKI X-Received: by 2002:a17:906:17d1:: with SMTP id u17mr19376179eje.6.1605622858396; Tue, 17 Nov 2020 06:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622858; cv=none; d=google.com; s=arc-20160816; b=QGpFiMJaAZM4K0PivLNfCZkQqa0XmzBRX141FH/EP6m/TFD4WDvaRv0VICbq0gpvm4 LM0RV12zdT/bdm4DccczKD0cLDs+X4KnCoKieRt36Q/M0qHobj/66dcwXvIeZf/rMgXr /RTRFkXXR1vZHyoEb5JFXgFfR8hF6Qt/qsSvCjKwoAwhRdPU7oANVguTyUKKOrATU08H YqlAkF+JkhTBoaj/KZUHFvwwgUio9FRJXUndci1FvS5lGZqrb7C3R4N8qbBBbfhxf3VV Ek0g789UqZf9A6UpnX8k6Hqhd9nkuQyn0VQ/IksK1Kmnx8MMGYbvyFQ/o/XDs6+wooiD eKiA== 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=kIo/r7Wu9cJoSrupWWIDrLLO+fHOHbEHmecvY0Krwz36Tri3a1/UXTCOueUtrOxGud 2bPDBiu1Ov2q7GoMMiOXzU1GXT+Xdrl0ZFydsJwrqJcv2cXihIqVflNzH1zmvCn7XoKt uUd4QOaV21wJpJODOsxNqeyaEG+V96GuFJt4rsPuDYfapU7XTiJqzzjLR+eo+jymZ5qq dUBrSed4tLIgzd3d8beUNotJEKKgzC1X58+GegBpgISMxnSEp4KTAj3nrhvHMUQPHCji 5TA327wM9a81+iAzjmdRmZTGdlwg6jQP9RRBLTcwyVc9D2FOe75NZoL9NNQNy7f9tjhu H+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eeu2ifDb; 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 gq9si13456532ejb.618.2020.11.17.06.20.33; Tue, 17 Nov 2020 06:20:58 -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=Eeu2ifDb; 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 S1731067AbgKQOAE (ORCPT + 99 others); Tue, 17 Nov 2020 09:00:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:49294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730310AbgKQNRI (ORCPT ); Tue, 17 Nov 2020 08:17:08 -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 1E1F1241A6; Tue, 17 Nov 2020 13:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619027; bh=cFm+X33idwFBFy3k9VmCTbLnVijn82oAwo+YDVz0Upk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eeu2ifDbXK1dQaziyFL2+d55bK6p3nYNKANoGpt7h5dLIH9QHo5hoH1Cy9+UVH16M Q0tLOaj+eiQZAUcIbOVfK1spe6itlT7olmlaEzb7wsGAYNXkg/Zux7XyCxTdJXMPWo ninWNVD2tc7weH1fakFWQf0STM6nnd6jOssB4jp4= 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.14 71/85] xen/events: fix race in evtchn_fifo_unmask() Date: Tue, 17 Nov 2020 14:05:40 +0100 Message-Id: <20201117122114.517303856@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@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); }