From patchwork Wed Feb 15 03:40:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 9573323 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 A468860578 for ; Wed, 15 Feb 2017 03:40:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AEE6283F3 for ; Wed, 15 Feb 2017 03:40:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FD8C2842C; Wed, 15 Feb 2017 03:40:24 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 3B5D7283F3 for ; Wed, 15 Feb 2017 03:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751695AbdBODkN (ORCPT ); Tue, 14 Feb 2017 22:40:13 -0500 Received: from ozlabs.org ([103.22.144.67]:36103 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751503AbdBODkM (ORCPT ); Tue, 14 Feb 2017 22:40:12 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3vNQ616xMkz9s1h; Wed, 15 Feb 2017 14:40:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1487130009; bh=EoIPuoOBffgEnNg6MAW0dOH8GBrz8ci80rOQHhuNmrA=; h=From:To:Cc:Subject:Date:From; b=DhC0/rVKY7sHipn3Pd1SyJInlWOq+lwWmsviFKidl40EuoWwoGq/97udmofPB6CXj GH1Rg1Cf8zRMu/33v7A/icDX3V9sOpNO1PStt2GPvzg2/iLnAN3LrKX7SPCSfL1WFP ZJc/mcrBod0NnaD9/wUubbQB3/veCL/JyQ0HWtes= From: David Gibson To: paulus@samba.org Cc: dan.carpenter@oracle.com, linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Gibson Subject: [PATCH] KVM: Prevent double-free on HPT resize commit path Date: Wed, 15 Feb 2017 14:40:04 +1100 Message-Id: <20170215034004.9255-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP resize_hpt_release(), called once the HPT resize of a KVM guest is completed (successfully or unsuccessfully) free()s the state structure for the resize. It is currently not safe to call with a NULL pointer. However, one of the error paths in kvm_vm_ioctl_resize_hpt_commit() can invoke it with a NULL pointer. This will occur if userspace improperly invokes KVM_PPC_RESIZE_HPT_COMMIT without previously calling KVM_PPC_RESIZE_HPT_PREPARE, or if it calls COMMIT twice without an intervening PREPARE. To fix this potential crash bug - and maybe others like it, make it safe (and a no-op) to call resize_hpt_release() with a NULL resize pointer. Found by Dan Carpenter with a static checker. Reported-by: Dan Carpenter Signed-off-by: David Gibson --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 013552f..72ccac2 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -1407,6 +1407,9 @@ static void resize_hpt_release(struct kvm *kvm, struct kvm_resize_hpt *resize) { BUG_ON(kvm->arch.resize_hpt != resize); + if (!resize) + return; + if (resize->hpt.virt) kvmppc_free_hpt(&resize->hpt);