Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1336953imm; Thu, 23 Aug 2018 01:03:33 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw0qVodc6jRTAFgVAr+tR1xhFbMs/aTMo3OSDgtvszKQLhFKer/2z7kiyj/uNRuY2LrIbXG X-Received: by 2002:a17:902:7c0a:: with SMTP id x10-v6mr56874774pll.77.1535011413580; Thu, 23 Aug 2018 01:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535011413; cv=none; d=google.com; s=arc-20160816; b=xUYXicNSl2Gwo7yBz4xdXqQqD3KjkrkclhU8mqN7t64QXB+KusbMQRII/pwZdjPR2A fXsmyDmQYOgrt2wNfjyvBvw8EWpsibb60B7X0IL5UuHLQsDIqnNG2lqSzlWZFfTAg8BW STCLlpIwoYQWdMz1qcGYteftPKNu0jmpTFQ2GAfAkiH4Bj40kVcRtma1TIzj57UrU8MH OqbhXHu87eekyamRn3b53T9nKarocdHB9L7Yc9nOarUWnY6KDJvWEMi9m+rsjXsT3no5 5ug5lf2mKU+D+6bmf4ZK+FDFz7zUhZz5x7vZ2/+TKKJudvTq9cWTUZ6VZzBibsnAuYEj LSyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=h9sgoF/QAlKgoG3u3tK+O5CzD2jj9SyRrbBoafTI52A=; b=a3zTXG17N/idPCJHE2C+msG2h0BHJaJP5nWl989eMCySv4o8/S+RsMqPowKUlH8StZ SDcq3BXgGoVgZYtN10vL7g8NAMdM+txbvDhb3NPJRT/Mg5LuqaQ3zWxDzVVtKoLyispK qUXXnVjfx5rTpaAQ6n9/6TCBFxLofnQs9mjYIXoSSzyYXvcQ19F3X2moAldns/KWR+IK c6UWH5Ca4IKMZ80O4ZGXMYdFxIHBUrkJ2906seeUc5mjKlX4/Q1YBxRB8DdrFgpwE1/U L5yLjepi6DbGSB6LSNpY37fCwvRc3n6HGPF/cZp2eMnRlWLPEhzRPLoT5HxZo3qzH8Nw Y0DA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8-v6si3661391plb.83.2018.08.23.01.03.17; Thu, 23 Aug 2018 01:03:33 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728897AbeHWL3l (ORCPT + 99 others); Thu, 23 Aug 2018 07:29:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727846AbeHWL3k (ORCPT ); Thu, 23 Aug 2018 07:29:40 -0400 Received: from localhost (5355525A.cm-6-6b.dynamic.ziggo.nl [83.85.82.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1438DC74; Thu, 23 Aug 2018 08:01:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Paolo Bonzini , David Hildenbrand , Sudip Mukherjee Subject: [PATCH 4.4 67/79] KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer Date: Thu, 23 Aug 2018 09:53:43 +0200 Message-Id: <20180823074923.544978272@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823074918.641878835@linuxfoundation.org> References: <20180823074918.641878835@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini commit 9432a3175770e06cb83eada2d91fac90c977cb99 upstream. A comment warning against this bug is there, but the code is not doing what the comment says. Therefore it is possible that an EPOLLHUP races against irq_bypass_register_consumer. The EPOLLHUP handler schedules irqfd_shutdown, and if that runs soon enough, you get a use-after-free. Reported-by: syzbot Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Reviewed-by: David Hildenbrand Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- virt/kvm/eventfd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -405,11 +405,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct if (events & POLLIN) schedule_work(&irqfd->inject); - /* - * do not drop the file until the irqfd is fully initialized, otherwise - * we might race against the POLLHUP - */ - fdput(f); #ifdef CONFIG_HAVE_KVM_IRQ_BYPASS irqfd->consumer.token = (void *)irqfd->eventfd; irqfd->consumer.add_producer = kvm_arch_irq_bypass_add_producer; @@ -423,6 +418,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct #endif srcu_read_unlock(&kvm->irq_srcu, idx); + + /* + * do not drop the file until the irqfd is fully initialized, otherwise + * we might race against the POLLHUP + */ + fdput(f); return 0; fail: