Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3761885pxk; Tue, 29 Sep 2020 05:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy03WQnMpQaVXMQ2vJQJ5q18DeUzdKpJQ2qfSNP32gpu7GRqr/NABFaAcnHlyNb0jshgfS X-Received: by 2002:a17:906:b0c:: with SMTP id u12mr1966333ejg.331.1601383594461; Tue, 29 Sep 2020 05:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383594; cv=none; d=google.com; s=arc-20160816; b=n4dce6v+AMjizUZNka4eQeKveVaJh8MQgtjQrvuNRIm16LM3nlXN/nDYXhGdZ6mxLD m6/skvIMu5Ury7ZnFp2bVby03lso5k389oxIq+8yer0+JI2uCU2XEBoz6u8seSyhc1oJ IaR47rc+B7UX5NAWr3YZSGkoybGwnZxBXwV2bZva2FPNJ62DztZStFh8TV8zluiCTmi+ BAUwP1CmJVbmwAporup+MAZ8HZokwhdrkx5gfwMjGj//53qvHnpnfgSiZPB5K/Cg2jmb 0u9RSnlI4eCfAHkoPWVvDZm19LaG5v7fQb9hoRqXykGyC2A09f5JDzSftwYMwq8aHs9W V4jQ== 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=x45PZVwHuHYghoVaqYJIUuyRtHu/ptvgT0brK3vxDl4=; b=GTFhCWhWWN/LRupDHSd8TG+nsBJPQnQTt9V4fmuIde8IYnsIPriNoLeDWwB4TY0hoG Dx4EyHAHpWck1Gyl0eOPBMrdoOoV2o7wejZ81t+cxHiUEXkIjvLFdLQ+aM8VtxZuUjsB Ze0X9+iG7t0fcUTzHsTe2/orBap+q/pktBD3ySYHdi4NAwWFKQSUZ7uaXnFnr4ndB6MC 5Qs3kubtYA07Gw3Z/A/JMsr/RYj7oxntaVPNvQ/dHqAMMkn8GMdFwnOyr9MHuEBQVYr0 UrMTs+0TIroPubIDzhbmhFwkw4xQo/SNU5Omz2NWBFd300bp3YNXwlS5DdmR2cZgbNdu g0kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wp6gLZfr; 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 r15si2752303edo.318.2020.09.29.05.46.11; Tue, 29 Sep 2020 05:46:34 -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=wp6gLZfr; 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 S1733185AbgI2MnA (ORCPT + 99 others); Tue, 29 Sep 2020 08:43:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:50706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729129AbgI2LKD (ORCPT ); Tue, 29 Sep 2020 07:10:03 -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 711A321D46; Tue, 29 Sep 2020 11:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377803; bh=RkAgZ0llnIywDojBShVlZTmNEJcf13A5yJpo8vi/diU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wp6gLZfrTKuNimrQonCZ+HmyINOB+p6QVjEGr7Jv8kqilqqv3rt88Fc7sBzVP8RpU N59JpTSkpN/OrZyJniaPw2ueNq5kBntIbas8GDASVGwSHjwOaXKf/aCeuEki9PGZuj tQUhmahKOybI1Xp5tLimL7V5WFpEv1OiBf09oRk8= 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.9 077/121] KVM: Remove CREATE_IRQCHIP/SET_PIT2 race Date: Tue, 29 Sep 2020 13:00:21 +0200 Message-Id: <20200929105933.995631521@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@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: 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 6b7faa14c27bb..3c0f9be107e42 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4263,10 +4263,13 @@ long kvm_arch_vm_ioctl(struct file *filp, 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: { @@ -4286,10 +4289,13 @@ long kvm_arch_vm_ioctl(struct file *filp, 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