linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Eric Biggers <ebiggers@google.com>
Cc: Linux-MM <linux-mm@kvack.org>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm: avoid undefined behavior in hardened usercopy check
Date: Fri, 19 Aug 2016 13:47:50 -0700	[thread overview]
Message-ID: <CAGXu5jKzGcHJj7oL_=ezPK46VfxbiuHdoRVbEfUNf_MSopoRMg@mail.gmail.com> (raw)
In-Reply-To: <1471634122-31789-1-git-send-email-ebiggers@google.com>

On Fri, Aug 19, 2016 at 12:15 PM, Eric Biggers <ebiggers@google.com> wrote:
> check_bogus_address() checked for pointer overflow using this expression,
> where 'ptr' has type 'const void *':
>
>         ptr + n < ptr
>
> Since pointer wraparound is undefined behavior, gcc at -O2 by default
> treats it like the following, which would not behave as intended:
>
>         (long)n < 0
>
> Fortunately, this doesn't currently happen for kernel code because kernel
> code is compiled with -fno-strict-overflow.  But the expression should be
> fixed anyway to use well-defined integer arithmetic, since it could be
> treated differently by different compilers in the future or could be
> reported by tools checking for undefined behavior.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Cool, thanks. I'll get this into my tree.

-Kees

> ---
>  mm/usercopy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/usercopy.c b/mm/usercopy.c
> index 8ebae91..82f81df 100644
> --- a/mm/usercopy.c
> +++ b/mm/usercopy.c
> @@ -124,7 +124,7 @@ static inline const char *check_kernel_text_object(const void *ptr,
>  static inline const char *check_bogus_address(const void *ptr, unsigned long n)
>  {
>         /* Reject if object wraps past end of memory. */
> -       if (ptr + n < ptr)
> +       if ((unsigned long)ptr + n < (unsigned long)ptr)
>                 return "<wrapped address>";
>
>         /* Reject if NULL or ZERO-allocation. */
> --
> 2.8.0.rc3.226.g39d4020
>



-- 
Kees Cook
Nexus Security

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2016-08-19 20:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 19:15 Eric Biggers
2016-08-19 20:47 ` Kees Cook [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='CAGXu5jKzGcHJj7oL_=ezPK46VfxbiuHdoRVbEfUNf_MSopoRMg@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=ebiggers@google.com \
    --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