Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbdLYJHl (ORCPT ); Mon, 25 Dec 2017 04:07:41 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55436 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750862AbdLYJHi (ORCPT ); Mon, 25 Dec 2017 04:07:38 -0500 Date: Mon, 25 Dec 2017 11:07:27 +0200 From: Mike Rapoport To: Andrea Arcangeli Cc: Andrew Morton , Eric Biggers , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH 1/1] userfaultfd: clear the vma->vm_userfaultfd_ctx if UFFD_EVENT_FORK fails References: <20171222222346.GB28786@zzz.localdomain> <20171223002505.593-1-aarcange@redhat.com> <20171223002505.593-2-aarcange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171223002505.593-2-aarcange@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 17122509-0012-0000-0000-0000059CB989 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122509-0013-0000-0000-00001917F245 Message-Id: <20171225090726.GA11724@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-25_06:,, 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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712250125 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2358 Lines: 73 On Sat, Dec 23, 2017 at 01:25:05AM +0100, Andrea Arcangeli wrote: > The previous fix 384632e67e0829deb8015ee6ad916b180049d252 corrected > the refcounting in case of UFFD_EVENT_FORK failure for the fork > userfault paths. That still didn't clear the vma->vm_userfaultfd_ctx > of the vmas that were set to point to the aborted new uffd ctx earlier > in dup_userfaultfd. > > Cc: stable@vger.kernel.org > Signed-off-by: Andrea Arcangeli Reviewed-by: Mike Rapoport > --- > fs/userfaultfd.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c > index 896f810b6a06..1a88916455bd 100644 > --- a/fs/userfaultfd.c > +++ b/fs/userfaultfd.c > @@ -591,11 +591,14 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason) > static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx, > struct userfaultfd_wait_queue *ewq) > { > + struct userfaultfd_ctx *release_new_ctx; Nit: we could have set release_new_ctx to NULL here... > + > if (WARN_ON_ONCE(current->flags & PF_EXITING)) > goto out; > > ewq->ctx = ctx; > init_waitqueue_entry(&ewq->wq, current); > + release_new_ctx = NULL; > > spin_lock(&ctx->event_wqh.lock); > /* > @@ -622,8 +625,7 @@ static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx, > new = (struct userfaultfd_ctx *) > (unsigned long) > ewq->msg.arg.reserved.reserved1; > - > - userfaultfd_ctx_put(new); > + release_new_ctx = new; > } > break; > } > @@ -638,6 +640,20 @@ static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx, > __set_current_state(TASK_RUNNING); > spin_unlock(&ctx->event_wqh.lock); > > + if (release_new_ctx) { > + struct vm_area_struct *vma; > + struct mm_struct *mm = release_new_ctx->mm; > + > + /* 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) > + vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX; > + up_write(&mm->mmap_sem); > + > + userfaultfd_ctx_put(release_new_ctx); > + } > + > /* > * ctx may go away after this if the userfault pseudo fd is > * already released. > -- Sincerely yours, Mike.