linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ralph Campbell <rcampbell@nvidia.com>
To: "Dan Carpenter" <dan.carpenter@oracle.com>,
	"Jérôme Glisse" <jglisse@redhat.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] lib/test_hmm.c: fix harmless shift wrapping bug
Date: Tue, 16 Mar 2021 09:43:30 -0700	[thread overview]
Message-ID: <6f1a3909-c42e-be33-6cc2-0ecc32f59b1c@nvidia.com> (raw)
In-Reply-To: <YFCZ1NNfMoixOjWP@mwanda>


On 3/16/21 4:43 AM, Dan Carpenter wrote:
> The "cmd.npages" variable is a u64 that comes from the user.  I noticed
> during review that it could have a shift wrapping bug when it is used
> in the integer overflow test on the next line.
> 
> It turns out this is harmless.  The users all do:
> 
> 	unsigned long size = cmd->npages << PAGE_SHIFT;
> 
> and after that "size" is used consistently and "cmd->npages" is never
> used again.  So even when there is an integer overflow, everything works
> fine.
> 
> Even though this is harmless, I believe syzbot will complain and fixing
> it makes the code easier to read.
> 
> Fixes: b2ef9f5a5cb3 ("mm/hmm/test: add selftest driver for HMM")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   lib/test_hmm.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index 80a78877bd93..541466034a6b 100644
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -930,6 +930,8 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp,
>   
>   	if (cmd.addr & ~PAGE_MASK)
>   		return -EINVAL;
> +	if (cmd.npages > ULONG_MAX >> PAGE_SHIFT)
> +		return -EINVAL;
>   	if (cmd.addr >= (cmd.addr + (cmd.npages << PAGE_SHIFT)))
>   		return -EINVAL;

Looks good to me too. Thanks for sending this.
Reviewed-by: Ralph Campbell <rcampbell@nvidia.com>


      reply	other threads:[~2021-03-16 16:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 11:43 Dan Carpenter
2021-03-16 16:43 ` Ralph Campbell [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=6f1a3909-c42e-be33-6cc2-0ecc32f59b1c@nvidia.com \
    --to=rcampbell@nvidia.com \
    --cc=dan.carpenter@oracle.com \
    --cc=jglisse@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@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