linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miles Chen <miles.chen@mediatek.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Peter Xu <peterx@redhat.com>,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	wsd_upstream@mediatek.com
Subject: Re: [PATCH] mm/gup: fix null pointer dereference detected by coverity
Date: Wed, 15 Apr 2020 09:53:26 +0800	[thread overview]
Message-ID: <1586915606.5647.5.camel@mtkswgap22> (raw)
In-Reply-To: <20200414170827.d32fc1fc12a33b140b740b94@linux-foundation.org>

On Tue, 2020-04-14 at 17:08 -0700, Andrew Morton wrote:
> On Tue, 7 Apr 2020 17:51:07 +0800 Miles Chen <miles.chen@mediatek.com> wrote:
> 
> > In fixup_user_fault(), it is possible that unlocked is NULL,
> > so we should test unlocked before using it.
> > 
> > For example, in arch/arc/kernel/process.c, NULL is passed
> > to fixup_user_fault().
> > 
> > SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
> > {
> > ...
> > 	ret = fixup_user_fault(current, current->mm, (unsigned long) uaddr,
> > 			       FAULT_FLAG_WRITE, NULL);
> > ...
> > }
> 
> (cc Peter)
> 
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -1230,7 +1230,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
> >  	if (ret & VM_FAULT_RETRY) {
> >  		down_read(&mm->mmap_sem);
> >  		if (!(fault_flags & FAULT_FLAG_TRIED)) {
> > -			*unlocked = true;
> > +			if (unlocked)
> > +				*unlocked = true;
> >  			fault_flags |= FAULT_FLAG_TRIED;
> >  			goto retry;
> >  		}
> 
> Not sure.  If the caller passes FAULT_FLAG_ALLOW_RETRY then they must
> also pass in a valid non-NULL `unlocked'.  If the caller passed
> FAULT_FLAG_ALLOW_RETRY and unlocked==NULL then the resulting oops is an
> appropriate way of reporting this mistake.  I think?
> 
Agree. How about put "unlocked==NULL must not be used with
FAULT_FLAG_ALLOW_RETRY." in the comment? Make it easier to understand
the oops.

e.g., 

--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1176,7 +1176,8 @@ static bool vma_permits_fault(struct
vm_area_struct *vma,
  * @address:   user address
  * @fault_flags:flags to pass down to handle_mm_fault()
  * @unlocked:  did we unlock the mmap_sem while retrying, maybe NULL if
caller
- *             does not allow retry
+ *             does not allow retry. If NULL, the caller must guarantee
+ *             the fault_flags does not contain FAULT_FLAG_ALLOW_RETRY.


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

      reply	other threads:[~2020-04-15  2:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07  9:51 [PATCH] mm/gup: fix null pointer dereference detected by coverity Miles Chen
2020-04-07 18:19 ` Ira Weiny
2020-04-14 19:55   ` Souptick Joarder
2020-04-15  0:08 ` Andrew Morton
2020-04-15  1:53   ` Miles Chen [this message]

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=1586915606.5647.5.camel@mtkswgap22 \
    --to=miles.chen@mediatek.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=wsd_upstream@mediatek.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;
as well as URLs for NNTP newsgroup(s).