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] [thread-next>] [day] [month] [year] [list]
Message-ID: <97d1f36a3b534b7fbd3790a0277ccaf5@AcuMS.aculab.com>
Date:   Mon, 25 Jan 2021 10:37:36 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Candle Sun' <candlesea@...il.com>,
        "keescook@...omium.org" <keescook@...omium.org>
CC:     "arnd@...db.de" <arnd@...db.de>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        "natechancellor@...il.com" <natechancellor@...il.com>,
        "ndesaulniers@...gle.com" <ndesaulniers@...gle.com>,
        "candle.sun@...soc.com" <candle.sun@...soc.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "clang-built-linux@...glegroups.com" 
        <clang-built-linux@...glegroups.com>
Subject: RE: [PATCH] lkdtm: fix memory copy size for WRITE_KERN

From: Candle Sun
> Sent: 25 January 2021 08:56
> 
> From: Candle Sun <candle.sun@...soc.com>
> 
> Though do_overwritten() follows do_nothing() in source code, the final
> memory address order is determined by 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.
> 
> Compare the address order before doing the subtraction.

It isn't clear that helps.
Compile with -ffunction-sections and/or do LTO an there
is no reason at all why the functions should be together.

Even without that lkdtm_WRITE_KERN() could easily be between them.

You need to get the size of the 'empty function' from the
symbol table.

	David

> 
> Signed-off-by: Candle Sun <candle.sun@...soc.com>
> ---
>  drivers/misc/lkdtm/perms.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
> index 2dede2ef658f..fbfbdf89d668 100644
> --- a/drivers/misc/lkdtm/perms.c
> +++ b/drivers/misc/lkdtm/perms.c
> @@ -31,13 +31,13 @@ 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;
> @@ -110,15 +110,14 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
> 
>  void lkdtm_WRITE_KERN(void)
>  {
> -	size_t size;
> -	volatile unsigned char *ptr;
> +	unsigned long value_dow = (unsigned long)do_overwritten;
> +	unsigned long value_do =  (unsigned long)do_nothing;
> +	size_t size = (size_t)(value_dow > value_do ?
> +			value_dow - value_do : value_do - value_dow);
> 
> -	size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
> -	ptr = (unsigned char *)do_overwritten;
> -
> -	pr_info("attempting bad %zu byte write at %px\n", size, ptr);
> -	memcpy((void *)ptr, (unsigned char *)do_nothing, size);
> -	flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
> +	pr_info("attempting bad %zu byte write at %px\n", size, do_overwritten);
> +	memcpy((void *)value_dow, (void *)value_do, size);
> +	flush_icache_range(value_dow, value_dow + (unsigned long)size);
>  	pr_err("FAIL: survived bad write\n");
> 
>  	do_overwritten();
> --
> 2.17.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