From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D3B16F060 for ; Sun, 18 Feb 2024 18:48:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282080; cv=none; b=GQ7bvhJxl1AVG+P9VTwwG6Dvv9Gvub/zoRe3P9eBP8MYV9E85ZbhhhIbocht/bLPQTqDwa1vrPfwyOuCHrNGZheWpkxtWeqJwF7TwV7JOO7cTrcbBxBywpMIVIJzZgtVawjxJp4/72n9J5EgIblsofMDtl6YfCzvD7sJxODgNXA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282080; c=relaxed/simple; bh=f7FVt/efY1jGgV5BEBGTUD8jWBdovQDBWLvm0hpGu90=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=CfwEMkRgoUohqny9EuHTLsMgA8N8g1tEf9SQ8FcRuuDWJ4VqKL86ESZAKy5JGAsPyxDHXoh+J/Du0gSH/uvDXegSEf8YsOfkJG7IMwqg77GehbqqyCwajPEpxJoe6GJSIqEm67acVaWUMeP2+DJ8KJ3bRc6jaFGLOid2GPPtpTY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jf4sWxY6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jf4sWxY6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D4F5C433F1; Sun, 18 Feb 2024 18:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708282079; bh=f7FVt/efY1jGgV5BEBGTUD8jWBdovQDBWLvm0hpGu90=; h=Subject:To:Cc:From:Date:From; b=jf4sWxY6DIvprclykQ6QlRPwhnd2bBac5MBnBbfinMSHk1qb3CCnMikD1uggnczRW 8ILwrqDDDJtUR+mAOIai7fblr/ZJ0n3GVFsa2b9D9+PmAWH0fRGe7Ecqq8YGQmNakp gEroyNXjJo7BM8244U8xRFlV34mJosb4AhYyWD0w= Subject: FAILED: patch "[PATCH] userfaultfd: fix mmap_changing checking in" failed to apply to 5.15-stable tree To: lokeshgidra@google.com,aarcange@redhat.com,akpm@linux-foundation.org,axelrasmussen@google.com,bgeffon@google.com,david@redhat.com,jannh@google.com,kaleshsingh@google.com,ngeoffray@google.com,peterx@redhat.com,rppt@kernel.org,stable@vger.kernel.org,surenb@google.com,willy@infradead.org Cc: From: Date: Sun, 18 Feb 2024 19:47:48 +0100 Message-ID: <2024021848-spiny-glitzy-711f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y git checkout FETCH_HEAD git cherry-pick -x 67695f18d55924b2013534ef3bdc363bc9e14605 # git commit -s git send-email --to '' --in-reply-to '2024021848-spiny-glitzy-711f@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 67695f18d55924b2013534ef3bdc363bc9e14605 Mon Sep 17 00:00:00 2001 From: Lokesh Gidra Date: Wed, 17 Jan 2024 14:37:29 -0800 Subject: [PATCH] userfaultfd: fix mmap_changing checking in mfill_atomic_hugetlb In mfill_atomic_hugetlb(), mmap_changing isn't being checked again if we drop mmap_lock and reacquire it. When the lock is not held, mmap_changing could have been incremented. This is also inconsistent with the behavior in mfill_atomic(). Link: https://lkml.kernel.org/r/20240117223729.1444522-1-lokeshgidra@google.com Fixes: df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races") Signed-off-by: Lokesh Gidra Cc: Andrea Arcangeli Cc: Mike Rapoport Cc: Axel Rasmussen Cc: Brian Geffon Cc: David Hildenbrand Cc: Jann Horn Cc: Kalesh Singh Cc: Matthew Wilcox (Oracle) Cc: Nicolas Geoffray Cc: Peter Xu Cc: Suren Baghdasaryan Cc: Signed-off-by: Andrew Morton diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 20e3b0d9cf7e..75fcf1f783bc 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -357,6 +357,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( unsigned long dst_start, unsigned long src_start, unsigned long len, + atomic_t *mmap_changing, uffd_flags_t flags) { struct mm_struct *dst_mm = dst_vma->vm_mm; @@ -472,6 +473,15 @@ static __always_inline ssize_t mfill_atomic_hugetlb( goto out; } mmap_read_lock(dst_mm); + /* + * If memory mappings are changing because of non-cooperative + * operation (e.g. mremap) running in parallel, bail out and + * request the user to retry later + */ + if (mmap_changing && atomic_read(mmap_changing)) { + err = -EAGAIN; + break; + } dst_vma = NULL; goto retry; @@ -506,6 +516,7 @@ extern ssize_t mfill_atomic_hugetlb(struct vm_area_struct *dst_vma, unsigned long dst_start, unsigned long src_start, unsigned long len, + atomic_t *mmap_changing, uffd_flags_t flags); #endif /* CONFIG_HUGETLB_PAGE */ @@ -622,8 +633,8 @@ static __always_inline ssize_t mfill_atomic(struct mm_struct *dst_mm, * If this is a HUGETLB vma, pass off to appropriate routine */ if (is_vm_hugetlb_page(dst_vma)) - return mfill_atomic_hugetlb(dst_vma, dst_start, - src_start, len, flags); + return mfill_atomic_hugetlb(dst_vma, dst_start, src_start, + len, mmap_changing, flags); if (!vma_is_anonymous(dst_vma) && !vma_is_shmem(dst_vma)) goto out_unlock;