From patchwork Tue Sep 29 10:59:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 263013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88C1BC4727C for ; Tue, 29 Sep 2020 12:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38AC920773 for ; Tue, 29 Sep 2020 12:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601382146; bh=NvZmPw2C2uvbDgqyuHUaqE7UzXhi8hTw7mWaXV6zhTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MEsnoZ5k1iCsDDTl5GCp56N8slJPSFgbmNlSrkkeczfCKnAVo8qUVK3eQmqUWRlUw F0VqtGXFnNgdLK/+3lKEL4jnInK3OkFJEo0Mf/GG2/DX7rZ6PU7WOy9DrU8Te8vrvm a0AdCPBeJQJHtsW5qqCheN53KftIeUXEgDJ796DE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728599AbgI2MWO (ORCPT ); Tue, 29 Sep 2020 08:22:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:49146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729800AbgI2LfL (ORCPT ); Tue, 29 Sep 2020 07:35:11 -0400 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 484D323BEE; Tue, 29 Sep 2020 11:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378887; bh=NvZmPw2C2uvbDgqyuHUaqE7UzXhi8hTw7mWaXV6zhTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyEPw9us5cg5arKYjKxhgbLwvAauUA6C5u2jmA+4LQvl3CXgJwb5fKO0YPSu7tEoj ID2/yC7d5/f0wCW+gD48PAdQwVUJCXcDJ/f/lNasYaGZqoyahCpjhGYzrOTX0A+YId Ia5qcHGSDLBHcj2/0rc2exTlOXEfsNXzfO3Ej0H0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve Rutherford , Jon Cargille , Jim Mattson , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.19 145/245] KVM: Remove CREATE_IRQCHIP/SET_PIT2 race Date: Tue, 29 Sep 2020 12:59:56 +0200 Message-Id: <20200929105954.042602806@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105946.978650816@linuxfoundation.org> References: <20200929105946.978650816@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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 430a4bc66f604..620ed1fa35119 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4668,10 +4668,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: { @@ -4691,10 +4694,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: {