lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKwvOdmviwYfLs4YOY3C0Hi6nw2JKPCW5kAGM_qPTOcrAUVQ5w@mail.gmail.com>
Date:   Thu, 28 Jan 2021 10:31:24 -0800
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Candle Sun <candlesea@...il.com>
Cc:     Kees Cook <keescook@...omium.org>, Arnd Bergmann <arnd@...db.de>,
        Greg KH <gregkh@...uxfoundation.org>,
        Nathan Chancellor <natechancellor@...il.com>,
        candle.sun@...soc.com, David Laight <David.Laight@...lab.com>,
        LKML <linux-kernel@...r.kernel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH v3] lkdtm: fix memory copy size for WRITE_KERN

On Wed, Jan 27, 2021 at 10:58 PM Candle Sun <candlesea@...il.com> wrote:
>
> From: Candle Sun <candle.sun@...soc.com>
>
> Though do_overwritten() follows do_nothing() in source code, the final
> memory address order is determined by the compiler. We can't always
> assume address of do_overwritten() is bigger than do_nothing(). At least
> the Clang we are using places do_overwritten() before do_nothing() in the
> object. This causes the copy size in lkdtm_WRITE_KERN() is *really* big
> and WRITE_KERN test on ARM32 arch will fail.
>
> Get absolute value of the address subtraction for memcpy() size.

LGTM, thanks Candle!
Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>

>
> Signed-off-by: Candle Sun <candle.sun@...soc.com>
> ---
> Changes in v3:
> - Clean some typo.
> - Remove one comment line.
> Changes in v2:
> - Use abs() in place of address comparison.
> ---
>  drivers/misc/lkdtm/perms.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
> index 2dede2ef658f..c9227e08f97f 100644
> --- a/drivers/misc/lkdtm/perms.c
> +++ b/drivers/misc/lkdtm/perms.c
> @@ -31,13 +31,12 @@ static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
>   * This just returns to the caller. It is designed to be copied into
>   * non-executable memory regions.
>   */
> -static void do_nothing(void)
> +static noinline void do_nothing(void)
>  {
>         return;
>  }
>
> -/* Must immediately follow do_nothing for size calculuations to work out. */
> -static void do_overwritten(void)
> +static noinline void do_overwritten(void)
>  {
>         pr_info("do_overwritten wasn't overwritten!\n");
>         return;
> @@ -113,7 +112,7 @@ void lkdtm_WRITE_KERN(void)
>         size_t size;
>         volatile unsigned char *ptr;
>
> -       size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
> +       size = (size_t)abs((uintptr_t)do_overwritten - (uintptr_t)do_nothing);
>         ptr = (unsigned char *)do_overwritten;
>
>         pr_info("attempting bad %zu byte write at %px\n", size, ptr);
> --
> 2.17.0
>


-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