Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp875550pxk; Thu, 17 Sep 2020 20:01:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8aEfnyOHvDaUk8kJMDbvIi0Lj0Vo2wndTqNxRjv9ZXrEZAd34QBvw7Oh1NYNz3KZa7ZF+ X-Received: by 2002:a17:906:9718:: with SMTP id k24mr31712397ejx.365.1600398083826; Thu, 17 Sep 2020 20:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398083; cv=none; d=google.com; s=arc-20160816; b=cqG0qtvKu3rQcIS7/qpo6SnrQzQV6vc9G7PfYsoK3sVzsb/p1wGJ85az1K9COg59M7 1nAl/mKgg7ogUIqncOUuw5xhhgvNVLlf0Hia2HhYpl20IIfDyLTVdX8nkgtmu1WVePL1 owZhEnZ7NSI/JbQojJM7XOJ51nTrQX/ZouM2UAldJruGqkU+IkHXEkVg5EKrpnRuzu3N 8Rq6QUubZrUo+p7aKzuMC6Gb4Iz8I93gF3Hv2L2hovgFn9yhKocKuqkiK1f5ijiOvpju rwO5gbcCqbjo2ATsDRZHwS88ArMV4oNxr+nVPw4+pCG3nfoK9WrHQ+znuwdUGvk82Io3 6VIQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dh1CxjauRJd09Pekdevo8j6obLMIkui3zIyvojMzlJg=; b=N9XgeU7+0PV4NqOVXsdYdC0d4lZF0jRDH2GUDxYryEyPX9f/aa2U4QpEySHnzXKRx0 yNeHM8YSq362VfA3v0inAknj37JZy0NLCiKIdsxMfOPaFlyhxVcDP3kVTwewa9QQN/Mo E9bvFU50QPjIb1f04ItrPos5EeazIQN0yJkpsT1cbVGQWAZsRka45huy8OR+tScu8aLF RoETRpSLYl9QX/J0zBAn/86lwp4BIH8WMGN2QATKOaEWvjwyxL2XkRXZPqLEBHk/f7yG pauVBNo3f4dtEyVKplLK8VYc0+rKo/nKYPPpHh0Q1YU/GvILjcXUK4MtvHUpAH4pd5Be ggIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FuLIYzE6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si1468455ejr.202.2020.09.17.20.01.00; Thu, 17 Sep 2020 20:01:23 -0700 (PDT) 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=FuLIYzE6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730420AbgIRC65 (ORCPT + 99 others); Thu, 17 Sep 2020 22:58:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:55038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbgIRCGC (ORCPT ); Thu, 17 Sep 2020 22:06:02 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24A2823718; Fri, 18 Sep 2020 02:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394762; bh=KFatgagQ4PvsOtZV3cqXpKu47OvAIH7wfqraFca7cSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FuLIYzE6qVSuAZCT5GIug0W+JqD6vDm5FahGzL+J1Mvu1nsnSYOE2QV1DPSQx6BaZ i7hXO8eSURN6LHQNyjmH/7ReLGZ69WjMxPIEcYzdA5A8YS3Ljw2PFYpH88RJMMYl42 Z4wGL6VVh0RpSSSCVvmjMiWz/CgeNmafghUYoFHM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Steve Rutherford , Jon Cargille , Jim Mattson , Paolo Bonzini , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 238/330] KVM: Remove CREATE_IRQCHIP/SET_PIT2 race Date: Thu, 17 Sep 2020 21:59:38 -0400 Message-Id: <20200918020110.2063155-238-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steve Rutherford [ Upstream commit 7289fdb5dcdbc5155b5531529c44105868a762f2 ] Fixes a NULL pointer dereference, caused by the PIT firing an interrupt before the interrupt table has been initialized. SET_PIT2 can race with the creation of the IRQchip. In particular, if SET_PIT2 is called with a low PIT timer period (after the creation of the IOAPIC, but before the instantiation of the irq routes), the PIT can fire an interrupt at an uninitialized table. Signed-off-by: Steve Rutherford Signed-off-by: Jon Cargille Reviewed-by: Jim Mattson Message-Id: <20200416191152.259434-1-jcargill@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/x86.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8920ee7b28811..67ad417a29ca4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5050,10 +5050,13 @@ set_identity_unlock: r = -EFAULT; if (copy_from_user(&u.ps, argp, sizeof(u.ps))) goto out; + mutex_lock(&kvm->lock); r = -ENXIO; if (!kvm->arch.vpit) - goto out; + goto set_pit_out; r = kvm_vm_ioctl_set_pit(kvm, &u.ps); +set_pit_out: + mutex_unlock(&kvm->lock); break; } case KVM_GET_PIT2: { @@ -5073,10 +5076,13 @@ set_identity_unlock: r = -EFAULT; if (copy_from_user(&u.ps2, argp, sizeof(u.ps2))) goto out; + mutex_lock(&kvm->lock); r = -ENXIO; if (!kvm->arch.vpit) - goto out; + goto set_pit2_out; r = kvm_vm_ioctl_set_pit2(kvm, &u.ps2); +set_pit2_out: + mutex_unlock(&kvm->lock); break; } case KVM_REINJECT_CONTROL: { -- 2.25.1