From patchwork Tue Jan 24 13:06:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Vyukov X-Patchwork-Id: 9535157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D68E66042C for ; Tue, 24 Jan 2017 13:06:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C144926D05 for ; Tue, 24 Jan 2017 13:06:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B215727F81; Tue, 24 Jan 2017 13:06:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8542326D05 for ; Tue, 24 Jan 2017 13:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750838AbdAXNGy (ORCPT ); Tue, 24 Jan 2017 08:06:54 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36806 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbdAXNGx (ORCPT ); Tue, 24 Jan 2017 08:06:53 -0500 Received: by mail-wm0-f41.google.com with SMTP id c85so180622056wmi.1 for ; Tue, 24 Jan 2017 05:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=clFseLJYywxTw9KBwx5S35ybhJMUpW2qf8omJKMi+AU=; b=D6Z+0HiuJTfRZ8xPywK0Ql0R0qe4U3uDJH2BVSfH/KCvq+ie466MxazBbvVi9sZjOP Y+MojZi50y5ohVYJTPKOP21hb/vMvhhH+5yWMxA6FKzx05GAI6f85IjqwevsVg4991AJ kBv9ecSqXThG9TCBUxyNFCZQjw5wL5DZS4/573YHln/6hToQbRztq6ThxCPh+2H/zBxZ 79Iy6pPpHeBiaYWEpx8+6/OZmVrolGk1EML4+aEPa/HuUnXypV16avaK4ZdATB59jaCp P3uykYRW3G8PA34xbM7u2WbXIAkTVRS32OzzN7eMkuKCFSVsobKaPGaGo0pIPH7/5sX7 hQeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=clFseLJYywxTw9KBwx5S35ybhJMUpW2qf8omJKMi+AU=; b=qjUsMY+OY2X9GxHeEgk+v0MjFiUPVEfcR3trcjG31hvgHiFaSk69fEwN5/on43amXr 5CLlEizfGt3lwZCrV3eqTIgHAn2Bmm5MrF+ZyZDF/GaLIpwAHX8U8/mG0XbpNt3mqAhJ sKt+SuT8g5u4We+4JjERxGAzv321TDqE37XFf7NWkKrADCTHAP2WgouPqEKkUj700BJB TEqQGeG1BkyRIdjSMXG5wVqw580EZcHb0zXZCUUrPmmGrmvaRnVxIu1eHuHG1IA3kzyC C6usoWnefhQ1S3CEpM37l0PiC/88Q6svQMn4OsyFsv8osIWyYb2LDMWmn+Lq3TvpNttc wM1g== X-Gm-Message-State: AIkVDXI9VDfi7blwgMzR5lTNDxXvvbuCy00KldkrPF/xVsDsJmXFgHFXexAW218ZdU6KkKzB X-Received: by 10.28.96.130 with SMTP id u124mr19620440wmb.81.1485263211619; Tue, 24 Jan 2017 05:06:51 -0800 (PST) Received: from dvyukov-z840.muc.corp.google.com ([2a00:79e0:15:10:5d97:ebfe:f72:2878]) by smtp.gmail.com with ESMTPSA id u47sm19923794wrb.15.2017.01.24.05.06.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 05:06:50 -0800 (PST) Received: by dvyukov-z840.muc.corp.google.com (Postfix, from userid 129372) id CCA9EE1177; Tue, 24 Jan 2017 14:06:49 +0100 (CET) From: Dmitry Vyukov To: pbonzini@redhat.com, rkrcmar@redhat.com Cc: Dmitry Vyukov , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, syzkaller@googlegroups.com Subject: [PATCH] kvm: fix usage of uninit spinlock in avic_vm_destroy() Date: Tue, 24 Jan 2017 14:06:48 +0100 Message-Id: <20170124130648.75935-1-dvyukov@google.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If avic is not enabled, avic_vm_init() does nothing and returns early. However, avic_vm_destroy() still tries to destroy what hasn't been created. The only bad consequence of this now is that avic_vm_destroy() uses svm_vm_data_hash_lock that hasn't been initialized (and is not meant to be used at all if avic is not enabled). Return early from avic_vm_destroy() if avic is not enabled. It has nothing to destroy. Signed-off-by: Dmitry Vyukov Cc: Joerg Roedel Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: David Hildenbrand Cc: kvm@vger.kernel.org Cc: syzkaller@googlegroups.com Reviewed-by: David Hildenbrand --- arch/x86/kvm/svm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 08a4d3ab3455..3aecaa13fd22 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1382,6 +1382,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return; + avic_free_vm_id(vm_data->avic_vm_id); if (vm_data->avic_logical_id_table_page)