Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4163588imu; Tue, 18 Dec 2018 10:02:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/UOrs844vkqPiBVjTSsokxQMtR0dKhWwCWnUOl8yVshCAM6bl3Xc1EM0vcdyup04OuUUBrB X-Received: by 2002:a63:1204:: with SMTP id h4mr16541245pgl.51.1545156158015; Tue, 18 Dec 2018 10:02:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545156157; cv=none; d=google.com; s=arc-20160816; b=Gyf0efqGtPE4T5m29Aivi1Gu3pJbRwU93ZgBrCcAOm8HRMtyMmVevCoffe4kzLb36d BRd97ndtDYRTnA7f8J2jSsI/645rMB6fmBaCrSiDirDm4VyehwAUWAwTc4Yw3o7ULJEr hsYNSwbIEF2Rmka4ZhfVeunnxBXJyB+A7CaZDbk6+sIRu92L/ilU88xjqWcLSp9spO3f R/RHHWV0r4fy2op0U5LTO1BLUsGrVju0KZ7Zxtma1Ga/AAq/Si0Ah59T7rLqA/EKSNT7 WEUtuVcZj9sJux47ZSLhm9BPa6tvzyUSRiLbZZLw6EsBwIf/m37XVItBoXTvvj5Zvq6o Mf2w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QocdDvU6DhAOo9MQL4YZRjAkaZNpXddIPH362svf4lM=; b=WZPsuSCmr+d2UAsMfLajJy80bbygGplgZyGX1wCgN4nurVM5J4O0ZAU8XpkgutZk/I OTO7AVOWRJdhLjzqbe3NQXIuDsTne5lp3Qg1zNgyG2eVEXq8XH4yWI2uDFVeKoVKcCsX zL/fcNLuIVyQUIoMGn3s2lw0/Y0IicIhRN77EdKXw5FOaLs8vAUZ2PTf1sBmdI187oWq pPMy9qkM2/hYUOv/Bjy9go0e5z0SCZYz6o4Bk0gCJK1mHi91tli8quPhyFW6Vpeeyx8o vdn4WKo6ItZTauhgjr32PUYQB7YboSWuYiCtJfJnMu4E66uu6yqXUM40//LsOD4zKYjS IdkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xP78srxL; 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 g10si13195309plq.371.2018.12.18.10.02.21; Tue, 18 Dec 2018 10:02:37 -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=@kernel.org header.s=default header.b=xP78srxL; 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 S1727432AbeLRQk7 (ORCPT + 99 others); Tue, 18 Dec 2018 11:40:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:38132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727394AbeLRQkx (ORCPT ); Tue, 18 Dec 2018 11:40:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7D35C218A3; Tue, 18 Dec 2018 16:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545151253; bh=1Lm//mzU2e0gxuE+a3YjC4vogDBirIO5eOvwbikJxGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xP78srxL32O2h0rxcJH40BOjuxQ+dGVw+RSVOHy9HDwKRGIuhrEVEB+M3cCUY6oN3 VuoEuHLiCwjDGzWJFvStrBPi9vpL3KttXxCe/c58osJ9JNxUdKAirknFXCY3WvrSQk hrEahlAqXZ7wnKQFDyTGxi7S0oG7WIvtVFmsHn1E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrea Arcangeli , syzbot+06c7092e7d71218a2c16@syzkaller.appspotmail.com, Mike Rapoport , Hugh Dickins , Peter Xu , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 12/44] userfaultfd: check VM_MAYWRITE was set after verifying the uffd is registered Date: Tue, 18 Dec 2018 17:39:24 +0100 Message-Id: <20181218163928.971029930@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181218163927.119623235@linuxfoundation.org> References: <20181218163927.119623235@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Arcangeli commit 01e881f5a1fca4677e82733061868c6d6ea05ca7 upstream. Calling UFFDIO_UNREGISTER on virtual ranges not yet registered in uffd could trigger an harmless false positive WARN_ON. Check the vma is already registered before checking VM_MAYWRITE to shut off the false positive warning. Link: http://lkml.kernel.org/r/20181206212028.18726-2-aarcange@redhat.com Cc: Fixes: 29ec90660d68 ("userfaultfd: shmem/hugetlbfs: only allow to register VM_MAYWRITE vmas") Signed-off-by: Andrea Arcangeli Reported-by: syzbot+06c7092e7d71218a2c16@syzkaller.appspotmail.com Acked-by: Mike Rapoport Acked-by: Hugh Dickins Acked-by: Peter Xu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/userfaultfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1566,7 +1566,6 @@ static int userfaultfd_unregister(struct cond_resched(); BUG_ON(!vma_can_userfault(vma)); - WARN_ON(!(vma->vm_flags & VM_MAYWRITE)); /* * Nothing to do: this vma is already registered into this @@ -1575,6 +1574,8 @@ static int userfaultfd_unregister(struct if (!vma->vm_userfaultfd_ctx.ctx) goto skip; + WARN_ON(!(vma->vm_flags & VM_MAYWRITE)); + if (vma->vm_start > start) start = vma->vm_start; vma_end = min(end, vma->vm_end);