Received: by 10.223.176.46 with SMTP id f43csp1399265wra; Fri, 19 Jan 2018 10:58:13 -0800 (PST) X-Google-Smtp-Source: ACJfBotv7oAROROskW3MOLvNlJddXEvfQcz+o5dJ/vknea9K4V4k+nUY8uWu2TQrD8OG0U58tdEE X-Received: by 10.101.80.204 with SMTP id s12mr25988859pgp.185.1516388293378; Fri, 19 Jan 2018 10:58:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516388293; cv=none; d=google.com; s=arc-20160816; b=x9VazNuoBgy3EzWCN+7kwdB0ta67tCHCe5F5wIlflixSnkoarhe/jv6eFbBSWPWMfF ebDGKfkzL+OHzB5e9SSxa1ybXEBeMydV3nspGnS6zlnA2akOJJKZqGNgQUJugEsd3bpq wbqj2TKtqoJs9Y/uNpOD5zSjiwm/tca2HQF3otKdYsSZswNbT57Ez0ltfHRa8kWbADoW pMwZmvjsC1VDJ7JDmkGl5gK7OX5xmW807+Lo2vKuUVycG6bAYziwOKK3lRxpFrR9G0Ze Q6fo1VBxsXIRwrZWGTuScMgRUJF2B4w6QA7M6ppj3X2wX3IyzOqRQv5+wBj+2KBUIVrC pzhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=8iUZQvkeT0DpnVbQRlLCUoHFNwDFHaIJWhGXtG7c2RU=; b=XUXJ+yKnkZsF0qw1Mc2fGenLNG6o5OYdj/2GV7msBBz6+jcgi947nZwr88VfJ2jRBg rVJwHc7N4kx93xKOHvMD6C2uifhVjDWNxOUGAh+QIvkQJ/Irh+VWVAOyL2cjdo9Sfb31 qmZlp2K+LR1WEGhzPSVnXJYCwt+ME9CJfBsBFCrRO8kHEAqLBv6d/o4nUYWq2uPXxveE DUS2sZeFIwTllJS3d8SFqaLa5w4QL5NAlhqZH1uQlcN5sgN8BYL3OfvyAPRpESxHVzE1 xMjHOhoIkBUI/2iAIGNvunRYHGl0p1qLAnO/HaZrkKKw/ZFwTIiaQa7mKeQemcAhX2nw PLxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lok1Myp1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s134si8605480pgs.301.2018.01.19.10.57.58; Fri, 19 Jan 2018 10:58:13 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lok1Myp1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756168AbeASS53 (ORCPT + 99 others); Fri, 19 Jan 2018 13:57:29 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:40857 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755830AbeASS5U (ORCPT ); Fri, 19 Jan 2018 13:57:20 -0500 Received: by mail-io0-f194.google.com with SMTP id t22so3193398ioa.7; Fri, 19 Jan 2018 10:57:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8iUZQvkeT0DpnVbQRlLCUoHFNwDFHaIJWhGXtG7c2RU=; b=lok1Myp17Bx9x1+nuLB/D9iKqkTb4eDmT8s7m5yg5/yAapA0UF9HUB6ZZQC3Jal7+f Pa24rGxbINb48p0X6t8UwwYa0ZUv4PkenlqzYfWxzM6j/Z7uL/TS6EhJssL3njmdXu6Z Wzxsk9CqM8ZjgNnEw8r8IK0p8tdkQ5yxBYUvY9bHM/GJYr+c4EaDxC2OzdlGNks3Y8+S 1ivtQgV8hFIRpcUlyES+TcV6akLd3xalJhkcvNONDBTojfxsAYl/oCch09cxul6WHQT7 MWs6PC4TksSqZW292Cdfm9RZCSMaRfYyO072SlOVOYDMW8PYCgeNVi3CztmPe+XzZYhr I3Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8iUZQvkeT0DpnVbQRlLCUoHFNwDFHaIJWhGXtG7c2RU=; b=X/BWcVMSB5+eicqAcmgPEoJ3cMyVR7LYTJwdNODvOKQA7WFeAXRvleL8p/YIvaqOL8 +lXZ10mslw2Cz2+8Cwbkr8ua5yEncEGuEVe258FuyIkTHVPAMaQM+Ji+8AycwYMmGibF 3VL2bl6ujsc695K/B91TgLFxrcYzqLyCTRmBqEQtcRfeU9ML3lHjFM3eDba6xdhw8R4Y Z3J6hKDqJQ3qWYfvKFJBTqsS5GFs3+pE0ToA8U5szJjkGJkk/LFPrZu+zPFDaWSpYS+D 8/+wNwB4VmQPzgKPVfeOAHpCR85NeaQf/XPlRQ1Ly2KVMg2nZFlFmPYYDgBS+9hdTnga s2AQ== X-Gm-Message-State: AKwxytf52mGoLCBExXitngIoK6teB5ifwy3yQyHt6rd9A7M9A4fLDaPe ic3jvZjE5+yI6jgFYj2taEU= X-Received: by 10.107.178.195 with SMTP id b186mr30608670iof.9.1516388239310; Fri, 19 Jan 2018 10:57:19 -0800 (PST) Received: from gmail.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id j204sm1098734itj.37.2018.01.19.10.57.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jan 2018 10:57:18 -0800 (PST) Date: Fri, 19 Jan 2018 10:57:16 -0800 From: Eric Biggers To: Wanpeng Li Cc: kvm , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Eric Biggers , "# v3 . 10+" , Alex Williamson Subject: Re: [PATCH] KVM: prevent overlap between user and private memslots Message-ID: <20180119185716.rmjh7nts6cubkvgw@gmail.com> References: <94eb2c06f65e7ece95055cf1aafd@google.com> <20180119081820.30803-1-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +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