From: Dan Carpenter <dan.carpenter@linaro.org>
To: Andrei Vagin <avagin@google.com>
Cc: "Muhammad Usama Anjum" <usama.anjum@collabora.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@redhat.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Oscar Salvador" <osalvador@suse.de>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Ryan Roberts" <ryan.roberts@arm.com>,
"Peter Xu" <peterx@redhat.com>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Arnd Bergmann" <arnd@arndb.de>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] fs/proc/task_mmu: prevent integer overflow in pagemap_scan_get_args()
Date: Fri, 15 Nov 2024 22:29:52 +0300 [thread overview]
Message-ID: <1b18cec7-3d58-4cdc-b653-fb5790d04879@stanley.mountain> (raw)
In-Reply-To: <CAEWA0a5vMq4vGRj4FVQXUR2unN-xAmsFt5ymi4SL+H0yfNpdfw@mail.gmail.com>
On Fri, Nov 15, 2024 at 10:49:44AM -0800, Andrei Vagin wrote:
> On Thu, Nov 14, 2024 at 12:59 AM Dan Carpenter <dan.carpenter@linaro.org> wrote:
> >
> > The "arg->vec_len" variable is a u64 that comes from the user at the
> > start of the function. The "arg->vec_len * sizeof(struct page_region))"
> > multiplication can lead to integer wrapping. Use size_mul() to avoid
> > that.
> >
> > Also the size_add/mul() functions work on unsigned long so for 32bit
> > systems we need to ensure that "arg->vec_len" fits in an unsigned long.
> >
> > Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>
> Acked-by: Andrei Vagin <avagin@google.com>
>
> > ---
> > fs/proc/task_mmu.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > index f57ea9b308bb..38a5a3e9cba2 100644
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -2665,8 +2665,10 @@ static int pagemap_scan_get_args(struct pm_scan_arg *arg,
> > return -EFAULT;
> > if (!arg->vec && arg->vec_len)
> > return -EINVAL;
> > + if (UINT_MAX == SIZE_MAX && arg->vec_len > SIZE_MAX)
>
> nit: arg->vec_len > SIZE_MAX / sizeof(struct page_region)
I don't like open coding integer overflow checks now that we have size_add().
Historically, we've done a poor job writing them correctly.
Probably the right thing is to add the > SIZE_MAX check to size_add/mul().
#define size_add(a, b) ({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
unsigned long __res; \
if (__a >= SIZE_MAX || __b >= SIZE_MAX) \
__res = ULONG_MAX; \
else \
__res = __size_add(__a, __b); \
__res; \
})
But I think you'd trigger compiler warnings if a or b were a u32 so probably
we'd need to use a _Generic() or something.
regards,
dan carpenter
prev parent reply other threads:[~2024-11-15 19:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 8:59 Dan Carpenter
2024-11-15 18:49 ` Andrei Vagin
2024-11-15 19:29 ` 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=1b18cec7-3d58-4cdc-b653-fb5790d04879@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=avagin@google.com \
--cc=david@redhat.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=usama.anjum@collabora.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
all inboxes | Powered by JetHome®