All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@google.com>
To: Rik van Riel <riel@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Daniel Micay <danielmicay@gmail.com>, Ted Ts'o <tytso@mit.edu>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@kernel.org>, "x86@kernel.org" <x86@kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	linux-sh <linux-sh@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>
Subject: Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 16:15:34 +0000	[thread overview]
Message-ID: <CAGXu5jKVTga05PqHKaZ_gEqjSYc4sfaD7Cy9eZeDaZSowJ_v3g@mail.gmail.com> (raw)
In-Reply-To: <20170524155751.424-2-riel@redhat.com>

On Wed, May 24, 2017 at 8:57 AM,  <riel@redhat.com> wrote:
> From: Rik van Riel <riel@redhat.com>
>
> Introduce the get_random_canary function, which provides a random
> unsigned long canary value with the first byte zeroed out on 64
> bit architectures, in order to mitigate non-terminated C string
> overflows.
>
> The null byte both prevents C string functions from reading the
> canary, and from writing it if the canary value were guessed or
> obtained through some other means.
>
> Reducing the entropy by 8 bits is acceptable on 64-bit systems,
> which will still have 56 bits of entropy left, but not on 32
> bit systems, so the "ascii armor" canary is only implemented on
> 64-bit systems.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and Daniel Micay's linux-hardened tree.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>

Since the other recent canary fix went via -mm, perhaps these should
go that way too? If not, I can take them via my KSPP tree.

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

-Kees

> ---
>  include/linux/random.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..1fa0dc880bd7 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,27 @@ static inline unsigned long get_random_long(void)
>  #endif
>  }
>
> +/*
> + * On 64-bit architectures, protect against non-terminated C string overflows
> + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
> + */
> +#ifdef CONFIG_64BIT
> +# ifdef __LITTLE_ENDIAN
> +#  define CANARY_MASK 0xffffffffffffff00UL
> +# else /* big endian, 64 bits: */
> +#  define CANARY_MASK 0x00ffffffffffffffUL
> +# endif
> +#else /* 32 bits: */
> +# define CANARY_MASK 0xffffffffUL
> +#endif
> +
> +static inline unsigned long get_random_canary(void)
> +{
> +       unsigned long val = get_random_long();
> +
> +       return val & CANARY_MASK;
> +}
> +
>  unsigned long randomize_page(unsigned long start, unsigned long range);
>
>  u32 prandom_u32(void);
> --
> 2.9.3
>



-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@google.com>
To: Rik van Riel <riel@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Daniel Micay <danielmicay@gmail.com>, "Ted Ts'o" <tytso@mit.edu>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@kernel.org>, "x86@kernel.org" <x86@kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	linux-sh <linux-sh@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	"kernel-hardening@lists.openwall.com" 
	<kernel-hardening@lists.openwall.com>
Subject: Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 09:15:34 -0700	[thread overview]
Message-ID: <CAGXu5jKVTga05PqHKaZ_gEqjSYc4sfaD7Cy9eZeDaZSowJ_v3g@mail.gmail.com> (raw)
In-Reply-To: <20170524155751.424-2-riel@redhat.com>

On Wed, May 24, 2017 at 8:57 AM,  <riel@redhat.com> wrote:
> From: Rik van Riel <riel@redhat.com>
>
> Introduce the get_random_canary function, which provides a random
> unsigned long canary value with the first byte zeroed out on 64
> bit architectures, in order to mitigate non-terminated C string
> overflows.
>
> The null byte both prevents C string functions from reading the
> canary, and from writing it if the canary value were guessed or
> obtained through some other means.
>
> Reducing the entropy by 8 bits is acceptable on 64-bit systems,
> which will still have 56 bits of entropy left, but not on 32
> bit systems, so the "ascii armor" canary is only implemented on
> 64-bit systems.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and Daniel Micay's linux-hardened tree.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>

Since the other recent canary fix went via -mm, perhaps these should
go that way too? If not, I can take them via my KSPP tree.

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

-Kees

> ---
>  include/linux/random.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..1fa0dc880bd7 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,27 @@ static inline unsigned long get_random_long(void)
>  #endif
>  }
>
> +/*
> + * On 64-bit architectures, protect against non-terminated C string overflows
> + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
> + */
> +#ifdef CONFIG_64BIT
> +# ifdef __LITTLE_ENDIAN
> +#  define CANARY_MASK 0xffffffffffffff00UL
> +# else /* big endian, 64 bits: */
> +#  define CANARY_MASK 0x00ffffffffffffffUL
> +# endif
> +#else /* 32 bits: */
> +# define CANARY_MASK 0xffffffffUL
> +#endif
> +
> +static inline unsigned long get_random_canary(void)
> +{
> +       unsigned long val = get_random_long();
> +
> +       return val & CANARY_MASK;
> +}
> +
>  unsigned long randomize_page(unsigned long start, unsigned long range);
>
>  u32 prandom_u32(void);
> --
> 2.9.3
>



