From patchwork Wed Jul 18 07:12:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 10531435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30BA76054B for ; Wed, 18 Jul 2018 07:12:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19229290C4 for ; Wed, 18 Jul 2018 07:12:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D4E2290D6; Wed, 18 Jul 2018 07:12:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F8A290C5 for ; Wed, 18 Jul 2018 07:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C31936B0003; Wed, 18 Jul 2018 03:12:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BDD0A6B0005; Wed, 18 Jul 2018 03:12:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7F846B0006; Wed, 18 Jul 2018 03:12:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by kanga.kvack.org (Postfix) with ESMTP id 7BDA46B0003 for ; Wed, 18 Jul 2018 03:12:43 -0400 (EDT) Received: by mail-oi0-f71.google.com with SMTP id e23-v6so3439726oii.10 for ; Wed, 18 Jul 2018 00:12:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:references:mime-version:content-disposition:in-reply-to :user-agent:message-id; bh=5/uezed/WiqonR3+TzSw2eHR6YtUucmy9IQJTKc3bUA=; b=BRE2QcJuFwfRkWEsU1nKTUXYBTLE/rjQiy9BAt4+Dm8wSBKTx4Xz2BVYqW8sNdtKwx rHfMrWnu0JQ9AO3T1jjZ3Yb35o7JfpvQKdNXHyHqxj70PQZwn5zaki8egHfPRTX3e4jR 6MsNJ8soPg1qlhGk7hkqzZOE16cKj7sKMhKMG0+oxcInjYi9atXTYoo4Wa35lTaRNCm7 Hm+/dLSI+uvX2bR0eVnzM49Pnrww1YBfZmw4iqekLoOAUpRuHi16SAED0x5ozdYoBPys BMs11o3NLzKdzZqvF3LGPyT57kVmoJQRcF8dKbChpoSLpqO45L48RGYMqkl8HaL2zoDS LkiQ== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of rppt@linux.vnet.ibm.com) smtp.mailfrom=rppt@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: AOUpUlHupCZIS2vGimjjX8wadP07JjGTQpMpAcZxCezEjjRpYTCM6h1U wMKTO+tBYnyu0mkGFNLQydueLC0iHZbyR0exR5MQy+nwMWqlod0eSqMIdLXMSEymcKBEBM4oKnI OfYI1u6zov3Zx1HgRqTvpygT8Iy7ghwIrpdDt7oPDa1Jn/9zG5Qx7VrXtIjm0HaY= X-Received: by 2002:aca:d7c2:: with SMTP id o185-v6mr5469351oig.55.1531897963269; Wed, 18 Jul 2018 00:12:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcGRQyZHu9hGuKOD74OMsCLMAaHIM545D0rcmHnyJ+uxFLDEsmAA/HNOIdldY7bdq7LN8VU X-Received: by 2002:aca:d7c2:: with SMTP id o185-v6mr5469313oig.55.1531897962214; Wed, 18 Jul 2018 00:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531897962; cv=none; d=google.com; s=arc-20160816; b=oWGAugMQiTMduq4ji60dy8diTPUCkei8qLITWh/dP3HofZFV//wPnJ/8nod+MOTA/5 xvzPhp154NwcKg3fowEYmFmUMnLgMdeClyWh2m+/ZkO4HZrzzfhqMSUz9QP1eVYWtXwH FGWB2rotkDGVcBMlLkLuF+Y1kfyfiMvGBtCTvbiyE5vVtnvGB0cI2i/gremAj3ugCPfW sdqQCy6F8MiUOTdhkP+bT4SVCbeEmCqtVnWbsgEMzuRAgF924sbDj8WUdM0z1vEhHKtV cGpj3+g+9Ihe3oSbDiWkSu7y+p9P8QoamaB5ST5k+DmWjXGtUlnJ+L+Gh3qdBicil7Wv NBsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=N3djkkAOAVSiG9I9lOP8NLPa93gWOK2akQbG8N6tN2u3QWtabtfZ5Y/scN2sjLXOPt D9jJn03HOHdL84aB8uwvvz3ll9j2+nRTEYRcPvXfQawGXIsMdVr9qit9xIUAhxk5Ip+a vme9sSXuJzX0/Zkq3ylYz4iguRMJlBRvaoB7TcncwHuvS8F7ivZlu4bb0xKKIgG6MeOl zD5xDXvN0vlD+496/GXzbuaJHtcbAtZrPXwp5kk35QbkUYFubVLGksYiHvPbh5y2lmrX ZqngN/5kAA0L9PgZO2RoQStyEe677ECnWMlgbVWG9zVWYA6QX80MUJTfg3XKOhJ/9142 pXGA== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of rppt@linux.vnet.ibm.com) smtp.mailfrom=rppt@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id t187-v6si1812131oie.262.2018.07.18.00.12.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 00:12:42 -0700 (PDT) Received-SPF: neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of rppt@linux.vnet.ibm.com) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.156.1 is neither permitted nor denied by best guess record for domain of rppt@linux.vnet.ibm.com) smtp.mailfrom=rppt@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6I78df4031217 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 2ka03k21ky-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-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=868 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807180084 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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);