Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3758141pxk; Tue, 29 Sep 2020 05:40:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMGWuR9gMoE52ljcCK/uJZPN/ot+/ltyrksVRkR0yPEdgGRSMaJn9u9YachbeqX0Kkok+2 X-Received: by 2002:a50:8fa3:: with SMTP id y32mr3146697edy.78.1601383236887; Tue, 29 Sep 2020 05:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383236; cv=none; d=google.com; s=arc-20160816; b=01hH3FjHriBnG5k659g637i/0uzY6N27ygR2j4t9705i3R5yivbzogsUhgF7m8nnyY rhLREEJy0Ycf9e2gGfr50lcCEiUiahpqsMlrIZrRB8/wfFVyKbQzf62idajaD3dCVdRe Ve7RazAZlccm9N50OuRqHuA0Nl33sT52bhyycwuKzkIYzfCZKzT3GYMIZiExe6BzmzgK g1FS9b7pklZqSdXRyJ4oCpIVdR1K4YAyomSUP5Xzm6nZn7sLjr/uv9+UE4KgBQmKUP2T WEAY1mWBO/BkPJZWH/4G7o1SyMsPn75DbNSv4XIZsEBk3/6Ph6B57Mkd17inm2Fft0z7 EIuQ== 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=eutIIpzx7sEWXFQ//evBDyl/yP07FfOIeRFYVe+6O90=; b=dEegosKUrZQrH+k2863QLY9JzRhrooZLekx0KG330cyScvGS7Yzla4gowvWXl4Bm4Q EM3XT+9VepdTJcsDnqD6yPQS5uHIj+vYIdtRalu+knlbe/+y1YEzK0sy8gdO2raYjebh 8DzWWUGc9HYMpRzrZZ+jxkD9meenXg/ys4ISAjcmNYLiOgsDyiyiHafzu77w7kdrd1Sr hw0i3nFdVOsPuqiMUX92srnGqLoXKOIZSpTxftkqSA2DDH5hdDTYrB7sQhMXtASssbjY O2rrPWDGchHrFENu23x4w5CDfTVMowrGXSLw3wuYqdS6lCNqdqlUm1jzmEGR1KLCkM3T Y9ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E4e+wDi9; 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 h16si2736533edr.336.2020.09.29.05.40.13; Tue, 29 Sep 2020 05:40:36 -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=E4e+wDi9; 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 S1733097AbgI2MjM (ORCPT + 99 others); Tue, 29 Sep 2020 08:39:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbgI2LQ7 (ORCPT ); Tue, 29 Sep 2020 07:16:59 -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 4C7F4206A5; Tue, 29 Sep 2020 11:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378218; bh=IYQ2allU1mwNxloo47xz+ovSbQ6yYNtlQiE/RPVests=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4e+wDi9xmTTcZ1HRDU0ZrguitV4jR2yTptOyL1gMwwq7q+u62iQ4Xj2VHdm/XWKA GC9JvJlle8OSSxJ0BG4sySrY53Cq+8cwW5PQywWkwex2c848JGA6EAlcLKFZZQya2b pVrfLV6RLksjYJUvwPdfesXzmx3U3662q2MW+eco= 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.14 104/166] KVM: Remove CREATE_IRQCHIP/SET_PIT2 race Date: Tue, 29 Sep 2020 13:00:16 +0200 Message-Id: <20200929105940.399300778@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@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 3aed03942d7d4..79fa55de635cc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4370,10 +4370,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: { @@ -4393,10 +4396,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