Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3599733imm; Sun, 29 Jul 2018 23:27:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfcmz9t3swguXYXpYzCicouG9Vgx2L3ljfrpRGidshmCDOnsmWrYh81AKFAACe9xcqpu6XD X-Received: by 2002:a17:902:7202:: with SMTP id ba2-v6mr14984801plb.179.1532932050124; Sun, 29 Jul 2018 23:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532932050; cv=none; d=google.com; s=arc-20160816; b=IAJ/Xhq4KNq8vDa45vsmFRlCc26VCpAdVvR3l3E5GEevDiDk5plxx00GgKjkNLRQVi lzgPkgHM/tkRkGHMvSUA+QZzEllPseR2te5wGsx6jdmhANMD8i+TkUooYGkh7eq5ftn6 0PyKWdIHJkh6bVuhgNDEhQkE1NLgXx3Tf+kmib1CQfZY6RJgV0z0Hav59THalf8QzxWW f04D+PMr0rY99TtkHzJ7pckbs3JgssTJDMamm3VVGDgcsnUsS4CnQ3GXO7um4aGpdcFD 95r70YuDtyBzX7zC5O5WQbN0pGAiT4u9nQEyxG1Iwc0F0Jk9SdZwYQLaAS7RFOqGgpMh 6Utg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IjaMA+ebK29TOJgXYEaav/KA9IPiV2tRaoxxYKiru7U=; b=XQXyFCjDM/s/cHJx3v+C4e5dlR1QidSaY/hO9Y2SVu8deFX/4rcbCq3+NFkUI9xfKQ Tz5BDDOXI16zemonzSZTCunR9CqzbMRJzS4Yrl/Sfm8fKxws5h13JQyeJ3F5vbZ++L2w qjli3Yqrm6uESCYtZDsMcpVIZBQG9JFAtLylc3nwo6nQg5pKggZews7UnUVWJU5mip7E 1+wl3mqvRtspjd5I0b85atG0V1XCW5CjboYNSVTx2G6wfby3Im7kh5Z/vNkZCO2qNSfi O+tEyupJd1Smw3yksSKecum1uTwG0DLIoWhMvbFggdJMaoih2xA0sN64SjHOMR9rK50H JuBA== 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 q74-v6si11234449pfq.32.2018.07.29.23.27.15; Sun, 29 Jul 2018 23:27: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 S1726497AbeG3H7y (ORCPT + 99 others); Mon, 30 Jul 2018 03:59:54 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46484 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbeG3H7x (ORCPT ); Mon, 30 Jul 2018 03:59:53 -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 w6U6JXb3103827 for ; Mon, 30 Jul 2018 02:26:27 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2khv5ejk24-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 30 Jul 2018 02:26:27 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 30 Jul 2018 07:26:24 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 30 Jul 2018 07:26:20 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6U6QJd936372526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 30 Jul 2018 06:26:19 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54A4611C058; Mon, 30 Jul 2018 09:26:31 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1EDDF11C066; Mon, 30 Jul 2018 09:26:29 +0100 (BST) Received: from rapoport-lnx (unknown [9.148.8.125]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 30 Jul 2018 09:26:28 +0100 (BST) Received: by rapoport-lnx (sSMTP sendmail emulation); Mon, 30 Jul 2018 09:26:16 +0300 From: Mike Rapoport To: Andrew Morton Cc: Eric Biggers , Andrea Arcangeli , Alexander Viro , syzbot , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Mike Rapoport , stable@vger.kernel.org Subject: [PATCH RESEND] userfaultfd: remove uffd flags from vma->vm_flags if UFFD_EVENT_FORK fails Date: Mon, 30 Jul 2018 09:26:15 +0300 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 18073006-0028-0000-0000-000002E23C77 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18073006-0029-0000-0000-0000239A3BD6 Message-Id: <1532931975-25473-1-git-send-email-rppt@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-30_02:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807300073 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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