linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Liam Howlett <liam.howlett@oracle.com>
Cc: "maple-tree@lists.infradead.org" <maple-tree@lists.infradead.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Liu Zixian <liuzixian4@huawei.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Matthew Wilcox <willy@infradead.org>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH] mm/mmap: Fix MAP_FIXED address return on VMA merge
Date: Wed, 19 Oct 2022 16:08:28 +0200	[thread overview]
Message-ID: <e361b003-6437-079b-b42d-a29b72604354@redhat.com> (raw)
In-Reply-To: <20221018202518.zrnoe6ho4lcfuptm@revolver>

>>>    mm/mmap.c | 15 +++++++--------
>>>    1 file changed, 7 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/mm/mmap.c b/mm/mmap.c
>>> index 42cd2c260898..22010e13f1a1 100644
>>> --- a/mm/mmap.c
>>> +++ b/mm/mmap.c
>>> @@ -2625,14 +2625,14 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
>>>    		if (error)
>>>    			goto unmap_and_free_vma;
>>> -		/* Can addr have changed??
>>> -		 *
>>> -		 * Answer: Yes, several device drivers can do it in their
>>> -		 *         f_op->mmap method. -DaveM
>>> +		/*
>>> +		 * Expansion is handled above, merging is handled below.
>>> +		 * Drivers should not alter the address of the VMA.
>>>    		 */
>>> -		WARN_ON_ONCE(addr != vma->vm_start);
>>> -
>>> -		addr = vma->vm_start;
>>> +		if (WARN_ON((addr != vma->vm_start))) {
>>> +			error = -EINVAL;
>>> +			goto close_and_free_vma;
>>> +		}
>>
>> If this is something that user space can trigger, WARN_* is the wrong
>> choice. But what I understand from the comment change is that this must not
>> happen at that point unless there is a real issue.
> 
> The VMA start address could be changed in call_mmap() which is a driver
> call.  I guess someone could write a driver to mmap by a users action?
> I don't think it can be reached other ways.  In any case, I'm changing a
> WARN_ON_ONCE() to a WARN_ON() and undoing the badness instead of
> marching forwards.

WARN_ON_ONCE() can also be used in conditionals if that's what you were 
concerned about, but ...

> 
>>
>> Why not "if (WARN_ON_ONCE)" ?
> 
> I was thinking it was harder to ignore if it happen more frequently?
> There isn't a driver that does this now, but I'm not picky over which
> variant to call.

.. I think the assumption really is that we won't see (m)any these 
calls. And if we do, it's a bad bad driver. So WARN_ON() might be just fine.

If this would be easy to trigger by any user space, WARN* would have 
been the wrong choice, that's why I was asking.

-- 
Thanks,

David / dhildenb



      reply	other threads:[~2022-10-19 14:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 19:17 Liam Howlett
2022-10-18 19:27 ` David Hildenbrand
2022-10-18 19:58   ` Matthew Wilcox
2022-10-18 20:25   ` Liam Howlett
2022-10-19 14:08     ` David Hildenbrand [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=e361b003-6437-079b-b42d-a29b72604354@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgg@nvidia.com \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuzixian4@huawei.com \
    --cc=maple-tree@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=willy@infradead.org \
    /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