{"id":814036,"url":"http://patchwork.ozlabs.org/api/1.2/patches/814036/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-ppc/patch/150542618501.6859.11512107352972110416.stgit@bahia.lan/","project":{"id":23,"url":"http://patchwork.ozlabs.org/api/1.2/projects/23/?format=json","name":"KVM PowerPC development","link_name":"kvm-ppc","list_id":"kvm-ppc.vger.kernel.org","list_email":"kvm-ppc@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<150542618501.6859.11512107352972110416.stgit@bahia.lan>","list_archive_url":null,"date":"2017-09-14T21:56:25","name":"KVM: PPC: fix oops when checking KVM_CAP_PPC_HTM","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e9641ff79093240532935af55f338454aff865de","submitter":{"id":69178,"url":"http://patchwork.ozlabs.org/api/1.2/people/69178/?format=json","name":"Greg Kurz","email":"groug@kaod.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/kvm-ppc/patch/150542618501.6859.11512107352972110416.stgit@bahia.lan/mbox/","series":[{"id":3198,"url":"http://patchwork.ozlabs.org/api/1.2/series/3198/?format=json","web_url":"http://patchwork.ozlabs.org/project/kvm-ppc/list/?series=3198","date":"2017-09-14T21:56:25","name":"KVM: PPC: fix oops when checking KVM_CAP_PPC_HTM","version":1,"mbox":"http://patchwork.ozlabs.org/series/3198/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/814036/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/814036/checks/","tags":{},"related":[],"headers":{"Return-Path":"<kvm-ppc-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=kvm-ppc-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xtfsg1K03z9sRm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 12:45:59 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751804AbdIOCp6 (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tThu, 14 Sep 2017 22:45:58 -0400","from 4.mo2.mail-out.ovh.net ([87.98.172.75]:59595 \"EHLO\n\t4.mo2.mail-out.ovh.net\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751798AbdIOCp5 (ORCPT\n\t<rfc822;kvm-ppc@vger.kernel.org>); Thu, 14 Sep 2017 22:45:57 -0400","from player770.ha.ovh.net (b6.ovh.net [213.186.33.56])\n\tby mo2.mail-out.ovh.net (Postfix) with ESMTP id 83FF8AA757\n\tfor <kvm-ppc@vger.kernel.org>; Thu, 14 Sep 2017 23:56:34 +0200 (CEST)","from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139])\n\t(Authenticated sender: groug@kaod.org)\n\tby player770.ha.ovh.net (Postfix) with ESMTPA id 4D1B53C006C;\n\tThu, 14 Sep 2017 23:56:25 +0200 (CEST)"],"X-Greylist":"delayed 4196 seconds by postgrey-1.27 at vger.kernel.org;\n\tThu, 14 Sep 2017 22:45:57 EDT","Subject":"[PATCH] KVM: PPC: fix oops when checking KVM_CAP_PPC_HTM","From":"Greg Kurz <groug@kaod.org>","To":"kvm@vger.kernel.org","Cc":"kvm-ppc@vger.kernel.org, Paul Mackerras <paulus@samba.org>,\n\tDavid Gibson <david@gibson.dropbear.id.au>,\n\tSam Bobroff <sam.bobroff@au1.ibm.com>,\n\tPaolo Bonzini <pbonzini@redhat.com>,\n\tlinuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org","Date":"Thu, 14 Sep 2017 23:56:25 +0200","Message-ID":"<150542618501.6859.11512107352972110416.stgit@bahia.lan>","User-Agent":"StGit/0.17.1-46-g6855-dirty","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","X-Ovh-Tracer-Id":"18091522656851630471","X-VR-SPAMSTATE":"OK","X-VR-SPAMSCORE":"-100","X-VR-SPAMCAUSE":"gggruggvucftvghtrhhoucdtuddrfeelledrgeeigddujedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm","Sender":"kvm-ppc-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<kvm-ppc.vger.kernel.org>","X-Mailing-List":"kvm-ppc@vger.kernel.org"},"content":"The following program causes a kernel oops:\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <sys/ioctl.h>\n#include <linux/kvm.h>\n\nmain()\n{\n    int fd = open(\"/dev/kvm\", O_RDWR);\n    ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_PPC_HTM);\n}\n\nThis happens because when using the global KVM fd with\nKVM_CHECK_EXTENSION, kvm_vm_ioctl_check_extension() gets\ncalled with a NULL kvm argument, which gets dereferenced\nin is_kvmppc_hv_enabled(). Spotted while reading the code.\n\nLet's use the hv_enabled fallback variable, like everywhere\nelse in this function.\n\nFixes: 23528bb21ee2 (\"KVM: PPC: Introduce KVM_CAP_PPC_HTM\")\nCc: stable@vger.kernel.org # v4.7+\nSigned-off-by: Greg Kurz <groug@kaod.org>\n---\n arch/powerpc/kvm/powerpc.c |    3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\n\n--\nTo unsubscribe from this list: send the line \"unsubscribe kvm-ppc\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","diff":"diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c\nindex 3480faaf1ef8..ee279c7f4802 100644\n--- a/arch/powerpc/kvm/powerpc.c\n+++ b/arch/powerpc/kvm/powerpc.c\n@@ -644,8 +644,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)\n \t\tbreak;\n #endif\n \tcase KVM_CAP_PPC_HTM:\n-\t\tr = cpu_has_feature(CPU_FTR_TM_COMP) &&\n-\t\t    is_kvmppc_hv_enabled(kvm);\n+\t\tr = cpu_has_feature(CPU_FTR_TM_COMP) && hv_enabled;\n \t\tbreak;\n \tdefault:\n \t\tr = 0;\n","prefixes":[]}