-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: keescook@google.com (Kees Cook)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/5] random, stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 09:15:34 -0700	[thread overview]
Message-ID: <CAGXu5jKVTga05PqHKaZ_gEqjSYc4sfaD7Cy9eZeDaZSowJ_v3g@mail.gmail.com> (raw)
In-Reply-To: <20170524155751.424-2-riel@redhat.com>

On Wed, May 24, 2017 at 8:57 AM,  <riel@redhat.com> wrote:
> From: Rik van Riel <riel@redhat.com>
>
> Introduce the get_random_canary function, which provides a random
> unsigned long canary value with the first byte zeroed out on 64
> bit architectures, in order to mitigate non-terminated C string
> overflows.
>
> The null byte both prevents C string functions from reading the
> canary, and from writing it if the canary value were guessed or
> obtained through some other means.
>
> Reducing the entropy by 8 bits is acceptable on 64-bit systems,
> which will still have 56 bits of entropy left, but not on 32
> bit systems, so the "ascii armor" canary is only implemented on
> 64-bit systems.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and Daniel Micay's linux-hardened tree.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>

Since the other recent canary fix went via -mm, perhaps these should
go that way too? If not, I can take them via my KSPP tree.

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

-Kees

> ---
>  include/linux/random.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..1fa0dc880bd7 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,27 @@ static inline unsigned long get_random_long(void)
>  #endif
>  }
>
> +/*
> + * On 64-bit architectures, protect against non-terminated C string overflows
> + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
> + */
> +#ifdef CONFIG_64BIT
> +# ifdef __LITTLE_ENDIAN
> +#  define CANARY_MASK 0xffffffffffffff00UL
> +# else /* big endian, 64 bits: */
> +#  define CANARY_MASK 0x00ffffffffffffffUL
> +# endif
> +#else /* 32 bits: */
> +# define CANARY_MASK 0xffffffffUL
> +#endif
> +
> +static inline unsigned long get_random_canary(void)
> +{
> +       unsigned long val = get_random_long();
> +
> +       return val & CANARY_MASK;
> +}
> +
>  unsigned long randomize_page(unsigned long start, unsigned long range);
>
>  u32 prandom_u32(void);
> --
> 2.9.3
>



-- 
Kees Cook
Pixel Security

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@google.com>
To: Rik van Riel <riel@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Daniel Micay <danielmicay@gmail.com>, Ted Ts'o <tytso@mit.edu>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@kernel.org>, "x86@kernel.org" <x86@kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	linux-sh <linux-sh@vger.kernel.org>,
	Yoshinori Sato <ysato@users.sourceforge.jp>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>
Subject: [kernel-hardening] Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 09:15:34 -0700	[thread overview]
Message-ID: <CAGXu5jKVTga05PqHKaZ_gEqjSYc4sfaD7Cy9eZeDaZSowJ_v3g@mail.gmail.com> (raw)
In-Reply-To: <20170524155751.424-2-riel@redhat.com>

On Wed, May 24, 2017 at 8:57 AM,  <riel@redhat.com> wrote:
> From: Rik van Riel <riel@redhat.com>
>
> Introduce the get_random_canary function, which provides a random
> unsigned long canary value with the first byte zeroed out on 64
> bit architectures, in order to mitigate non-terminated C string
> overflows.
>
> The null byte both prevents C string functions from reading the
> canary, and from writing it if the canary value were guessed or
> obtained through some other means.
>
> Reducing the entropy by 8 bits is acceptable on 64-bit systems,
> which will still have 56 bits of entropy left, but not on 32
> bit systems, so the "ascii armor" canary is only implemented on
> 64-bit systems.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and Daniel Micay's linux-hardened tree.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>

Since the other recent canary fix went via -mm, perhaps these should
go that way too? If not, I can take them via my KSPP tree.

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

-Kees

> ---
>  include/linux/random.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..1fa0dc880bd7 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,27 @@ static inline unsigned long get_random_long(void)
>  #endif
>  }
>
> +/*
> + * On 64-bit architectures, protect against non-terminated C string overflows
> + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
> + */
> +#ifdef CONFIG_64BIT
> +# ifdef __LITTLE_ENDIAN
> +#  define CANARY_MASK 0xffffffffffffff00UL
> +# else /* big endian, 64 bits: */
> +#  define CANARY_MASK 0x00ffffffffffffffUL
> +# endif
> +#else /* 32 bits: */
> +# define CANARY_MASK 0xffffffffUL
> +#endif
> +
> +static inline unsigned long get_random_canary(void)
> +{
> +       unsigned long val = get_random_long();
> +
> +       return val & CANARY_MASK;
> +}
> +
>  unsigned long randomize_page(unsigned long start, unsigned long range);
>
>  u32 prandom_u32(void);
> --
> 2.9.3
>



