Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp201914imm; Wed, 18 Jul 2018 00:13:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfg8318IJlLRALWP/7ZYcrhB5lf8/D7Zf6Crd2ewaNC5Z8HcOc8zrit+tzaZHzmtODDNUiX X-Received: by 2002:a17:902:925:: with SMTP id 34-v6mr4860371plm.103.1531898010941; Wed, 18 Jul 2018 00:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531898010; cv=none; d=google.com; s=arc-20160816; b=hLDjyLAtjZU03KqDf2dr8CmbJkzgHGIlEV0SZ4Qoa+RHU/4O+wFTRUo4ZZUXfUu1q4 autIx8kBraFoNGSnc8lebzhAZcul5W9NnWpQBMap77LW5Q2TwbT9Ib40BG1GxT/qrQUl gHjBsy9MastISANSSGI/O300+wIhwCfsEfttooI33oGz21VQjocx5h/H0K6axoycR0Tf /FAnTJ01XQNmMVUom/ODx+TXPTB9CBtL91L4a9nninp52d4414hnz2tFoQlozx0XUALv 2UkePFIQpv40ZgnxAUinUl/yruPzpnYZ00TKc4rULEnx6/hpDRe4W/wL2zV+OxnuX4cA hjIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :arc-authentication-results; bh=5/uezed/WiqonR3+TzSw2eHR6YtUucmy9IQJTKc3bUA=; b=iFd0kSGuXWL6tkipcpPubyrLqoyiS2ddAa61sHewH7MelrIStiLqT5wt/Frqp416n4 jmPIfZOZ4po3jhV0YL38fgcVcRZZXJJbku7CjiSe4CrXhstCiaEasvaj9OupUZasPCS9 YA6WYVYJYhLW6Gum8BuTZjnKk62eKUyYv8STeE92T0pzQIMJCYZRuEOPzRjSWT+/tLgP lZaMAdFMZgsijwpVx15jytlp3Es/2zX28A/KbQe5fz582XkHUiT/0L0yE+q3SPVMsdtF 9fwOXzwo/iR/A+rttimb8IQxARNYgj1BhEKCbtoF2M6zI5GFHml8ftfVu3R/cfJS1p3Y XCnw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n125-v6si2903631pga.376.2018.07.18.00.13.16; Wed, 18 Jul 2018 00:13:30 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbeGRHtG (ORCPT + 99 others); Wed, 18 Jul 2018 03:49:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53106 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbeGRHtF (ORCPT ); Wed, 18 Jul 2018 03:49:05 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6I78eEL073478 for ; Wed, 18 Jul 2018 03:12:41 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ka0hxh0vv-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Jul 2018 03:12:41 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jul 2018 08:12:38 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 18 Jul 2018 08:12:34 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6I7CXLj27590852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Jul 2018 07:12:33 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE18842045; Wed, 18 Jul 2018 10:12:51 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 253884204D; Wed, 18 Jul 2018 10:12:51 +0100 (BST) Received: from rapoport-lnx (unknown [9.148.8.216]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 18 Jul 2018 10:12:51 +0100 (BST) Date: Wed, 18 Jul 2018 10:12:31 +0300 From: Mike Rapoport To: Eric Biggers Cc: Andrea Arcangeli , syzbot , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk Subject: Re: kernel BUG at fs/userfaultfd.c:LINE! (2) References: <000000000000dcb1a1057112c66a@google.com> <20180717192806.GI75957@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180717192806.GI75957@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18071807-0008-0000-0000-000002547029 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071807-0009-0000-0000-000021BAC50C Message-Id: <20180718071230.GA4302@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-18_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=869 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807180084 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 12:28:06PM -0700, Eric Biggers wrote: > [+Cc userfaultfd developers and linux-mm] > > The reproducer hits the BUG_ON() in userfaultfd_release(): > > BUG_ON(!!vma->vm_userfaultfd_ctx.ctx ^ > !!(vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP))); Thanks for the CC. The fix is below. -- Sincerely yours, Mike. From 3711b6a72abe3796b2b97fdba8eadd995b29f195 Mon Sep 17 00:00:00 2001 From: Mike Rapoport Date: Wed, 18 Jul 2018 09:45:54 +0300 Subject: [PATCH] userfaultfd: remove uffd flags from vma->vm_flags if UFFD_EVENT_FORK fails The fix in commit 0cbb4b4f4c44 ("userfaultfd: clear the vma->vm_userfaultfd_ctx if UFFD_EVENT_FORK fails") cleared the vma->vm_userfaultfd_ctx but kept userfaultfd flags in vma->vm_flags that were copied from the parent process VMA. As the result, there is an inconsistency between the values of vma->vm_userfaultfd_ctx.ctx and vma->vm_flags which triggers BUG_ON in userfaultfd_release(). Clearing the uffd flags from vma->vm_flags in case of UFFD_EVENT_FORK failure resolves the issue. Signed-off-by: Mike Rapoport Reported-by: syzbot+121be635a7a35ddb7dcb@syzkaller.appspotmail.com Cc: Andrea Arcangeli Cc: Eric Biggers Cc: stable@vger.kernel.org --- fs/userfaultfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 594d192b2331..bad9cea37f12 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -633,8 +633,10 @@ static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx, /* the various vma->vm_userfaultfd_ctx still points to it */ down_write(&mm->mmap_sem); for (vma = mm->mmap; vma; vma = vma->vm_next) - if (vma->vm_userfaultfd_ctx.ctx == release_new_ctx) + if (vma->vm_userfaultfd_ctx.ctx == release_new_ctx) { vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; + vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING); + } up_write(&mm->mmap_sem); userfaultfd_ctx_put(release_new_ctx); -- 2.7.4