Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	dave.hansen@linux.intel.com, kirill.shutemov@linux.intel.com,
	Shakeel Butt <shakeel.butt@linux.dev>,
	SeongJae Park <sj@kernel.org>,
	David Hildenbrand <david@redhat.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Ryan Roberts <ryan.roberts@arm.com>
Subject: Re: untagged_addr_remote() in do_madvise()
Date: Tue, 14 Jan 2025 12:15:30 -0800	[thread overview]
Message-ID: <1053174c-0057-4086-b8c2-360eb2504104@intel.com> (raw)
In-Reply-To: <p2agopwbhdt7nin7wdjjggz3o2wuh4gnqaspoxfemirrjoofls@cg4o4lalbpyw>

On 1/14/25 11:43, Liam R. Howlett wrote:
> Can anyone tell me why the code today is correct?  That is, how can we
> trust the validation of start/end is still okay after we change the
> start/end by untagging the start?

Well, let's walk through the start/end validation.  First:

        if (!PAGE_ALIGNED(start))
                return -EINVAL;

That should stay valid as long as the tag/untag doesn't affect the lower
bits. All the tagging is upper bits that are far away from the
<PAGE_SHIFT bits. I can hardly imagine an implementation that would tag
in the lower bits.

        end = start + len;
        if (end < start)
                return -EINVAL;

This one is a test for negative 'len' and for start+len overflows. It's
certainly possible that a tagged 'start' would overflow when an untagged
'start' would not. But something that overflows that positive/negative
boundary would also cross a tag boundary so it would probably be a bug
anyway.

The last check is:

        if (end == start)
                return 0;

But since 'end' is derived from 'start':

	end = start + len;

I can't think of a way that changing 'start'  (via untagging) will end
up changing the result 'end==start' comparison.

So, is the code "correct"?  The overflow detection can certainly be
triggered with tagged addresses, but it's arguably doing a service in
that case since the input in nonsensical crossing tags.

I'd say it's correct, but far from *obviously* correct. It could
definitely use some clarity.


  reply	other threads:[~2025-01-14 20:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 19:43 untagged_addr_remote() in do_madvise() Liam R. Howlett
2025-01-14 20:15 ` Dave Hansen [this message]
2025-01-14 20:41 ` Lorenzo Stoakes
2025-01-14 21:13   ` Dave Hansen
2025-01-15 11:55     ` 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=1053174c-0057-4086-b8c2-360eb2504104@intel.com \
    --to=dave.hansen@intel.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=sj@kernel.org \
    --cc=vbabka@suse.cz \
    /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