Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1651617 > unrolled thread

Re: [stable backport PATCH] usercopy: Adjust tests to deal with SMAP/PAN

Started byKees Cook <keescook@chromium.org>
First post2017-05-27 03:30 +0200
Last post2017-05-27 03:40 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [stable backport PATCH] usercopy: Adjust tests to deal with SMAP/PAN Kees Cook <keescook@chromium.org> - 2017-05-27 03:30 +0200
    Re: [stable backport PATCH] usercopy: Adjust tests to deal with SMAP/PAN Arnd Bergmann <arnd@arndb.de> - 2017-05-27 03:40 +0200

#1651617 — Re: [stable backport PATCH] usercopy: Adjust tests to deal with SMAP/PAN

FromKees Cook <keescook@chromium.org>
Date2017-05-27 03:30 +0200
SubjectRe: [stable backport PATCH] usercopy: Adjust tests to deal with SMAP/PAN
Message-ID<tLyIh-4Vw-9@gated-at.bofh.it>
On Fri, May 26, 2017 at 1:40 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> From: Kees Cook <keescook@chromium.org>
>
> Commit f5f893c57e37ca730808cb2eee3820abd05e7507 upstream.
>
> Under SMAP/PAN/etc, we cannot write directly to userspace memory, so
> this rearranges the test bytes to get written through copy_to_user().
> Additionally drops the bad copy_from_user() test that would trigger a
> memcpy() against userspace on failure.
>
> [arnd: the test module was added in 3.14, and this backported patch
>        should apply cleanly on all version from 3.14 to 4.10.
>        The original patch was in 4.11 on top of a context change.
>        I saw the bug triggered with kselftest on a 4.4.y stable kernel]
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  lib/test_user_copy.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c
> index 0ecef3e4690e..b16891d01112 100644
> --- a/lib/test_user_copy.c
> +++ b/lib/test_user_copy.c
> @@ -58,7 +58,9 @@ static int __init test_user_copy_init(void)
>         usermem = (char __user *)user_addr;
>         bad_usermem = (char *)user_addr;
>
> -       /* Legitimate usage: none of these should fail. */
> +       /*
> +        * Legitimate usage: none of these copies should fail.
> +        */
>         ret |= test(copy_from_user(kmem, usermem, PAGE_SIZE),
>                     "legitimate copy_from_user failed");
>         ret |= test(copy_to_user(usermem, kmem, PAGE_SIZE),
> @@ -68,19 +70,34 @@ static int __init test_user_copy_init(void)
>         ret |= test(put_user(value, (unsigned long __user *)usermem),
>                     "legitimate put_user failed");
>
> -       /* Invalid usage: none of these should succeed. */
> +       /*
> +        * Invalid usage: none of these copies should succeed.
> +        */
> +
> +       /* Reject kernel-to-kernel copies through copy_from_user(). */
>         ret |= test(!copy_from_user(kmem, (char __user *)(kmem + PAGE_SIZE),
>                                     PAGE_SIZE),
>                     "illegal all-kernel copy_from_user passed");
> +
> +#if 0
> +       /*
> +        * When running with SMAP/PAN/etc, this will Oops the kernel
> +        * due to the zeroing of userspace memory on failure. This needs
> +        * to be tested in LKDTM instead, since this test module does not
> +        * expect to explode.
> +        */
>         ret |= test(!copy_from_user(bad_usermem, (char __user *)kmem,
>                                     PAGE_SIZE),
>                     "illegal reversed copy_from_user passed");
> +#endif
>         ret |= test(!copy_to_user((char __user *)kmem, kmem + PAGE_SIZE,
>                                   PAGE_SIZE),
>                     "illegal all-kernel copy_to_user passed");
>         ret |= test(!copy_to_user((char __user *)kmem, bad_usermem,
>                                   PAGE_SIZE),
>                     "illegal reversed copy_to_user passed");
> +
> +       value = 0x5a;

I don't think this "value" bit wanted, but it should be harmless.

-Kees

>         ret |= test(!get_user(value, (unsigned long __user *)kmem),
>                     "illegal get_user passed");
>         ret |= test(!put_user(value, (unsigned long __user *)kmem),
> --
> 2.9.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel



-- 
Kees Cook
Pixel Security

[toc] | [next] | [standalone]


#1651703

FromArnd Bergmann <arnd@arndb.de>
Date2017-05-27 03:40 +0200
Message-ID<tLyRY-4YN-25@gated-at.bofh.it>
In reply to#1651617
On Fri, May 26, 2017 at 10:53 PM, Kees Cook <keescook@chromium.org> wrote:
>> +
>> +       value = 0x5a;
>
> I don't think this "value" bit wanted, but it should be harmless.
>

Right, that should not be there, it came from a different patch.
I've sent a new version of the backport now. Thanks for taking a look.

       Arnd

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web