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


Groups > linux.kernel > #1522392 > unrolled thread

[PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK()

Started byMichael Ellerman <mpe@ellerman.id.au>
First post2016-11-15 08:10 +0100
Last post2016-11-15 19:30 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK() Michael Ellerman <mpe@ellerman.id.au> - 2016-11-15 08:10 +0100
    Re: [PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK() Kees Cook <keescook@chromium.org> - 2016-11-15 18:30 +0100
      Re: [PATCH] lkdtm: Prevent the compiler from optimising  lkdtm_CORRUPT_STACK() Greg KH <gregkh@linuxfoundation.org> - 2016-11-15 19:30 +0100

#1522392 — [PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK()

FromMichael Ellerman <mpe@ellerman.id.au>
Date2016-11-15 08:10 +0100
Subject[PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK()
Message-ID<sDG2t-1Lo-1@gated-at.bofh.it>
At least on powerpc with GCC 6, the compiler is smart enough to optimise
lkdtm_CORRUPT_STACK() into an empty function that just returns.

If we print the buffer after we've written to it that prevents the
compiler from optimising away data and the memset().

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 drivers/misc/lkdtm_bugs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/lkdtm_bugs.c b/drivers/misc/lkdtm_bugs.c
index 182ae1894b32..30e62dd7e7ca 100644
--- a/drivers/misc/lkdtm_bugs.c
+++ b/drivers/misc/lkdtm_bugs.c
@@ -80,7 +80,8 @@ noinline void lkdtm_CORRUPT_STACK(void)
 	/* Use default char array length that triggers stack protection. */
 	char data[8];
 
-	memset((void *)data, 0, 64);
+	memset((void *)data, 'a', 64);
+	pr_info("Corrupted stack with '%16s'...\n", data);
 }
 
 void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void)
-- 
2.7.4

[toc] | [next] | [standalone]


#1522931

FromKees Cook <keescook@chromium.org>
Date2016-11-15 18:30 +0100
Message-ID<sDPIu-7SW-1@gated-at.bofh.it>
In reply to#1522392
On Mon, Nov 14, 2016 at 11:02 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> At least on powerpc with GCC 6, the compiler is smart enough to optimise
> lkdtm_CORRUPT_STACK() into an empty function that just returns.

Sneaky. Thanks!

> If we print the buffer after we've written to it that prevents the
> compiler from optimising away data and the memset().
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Acked-by: Kees Cook <keescook@chromium.org>

Greg, can you add this to the drivers/misc?

-Kees

> ---
>  drivers/misc/lkdtm_bugs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm_bugs.c b/drivers/misc/lkdtm_bugs.c
> index 182ae1894b32..30e62dd7e7ca 100644
> --- a/drivers/misc/lkdtm_bugs.c
> +++ b/drivers/misc/lkdtm_bugs.c
> @@ -80,7 +80,8 @@ noinline void lkdtm_CORRUPT_STACK(void)
>         /* Use default char array length that triggers stack protection. */
>         char data[8];
>
> -       memset((void *)data, 0, 64);
> +       memset((void *)data, 'a', 64);
> +       pr_info("Corrupted stack with '%16s'...\n", data);
>  }
>
>  void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void)
> --
> 2.7.4
>



-- 
Kees Cook
Nexus Security

[toc] | [prev] | [next] | [standalone]


#1522994 — Re: [PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK()

FromGreg KH <gregkh@linuxfoundation.org>
Date2016-11-15 19:30 +0100
SubjectRe: [PATCH] lkdtm: Prevent the compiler from optimising lkdtm_CORRUPT_STACK()
Message-ID<sDQEy-5I-27@gated-at.bofh.it>
In reply to#1522931
On Tue, Nov 15, 2016 at 09:27:47AM -0800, Kees Cook wrote:
> On Mon, Nov 14, 2016 at 11:02 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > At least on powerpc with GCC 6, the compiler is smart enough to optimise
> > lkdtm_CORRUPT_STACK() into an empty function that just returns.
> 
> Sneaky. Thanks!
> 
> > If we print the buffer after we've written to it that prevents the
> > compiler from optimising away data and the memset().
> >
> > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> 
> Acked-by: Kees Cook <keescook@chromium.org>
> 
> Greg, can you add this to the drivers/misc?

Now added, thanks.

greg k-h

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web