linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
	Hugh Dickins <hughd@google.com>,
	 Axel Rasmussen <axelrasmussen@google.com>,
	Peter Xu <peterx@redhat.com>,
	 linux-mm@kvack.org
Subject: [PATCH mm-unstable fix] mm: userfaultfd: add new UFFDIO_POISON ioctl: fix
Date: Tue, 11 Jul 2023 18:27:17 -0700 (PDT)	[thread overview]
Message-ID: <bc7bba61-d34f-ad3a-ccf1-c191585ef851@google.com> (raw)

Smatch has observed that pte_offset_map_lock() is now allowed to fail,
and then ptl should not be unlocked.  Use -EAGAIN here like elsewhere.

Signed-off-by: Hugh Dickins <hughd@google.com>
---
Axel, Peter: this seems right as a fix to the patch in mm-unstable;
but in preparing this, I noticed mfill_atomic()'s code before calling
mfill_atomic_pte(), and think that my original choice of -EFAULT was
therefore better than -EAGAIN for all of these; and that mfill_atomic()'s
BUG_ONs there would be better deleted (and is its BUG_ON(folio) safe??).
Something one of us should address, after this fixup is in akpm's tree.

 mm/userfaultfd.c | 4 ++++
 1 file changed, 4 insertions(+)

--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -300,7 +300,10 @@ static int mfill_atomic_pte_poison(pmd_t *dst_pmd,
 	spinlock_t *ptl;
 
 	_dst_pte = make_pte_marker(PTE_MARKER_POISONED);
+	ret = -EAGAIN;
 	dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl);
+	if (!dst_pte)
+		goto out;
 
 	if (mfill_file_over_size(dst_vma, dst_addr)) {
 		ret = -EFAULT;
@@ -319,6 +322,7 @@ static int mfill_atomic_pte_poison(pmd_t *dst_pmd,
 	ret = 0;
 out_unlock:
 	pte_unmap_unlock(dst_pte, ptl);
+out:
 	return ret;
 }
 


             reply	other threads:[~2023-07-12  1:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12  1:27 Hugh Dickins [this message]
2023-07-12 18:16 ` Axel Rasmussen
2023-07-14  2:40   ` Hugh Dickins
2023-07-19 21:53     ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bc7bba61-d34f-ad3a-ccf1-c191585ef851@google.com \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox