From: Ingo Molnar <mingo@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 08:30:43 +0000 [thread overview]
Message-ID: <20170524083043.hpbpuracjqj2bbv2@gmail.com> (raw)
In-Reply-To: <20170519212636.30440-2-riel@redhat.com>
* riel@redhat.com <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.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and the current PaX/grsecurity code base.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>
> ---
> include/linux/random.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..765a992c6774 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,26 @@ static inline unsigned long get_random_long(void)
> #endif
> }
>
> +/*
> + * On 64 bit architectures, protect against non-terminated C string overflows
s/64 bit/64-bit
> + * 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;
> +}
Please separate function definitions from macros by a separate empty line.
Also, a bit of structure and organization would make the macro easier to read:
#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 0x00000000ffffffffUL
#endif
Thanks,
Ingo
WARNING: multiple messages have this Message-ID (diff)
From: mingo@kernel.org (Ingo Molnar)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 10:30:43 +0200 [thread overview]
Message-ID: <20170524083043.hpbpuracjqj2bbv2@gmail.com> (raw)
In-Reply-To: <20170519212636.30440-2-riel@redhat.com>
* riel at redhat.com <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.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and the current PaX/grsecurity code base.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>
> ---
> include/linux/random.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..765a992c6774 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,26 @@ static inline unsigned long get_random_long(void)
> #endif
> }
>
> +/*
> + * On 64 bit architectures, protect against non-terminated C string overflows
s/64 bit/64-bit
> + * 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;
> +}
Please separate function definitions from macros by a separate empty line.
Also, a bit of structure and organization would make the macro easier to read:
#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 0x00000000ffffffffUL
#endif
Thanks,
Ingo
WARNING: multiple messages have this Message-ID (diff)
From: Ingo Molnar <mingo@kernel.org>
To: riel@redhat.com
Cc: linux-kernel@vger.kernel.org, danielmicay@gmail.com,
tytso@mit.edu, keescook@chromium.org, hpa@zytor.com,
luto@amacapital.net, x86@kernel.org,
linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com,
linux-sh@vger.kernel.org, ysato@users.sourceforge.jp
Subject: Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function
Date: Wed, 24 May 2017 10:30:43 +0200 [thread overview]
Message-ID: <20170524083043.hpbpuracjqj2bbv2@gmail.com> (raw)
In-Reply-To: <20170519212636.30440-2-riel@redhat.com>
* riel@redhat.com <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.
>
> Inspired by the "ascii armor" code in the old execshield patches,
> and the current PaX/grsecurity code base.
>
> Signed-off-by: Rik van Riel <riel@redhat.com>
> ---
> include/linux/random.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/include/linux/random.h b/include/linux/random.h
> index ed5c3838780d..765a992c6774 100644
> --- a/include/linux/random.h
> +++ b/include/linux/random.h
> @@ -57,6 +57,26 @@ static inline unsigned long get_random_long(void)
> #endif
> }
>
> +/*
> + * On 64 bit architectures, protect against non-terminated C string overflows
s/64 bit/64-bit
> + * 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;
> +}
Please separate function definitions from macros by a separate empty line.
Also, a bit of structure and organization would make the macro easier to read:
#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 0x00000000ffffffffUL
#endif
Thanks,
Ingo
next prev parent reply other threads:[~2017-05-24 8:30 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 21:26 stackprotector: ascii armor the stack canary riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` riel at redhat.com
2017-05-19 21:26 ` [PATCH 1/5] random,stackprotect: introduce get_random_canary function riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` [PATCH 1/5] random, stackprotect: " riel at redhat.com
2017-05-24 8:30 ` Ingo Molnar [this message]
2017-05-24 8:30 ` [PATCH 1/5] random,stackprotect: " Ingo Molnar
2017-05-24 8:30 ` Ingo Molnar
2017-05-19 21:26 ` [PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` [PATCH 2/5] fork, random: " riel at redhat.com
2017-05-19 21:26 ` [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` riel at redhat.com
2017-05-19 21:26 ` [PATCH 4/5] arm64: ascii armor the arm64 " riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` riel at redhat.com
2017-05-19 21:26 ` [PATCH 5/5] sh64: ascii armor the sh64 " riel
2017-05-19 21:26 ` riel
2017-05-19 21:26 ` riel at redhat.com
2017-05-19 21:32 ` stackprotector: ascii armor the " Kees Cook
2017-05-19 21:32 ` Kees Cook
2017-05-19 21:32 ` Kees Cook
2017-05-24 11:57 ` Geert Uytterhoeven
2017-05-24 11:57 ` Geert Uytterhoeven
2017-05-24 11:57 ` Geert Uytterhoeven
2017-05-19 23:57 ` Daniel Micay
2017-05-19 23:57 ` Daniel Micay
2017-05-19 23:57 ` Daniel Micay
-- strict thread matches above, loose matches on Subject: below --
2017-05-24 15:57 [kernel-hardening] [PATCH v2 0/5] " riel
2017-05-24 15:57 ` [PATCH 1/5] random,stackprotect: introduce get_random_canary function riel
2017-05-24 15:57 ` riel
2017-05-24 15:57 ` [PATCH 1/5] random, stackprotect: " riel at redhat.com
2017-05-24 16:15 ` [PATCH 1/5] random,stackprotect: " Kees Cook
2017-05-24 16:15 ` Kees Cook
2017-05-24 16:15 ` [PATCH 1/5] random, stackprotect: " Kees Cook
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=20170524083043.hpbpuracjqj2bbv2@gmail.com \
--to=mingo@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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.