linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Muhammad Usama Anjum <Usama.Anjum@collabora.com>
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	Kees Cook <keescook@chromium.org>
Subject: Re: [bug report] fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs
Date: Thu, 12 Sep 2024 13:06:08 +0300	[thread overview]
Message-ID: <69e01b95-fcf1-4168-8aa9-708623ec3956@stanley.mountain> (raw)
In-Reply-To: <d3db84fc-c107-423d-9f02-3cae0217b576@collabora.com>

On Thu, Sep 12, 2024 at 02:34:54PM +0500, Muhammad Usama Anjum wrote:
> On 9/12/24 11:36 AM, Muhammad Usama Anjum wrote:
> > Hi Dan,
> > 
> > Thank you for reporting.
> I've debugged more and found out that no changes are required as
> access_ok() already deals well with the overflows. I've tested the
> corner cases on x86_64 and there are no issue found.
> 
> I'll add more test cases in the selftest for this ioctl. Please share
> your thoughts if I may have missed something.
> 

I don't understand what you are saying.  We are discussing three issues:

1)  We check the size and then make the size larger:

    check: if (!access_ok((void __user *)(long)arg->start, arg->end - arg->start))
    larger: arg->end = ALIGN(arg->end, PAGE_SIZE);

The ALIGN() can't make ->end go beyond the end of the page so it's possible that
if you have access_ok to the start of the page then you have access to the whole
page.  It just seems ugly to rely on that.  (I don't know mm very well).

2) Passing negative sizes to access_ok().

The access_ok() check will treat negative sizes as very large positive sizes and
it will be rejected.  So far as I can see this is fine.  Plus there is a check
at the start of walk_page_range() which says if (start >= end) return -EINVAL;

3) Integer overflow:
	access_ok((void __user *)(long)arg->vec, arg->vec_len * sizeof(struct page_region))
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This multiplication can overflow so access_ok() checks a smaller size than
intended.  It will absolutely return success when it shouldn't.  To determine
the impact then we have to look at do_pagemap_scan() but I don't know the code
well enough to say if it's harmless or what the impact is.

Integer overflows to access_ok() are always treated as a bug though even if it's
harmless.

regards,
dan carpenter



      reply	other threads:[~2024-09-12 10:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3a4e2a3e-b395-41e6-807d-0e6ad8722c7d@stanley.mountain>
     [not found] ` <b33db5d3-2407-4d25-a516-f0fd8d74a827@collabora.com>
2024-09-12  9:34   ` Muhammad Usama Anjum
2024-09-12 10:06     ` Dan Carpenter [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=69e01b95-fcf1-4168-8aa9-708623ec3956@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=Usama.Anjum@collabora.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.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