-- 
Kees Cook
Pixel Security

  reply	other threads:[~2017-05-24 16:15 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 15:57 [PATCH v2 0/5] stackprotector: ascii armor the stack canary riel
2017-05-24 15:57 ` [kernel-hardening] " riel
2017-05-24 15:57 ` riel at redhat.com
2017-05-24 15:57 ` riel
2017-05-24 15:57 ` [PATCH 1/5] random,stackprotect: introduce get_random_canary function riel
2017-05-24 15:57   ` [kernel-hardening] " riel
2017-05-24 15:57   ` [PATCH 1/5] random, stackprotect: " riel at redhat.com
2017-05-24 15:57   ` [PATCH 1/5] random,stackprotect: " riel
2017-05-24 16:15   ` Kees Cook [this message]
2017-05-24 16:15     ` [kernel-hardening] " Kees Cook
2017-05-24 16:15     ` [PATCH 1/5] random, stackprotect: " Kees Cook
2017-05-24 16:15     ` [PATCH 1/5] random,stackprotect: " Kees Cook
2017-05-24 15:57 ` [PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary riel
2017-05-24 15:57   ` [kernel-hardening] " riel
2017-05-24 15:57   ` [PATCH 2/5] fork, random: " riel at redhat.com
2017-05-24 15:57   ` [PATCH 2/5] fork,random: " riel
2017-05-24 16:16   ` Kees Cook
2017-05-24 16:16     ` [kernel-hardening] " Kees Cook
2017-05-24 16:16     ` [PATCH 2/5] fork, random: " Kees Cook
2017-05-24 16:16     ` [PATCH 2/5] fork,random: " Kees Cook
2017-05-24 15:57 ` [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary riel
2017-05-24 15:57   ` [kernel-hardening] " riel
2017-05-24 15:57   ` riel at redhat.com
2017-05-24 15:57   ` riel
2017-05-24 16:16   ` Kees Cook
2017-05-24 16:16     ` [kernel-hardening] " Kees Cook
2017-05-24 16:16     ` Kees Cook
2017-05-24 16:16     ` Kees Cook
2017-05-24 15:57 ` [PATCH 4/5] arm64: ascii armor the arm64 " riel
2017-05-24 15:57   ` [kernel-hardening] " riel
2017-05-24 15:57   ` riel at redhat.com
2017-05-24 15:57   ` riel
2017-05-24 16:16   ` Kees Cook
2017-05-24 16:16     ` [kernel-hardening] " Kees Cook
2017-05-24 16:16     ` Kees Cook
2017-05-24 16:16     ` Kees Cook
2017-05-24 15:57 ` [PATCH 5/5] sh64: ascii armor the sh64 " riel
2017-05-24 15:57   ` [kernel-hardening] " riel
2017-05-24 15:57   ` riel at redhat.com
2017-05-24 15:57   ` riel
2017-05-24 16:34 ` Rik van Riel
2017-05-24 16:34   ` [kernel-hardening] " Rik van Riel
2017-05-24 16:34   ` Rik van Riel
2017-05-24 16:34   ` Rik van Riel
2017-05-24 16:35   ` Kees Cook
2017-05-24 16:35     ` [kernel-hardening] " Kees Cook
2017-05-24 16:35     ` Kees Cook
2017-05-24 16:35     ` Kees Cook
2017-09-19 17:16 ` [kernel-hardening] [PATCH v2 0/5] stackprotector: ascii armor the " Solar Designer
2017-09-19 17:16   ` Solar Designer
2017-09-19 17:16   ` Solar Designer
2017-09-19 20:22   ` Kees Cook
2017-09-19 20:22     ` Kees Cook
2017-09-19 20:22     ` Kees Cook
2017-09-19 20:22     ` Kees Cook
2017-09-19 21:10   ` Daniel Micay
2017-09-19 21:10     ` Daniel Micay
2017-09-19 21:10     ` Daniel Micay
2017-09-20 11:18   ` Yann Droneaud
2017-09-20 11:18     ` Yann Droneaud
2017-09-20 11:18     ` Yann Droneaud
2017-09-20 15:03     ` Solar Designer
2017-09-20 15:03       ` Solar Designer
2017-09-20 15:03       ` Solar Designer
  -- strict thread matches above, loose matches on Subject: below --
2017-05-19 21:26 riel
2017-05-19 21:26 ` [PATCH 1/5] random,stackprotect: introduce get_random_canary function riel
2017-05-19 21:26   ` [PATCH 1/5] random, stackprotect: " riel at redhat.com
2017-05-19 21:26   ` [PATCH 1/5] random,stackprotect: " riel
2017-05-24  8:30   ` Ingo Molnar
2017-05-24  8:30     ` Ingo Molnar
2017-05-24  8:30     ` Ingo Molnar

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=CAGXu5jKVTga05PqHKaZ_gEqjSYc4sfaD7Cy9eZeDaZSowJ_v3g@mail.gmail.com \
    --to=keescook@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=danielmicay@gmail.com \
    --cc=hpa@zytor.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=riel@redhat.com \
    --cc=tytso@mit.edu \
    --cc=x86@kernel.org \
    --cc=ysato@users.sourceforge.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.