Received: by 10.223.185.116 with SMTP id b49csp3712270wrg; Tue, 13 Feb 2018 06:39:38 -0800 (PST) X-Google-Smtp-Source: AH8x225OVTVp95TViq7T+DGKdgVcWJCcnWCqi8B1kQ8FU8nlV7+lp7Mx3xsa80/bJ9dv3U6aYZFb X-Received: by 10.99.191.78 with SMTP id i14mr1188897pgo.9.1518532778286; Tue, 13 Feb 2018 06:39:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518532778; cv=none; d=google.com; s=arc-20160816; b=lv5/86MsnviqVuSe7XzPrCyFa224kUYAKsyvRMqUmPFZDtGTuSzQc83zd4b/t+peSD M8N+T+Jn1q46/H98jJZGlMJ4cQQ184huXU/+WnBbJZQCEVNLqOb1pV9H7+HkzY3cX7h/ sFe58ZeK3gldalkHZHRnreb4wupEQgJccN3GMFNA0xktZ127J4UJWZqv8N7HIfIbe51Q 2HaiCmgEhsj/6+aYhyc7zb67zAJongGZdqd7hwMDEenF7H5y1Tgxsxy9rwKzP7jPRpZq ijwE1orUPnrUJ6/o87yEqXG5JvZD+LEBla6yZ6ktQvzMZIP0i2KEhiw1/nDzTZ/JEmm2 sfLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=oZJ7hEAq4w3ocC6Fb2OfEJx2ze6PlMZxP6tM98P6yio=; b=s8JNokXdsT0q1HmkiBDuQxPvYZ2VGvB89AuK05HhauTvC6cQlnQ2NC2hzjbvoPKovs /af3xLBcRWa/u4ScmyhOHJ6Ql3/R6i5FAj4jDQIlJUwYejb0ZBDXhaZ4t+11BtlJ4ghl X7tzkWlq48zLJzabH1boQeShAfCQLT4NcRkXQ/Mqw4fDsDUMfeeif/d4qawT+ELcHSwE S7597Jayz1B3o7rbw15PlEEKnu6/lQdXi7dQZc/Q+mbxQ0n2+qwO4hPEbE7usAkU8EWx BiT3Jd/ITB1By4XSExil/8zCARBQdTqeZO1+G3qAiZQwKjI75jGwJ6meL8doNPRGK0bc X0AQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e10si2746032pfn.81.2018.02.13.06.39.20; Tue, 13 Feb 2018 06:39:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935470AbeBMOiI (ORCPT + 99 others); Tue, 13 Feb 2018 09:38:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58912 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935370AbeBMOiG (ORCPT ); Tue, 13 Feb 2018 09:38:06 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9715E7C81F; Tue, 13 Feb 2018 14:38:05 +0000 (UTC) Received: from [10.36.116.223] (ovpn-116-223.ams2.redhat.com [10.36.116.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2D202024CA2; Tue, 13 Feb 2018 14:38:03 +0000 (UTC) Subject: Re: [PATCH] KVM: prevent overlap between user and private memslots To: Eric Biggers , Wanpeng Li Cc: kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Eric Biggers , stable@vger.kernel.org, Alex Williamson References: <94eb2c06f65e7ece95055cf1aafd@google.com> <20180119081820.30803-1-ebiggers3@gmail.com> <20180119185716.rmjh7nts6cubkvgw@gmail.com> <20180130204921.trzixusqdorm4a7w@gmail.com> <20180213033821.GA23301@zzz.localdomain> From: Paolo Bonzini Message-ID: Date: Tue, 13 Feb 2018 15:38:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180213033821.GA23301@zzz.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Feb 2018 14:38:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 13 Feb 2018 14:38:05 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/02/2018 04:38, Eric Biggers wrote: > On Tue, Jan 30, 2018 at 12:49:21PM -0800, Eric Biggers wrote: >> On Fri, Jan 19, 2018 at 10:57:16AM -0800, Eric Biggers wrote: >>> +Cc alex.williamson@redhat.com >>> >>> On Fri, Jan 19, 2018 at 05:03:47PM +0800, Wanpeng Li wrote: >>>> 2018-01-19 17:01 GMT+08:00 Wanpeng Li : >>>>> 2018-01-19 16:18 GMT+08:00 Eric Biggers : >>>>>> From: Eric Biggers >>>>>> >>>>>> Memslots must not overlap in guest physical memory, since otherwise some >>>>>> guest physical addresses will not uniquely map to a memslot. Yet, the >>>>>> overlap check in __kvm_set_memory_region() allows a memslot that >>>>>> overlaps one of the "private" memslots, e.g. the memslot reserved for >>>>>> the TSS on x86. >>>>>> >>>>>> This seems to be a very old bug that was introduced years ago when >>>>>> private memory slots were first added. It seems that later refactoring >>>>>> incorrectly assumed this bug was intentional and preserved it. >>>>>> >>>>>> Fix it by removing the loophole for private memslots, so we just check >>>>>> for overlap against all memslots. >>>>>> >>>>>> This bug was found by syzkaller, which used a memslot overlap to make >>>>>> pte_list_remove() be called for the wrong memslot, hitting a BUG(): >>>>>> >>>>>> pte_list_remove: 000000007185ed42 0->BUG >>>>>> kernel BUG at arch/x86/kvm/mmu.c:1209! >>>>>> [...] >>>>>> RIP: 0010:pte_list_remove+0x107/0x110 arch/x86/kvm/mmu.c:1208 >>>>>> [...] >>>>>> Call Trace: >>>>>> mmu_page_zap_pte+0x7e/0xd0 arch/x86/kvm/mmu.c:2499 >>>>>> kvm_mmu_page_unlink_children arch/x86/kvm/mmu.c:2521 [inline] >>>>>> kvm_mmu_prepare_zap_page+0x4f/0x340 arch/x86/kvm/mmu.c:2565 >>>>>> kvm_zap_obsolete_pages arch/x86/kvm/mmu.c:5348 [inline] >>>>>> kvm_mmu_invalidate_zap_all_pages+0xa6/0x100 arch/x86/kvm/mmu.c:5389 >>>>>> kvm_mmu_notifier_release+0x4f/0x80 arch/x86/kvm/../../../virt/kvm/kvm_main.c:468 >>>>>> __mmu_notifier_release+0x63/0x100 mm/mmu_notifier.c:75 >>>>>> mmu_notifier_release include/linux/mmu_notifier.h:244 [inline] >>>>>> exit_mmap+0x160/0x170 mm/mmap.c:3009 >>>>>> __mmput kernel/fork.c:966 [inline] >>>>>> mmput+0x44/0xd0 kernel/fork.c:987 >>>>>> exit_mm kernel/exit.c:544 [inline] >>>>>> do_exit+0x24a/0xb50 kernel/exit.c:856 >>>>>> do_group_exit+0x34/0xb0 kernel/exit.c:972 >>>>>> SYSC_exit_group kernel/exit.c:983 [inline] >>>>>> SyS_exit_group+0xb/0x10 kernel/exit.c:981 >>>>>> entry_SYSCALL_64_fastpath+0x1e/0x8b >>>>>> >>>>>> Reproducer: >>>>>> >>>>>> #include >>>>>> #include >>>>>> #include >>>>>> >>>>>> int main() >>>>>> { >>>>>> static char buf[4096*3] __attribute__((aligned(4096))); >>>>>> int kvm, vm, cpu; >>>>>> struct kvm_mp_state mp_state = { KVM_MP_STATE_SIPI_RECEIVED }; >>>>>> struct kvm_userspace_memory_region memreg = { >>>>>> .memory_size = sizeof(buf), >>>>>> .userspace_addr = (__u64)buf, >>>>>> }; >>>>>> >>>>>> kvm = open("/dev/kvm", O_RDWR); >>>>>> vm = ioctl(kvm, KVM_CREATE_VM, 0); >>>>>> ioctl(vm, KVM_CREATE_IRQCHIP); >>>>>> cpu = ioctl(vm, KVM_CREATE_VCPU, 0); >>>>>> ioctl(cpu, KVM_SET_MP_STATE, &mp_state); >>>>>> ioctl(vm, KVM_SET_TSS_ADDR, 0); >>>>>> ioctl(cpu, KVM_RUN, 0); >>>>>> ioctl(vm, KVM_SET_USER_MEMORY_REGION, &memreg); >>>>>> } >>>>>> >>>>>> Reported-by: syzbot >>>>>> Fixes: e0d62c7f4860 ("KVM: Add kernel-internal memory slots") >>>>>> Cc: # v2.6.25+ >>>>>> Signed-off-by: Eric Biggers >>>>> >>>>> Please refer to this one. https://patchwork.kernel.org/patch/9645377/ >>>> >>>> https://lkml.org/lkml/2017/3/27/57 >>>> >>> >>> Ah, so this was reported before, and you sent the same fix. Well, it was never >>> applied, so the bug is still there, and anyone who can use /dev/kvm can trigger >>> it. So one of these patches needs to be applied, unless there is a better fix. >>> >>> I don't agree with the "Fixes:" line in your version of the patch. The bug was >>> actually there prior to 5419369ed, which might explain why that commit seemed to >>> preserve the behavior intentionally. (Note that KVM_MEMORY_SLOTS did not >>> include the private memory slots; it was later renamed to KVM_USER_MEM_SLOTS.) >>> >>> Eric >> >> Ping. Paolo or Radim, can you please consider applying one of these patches? Applied, thanks. Paolo