public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Cc: linux-fsdevel@vger.kernel.org, David Disseldorp <ddiss@suse.de>,
	Thadeu Lima de Souza Cascardo <cascardo@canonical.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Michel Lespinasse <walken@google.com>,
	Helge Deller <deller@gmx.de>, Oleg Nesterov <oleg@redhat.com>,
	Lorenzo Stoakes <lstoakes@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] proc: Avoid mixing integer types in mem_rw()
Date: Wed, 12 May 2021 16:19:26 +0300	[thread overview]
Message-ID: <YJvV3jsotDj5COKe@localhost.localdomain> (raw)
In-Reply-To: <20210512125215.3348316-1-marcelo.cerri@canonical.com>

On Wed, May 12, 2021 at 09:52:12AM -0300, Marcelo Henrique Cerri wrote:
> Use size_t when capping the count argument received by mem_rw(). Since
> count is size_t, using min_t(int, ...) can lead to a negative value
> that will later be passed to access_remote_vm(), which can cause
> unexpected behavior.
> 
> Since we are capping the value to at maximum PAGE_SIZE, the conversion
> from size_t to int when passing it to access_remote_vm() as "len"
> shouldn't be a problem.

> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -854,7 +854,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
>  	flags = FOLL_FORCE | (write ? FOLL_WRITE : 0);
>  
>  	while (count > 0) {
> -		int this_len = min_t(int, count, PAGE_SIZE);
> +		size_t this_len = min_t(size_t, count, PAGE_SIZE);

As much as I don't like signed integers, VFS caps read/write lengths
at INT_MAX & PAGE_MASK, so casting doesn't change values.

  reply	other threads:[~2021-05-12 13:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 12:52 [PATCH] proc: Avoid mixing integer types in mem_rw() Marcelo Henrique Cerri
2021-05-12 13:19 ` Alexey Dobriyan [this message]
2021-05-12 13:40   ` Marcelo Henrique Cerri

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=YJvV3jsotDj5COKe@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cascardo@canonical.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=ddiss@suse.de \
    --cc=deller@gmx.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lstoakes@gmail.com \
    --cc=marcelo.cerri@canonical.com \
    --cc=oleg@redhat.com \
    --cc=walken@google.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