linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lstoakes@gmail.com>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/7] mm/gup: remove vmas parameter from get_user_pages_remote()
Date: Sat, 15 Apr 2023 11:14:08 +0100	[thread overview]
Message-ID: <63d92734-2185-439c-bbc7-53a4720f5d4a@lucifer.local> (raw)
In-Reply-To: <b4706369-f97c-8b78-f194-b45a870114e1@I-love.SAKURA.ne.jp>

On Sat, Apr 15, 2023 at 06:52:41PM +0900, Tetsuo Handa wrote:
> On 2023/04/15 18:08, Lorenzo Stoakes wrote:
> > @@ -475,10 +474,14 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
> >  		gup_flags |= FOLL_SPLIT_PMD;
> >  	/* Read the page with vaddr into memory */
> >  	ret = get_user_pages_remote(mm, vaddr, 1, gup_flags,
> > -				    &old_page, &vma, NULL);
> > +				    &old_page, NULL);
> >  	if (ret <= 0)
> >  		return ret;
> >
> > +	vma = vma_lookup(mm, vaddr);
> > +	if (!vma)
> > +		goto put_old;
> > +
> >  	ret = verify_opcode(old_page, vaddr, &opcode);
> >  	if (ret <= 0)
> >  		goto put_old;
>
> This conversion looks wrong.
> This causes returning a positive number when vma_lookup() returned NULL.
>
>   * Return 0 (success) or a negative errno.
>

In reality it shouldn't be possible for vma to return NULL, I'm adding the
checks to be extra careful.

In any case you're right, attaching a -fix patch to avoid spam:-

----8<----
From 0710d01ea69ad4e846fa1e56a40b253ff59714ac Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <lstoakes@gmail.com>
Date: Sat, 15 Apr 2023 11:09:15 +0100
Subject: [PATCH] mm/gup: remove vmas parameter from get_user_pages_remote()

Correct vma NULL check as indicated by Tetsuo.

Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
---
 kernel/events/uprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index b21993cd2dcc..affe42a13eff 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -479,8 +479,10 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
 		return ret;
 
 	vma = vma_lookup(mm, vaddr);
-	if (!vma)
+	if (!vma) {
+		ret = -EINVAL;
 		goto put_old;
+	}
 
 	ret = verify_opcode(old_page, vaddr, &opcode);
 	if (ret <= 0)
-- 
2.40.0



  reply	other threads:[~2023-04-15 10:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15  9:06 [PATCH v2 0/7] remove the vmas parameter from GUP APIs Lorenzo Stoakes
2023-04-15  9:07 ` [PATCH v2 1/7] mm/gup: remove unused vmas parameter from get_user_pages() Lorenzo Stoakes
2023-04-15  9:08 ` [PATCH v2 2/7] mm/gup: remove unused vmas parameter from pin_user_pages_remote() Lorenzo Stoakes
2023-04-15  9:08 ` [PATCH v2 3/7] mm/gup: remove vmas parameter from get_user_pages_remote() Lorenzo Stoakes
2023-04-15  9:52   ` Tetsuo Handa
2023-04-15 10:14     ` Lorenzo Stoakes [this message]
2023-04-15 10:36       ` Tetsuo Handa
2023-04-15 11:27         ` Lorenzo Stoakes
2023-04-15 11:40           ` Tetsuo Handa
2023-04-15 11:48             ` Lorenzo Stoakes
2023-04-15  9:08 ` [PATCH v2 4/7] mm/gup: introduce the FOLL_SAME_FILE GUP flag Lorenzo Stoakes
2023-04-15  9:08 ` [PATCH v2 5/7] io_uring: rsrc: use FOLL_SAME_FILE on pin_user_pages() Lorenzo Stoakes
2023-04-15  9:08 ` [PATCH v2 6/7] mm/gup: remove vmas parameter from pin_user_pages() Lorenzo Stoakes
2023-04-15  9:09 ` [PATCH v2 7/7] mm/gup: remove vmas array from internal GUP functions Lorenzo Stoakes

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=63d92734-2185-439c-bbc7-53a4720f5d4a@lucifer.local \
    --to=lstoakes@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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;
as well as URLs for NNTP newsgroup(s).