Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1649725 > unrolled thread
| Started by | riel@redhat.com |
|---|---|
| First post | 2017-05-24 18:00 +0200 |
| Last post | 2017-05-24 18:50 +0200 |
| Articles | 12 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v2 0/5] stackprotector: ascii armor the stack canary riel@redhat.com - 2017-05-24 18:00 +0200
[PATCH 1/5] random,stackprotect: introduce get_random_canary function riel@redhat.com - 2017-05-24 18:00 +0200
Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function Kees Cook <keescook@google.com> - 2017-05-24 18:20 +0200
[PATCH 4/5] arm64: ascii armor the arm64 boot init stack canary riel@redhat.com - 2017-05-24 18:00 +0200
Re: [PATCH 4/5] arm64: ascii armor the arm64 boot init stack canary Kees Cook <keescook@google.com> - 2017-05-24 18:20 +0200
[PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary riel@redhat.com - 2017-05-24 18:00 +0200
Re: [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary Kees Cook <keescook@google.com> - 2017-05-24 18:20 +0200
[PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary riel@redhat.com - 2017-05-24 18:00 +0200
Re: [PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary Kees Cook <keescook@google.com> - 2017-05-24 18:20 +0200
[PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary Rik van Riel <riel@redhat.com> - 2017-05-24 18:40 +0200
Re: [PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary Kees Cook <keescook@google.com> - 2017-05-24 18:40 +0200
[PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary riel@redhat.com - 2017-05-24 18:50 +0200
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:00 +0200 |
| Subject | [PATCH v2 0/5] stackprotector: ascii armor the stack canary |
| Message-ID | <tKGRz-4dh-7@gated-at.bofh.it> |
Zero out the first byte of the stack canary value on 64 bit systems,
in order to mitigate unterminated 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 execshield and Daniel Micay's
linux-hardened tree.
Also see https://github.com/thestinger/linux-hardened/
v2:
- improve changelogs
- address Ingo's coding style comments
[toc] | [next] | [standalone]
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:00 +0200 |
| Subject | [PATCH 1/5] random,stackprotect: introduce get_random_canary function |
| Message-ID | <tKGRz-4dh-13@gated-at.bofh.it> |
| In reply to | #1649725 |
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>
---
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
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2017-05-24 18:20 +0200 |
| Subject | Re: [PATCH 1/5] random,stackprotect: introduce get_random_canary function |
| Message-ID | <tKHaV-4zP-11@gated-at.bofh.it> |
| In reply to | #1649728 |
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
[toc] | [prev] | [next] | [standalone]
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:00 +0200 |
| Subject | [PATCH 4/5] arm64: ascii armor the arm64 boot init stack canary |
| Message-ID | <tKGRA-4dh-21@gated-at.bofh.it> |
| In reply to | #1649725 |
From: Rik van Riel <riel@redhat.com> Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel <riel@redhat.com> --- arch/arm64/include/asm/stackprotector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/include/asm/stackprotector.h b/arch/arm64/include/asm/stackprotector.h index fe5e287dc56b..b86a0865ddf1 100644 --- a/arch/arm64/include/asm/stackprotector.h +++ b/arch/arm64/include/asm/stackprotector.h @@ -30,6 +30,7 @@ static __always_inline void boot_init_stack_canary(void) /* Try to get a semi random initial value. */ get_random_bytes(&canary, sizeof(canary)); canary ^= LINUX_VERSION_CODE; + canary &= CANARY_MASK; current->stack_canary = canary; __stack_chk_guard = current->stack_canary; -- 2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2017-05-24 18:20 +0200 |
| Subject | Re: [PATCH 4/5] arm64: ascii armor the arm64 boot init stack canary |
| Message-ID | <tKHaV-4zP-1@gated-at.bofh.it> |
| In reply to | #1649730 |
On Wed, May 24, 2017 at 8:57 AM, <riel@redhat.com> wrote: > From: Rik van Riel <riel@redhat.com> > > Use the ascii-armor canary to prevent unterminated C string overflows > from being able to successfully overwrite the canary, even if they > somehow obtain the canary value. > > Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. > > Signed-off-by: Rik van Riel <riel@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > arch/arm64/include/asm/stackprotector.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm64/include/asm/stackprotector.h b/arch/arm64/include/asm/stackprotector.h > index fe5e287dc56b..b86a0865ddf1 100644 > --- a/arch/arm64/include/asm/stackprotector.h > +++ b/arch/arm64/include/asm/stackprotector.h > @@ -30,6 +30,7 @@ static __always_inline void boot_init_stack_canary(void) > /* Try to get a semi random initial value. */ > get_random_bytes(&canary, sizeof(canary)); > canary ^= LINUX_VERSION_CODE; > + canary &= CANARY_MASK; > > current->stack_canary = canary; > __stack_chk_guard = current->stack_canary; > -- > 2.9.3 > -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:00 +0200 |
| Subject | [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary |
| Message-ID | <tKGRA-4dh-23@gated-at.bofh.it> |
| In reply to | #1649725 |
From: Rik van Riel <riel@redhat.com> Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel <riel@redhat.com> --- arch/x86/include/asm/stackprotector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h index dcbd9bcce714..8abedf1d650e 100644 --- a/arch/x86/include/asm/stackprotector.h +++ b/arch/x86/include/asm/stackprotector.h @@ -74,6 +74,7 @@ static __always_inline void boot_init_stack_canary(void) get_random_bytes(&canary, sizeof(canary)); tsc = rdtsc(); canary += tsc + (tsc << 32UL); + canary &= CANARY_MASK; current->stack_canary = canary; #ifdef CONFIG_X86_64 -- 2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2017-05-24 18:20 +0200 |
| Subject | Re: [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary |
| Message-ID | <tKHaV-4zP-7@gated-at.bofh.it> |
| In reply to | #1649731 |
On Wed, May 24, 2017 at 8:57 AM, <riel@redhat.com> wrote: > From: Rik van Riel <riel@redhat.com> > > Use the ascii-armor canary to prevent unterminated C string overflows > from being able to successfully overwrite the canary, even if they > somehow obtain the canary value. > > Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. > > Signed-off-by: Rik van Riel <riel@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > arch/x86/include/asm/stackprotector.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h > index dcbd9bcce714..8abedf1d650e 100644 > --- a/arch/x86/include/asm/stackprotector.h > +++ b/arch/x86/include/asm/stackprotector.h > @@ -74,6 +74,7 @@ static __always_inline void boot_init_stack_canary(void) > get_random_bytes(&canary, sizeof(canary)); > tsc = rdtsc(); > canary += tsc + (tsc << 32UL); > + canary &= CANARY_MASK; > > current->stack_canary = canary; > #ifdef CONFIG_X86_64 > -- > 2.9.3 > -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:00 +0200 |
| Subject | [PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary |
| Message-ID | <tKGRA-4dh-25@gated-at.bofh.it> |
| In reply to | #1649725 |
From: Rik van Riel <riel@redhat.com> Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel <riel@redhat.com> --- kernel/fork.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index aa1076c5e4a9..b3591e9250a8 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -560,7 +560,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) set_task_stack_end_magic(tsk); #ifdef CONFIG_CC_STACKPROTECTOR - tsk->stack_canary = get_random_long(); + tsk->stack_canary = get_random_canary(); #endif /* -- 2.9.3
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2017-05-24 18:20 +0200 |
| Subject | Re: [PATCH 2/5] fork,random: use get_random_canary to set tsk->stack_canary |
| Message-ID | <tKHaV-4zP-5@gated-at.bofh.it> |
| In reply to | #1649732 |
On Wed, May 24, 2017 at 8:57 AM, <riel@redhat.com> wrote: > From: Rik van Riel <riel@redhat.com> > > Use the ascii-armor canary to prevent unterminated C string overflows > from being able to successfully overwrite the canary, even if they > somehow obtain the canary value. > > Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. > > Signed-off-by: Rik van Riel <riel@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > kernel/fork.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/fork.c b/kernel/fork.c > index aa1076c5e4a9..b3591e9250a8 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -560,7 +560,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) > set_task_stack_end_magic(tsk); > > #ifdef CONFIG_CC_STACKPROTECTOR > - tsk->stack_canary = get_random_long(); > + tsk->stack_canary = get_random_canary(); > #endif > > /* > -- > 2.9.3 > -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | Rik van Riel <riel@redhat.com> |
|---|---|
| Date | 2017-05-24 18:40 +0200 |
| Subject | [PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary |
| Message-ID | <tKHuh-4G7-1@gated-at.bofh.it> |
| In reply to | #1649725 |
Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel <riel@redhat.com> --- arch/sh/include/asm/stackprotector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/sh/include/asm/stackprotector.h b/arch/sh/include/asm/stackprotector.h index d9df3a76847c..141515a43b78 100644 --- a/arch/sh/include/asm/stackprotector.h +++ b/arch/sh/include/asm/stackprotector.h @@ -19,6 +19,7 @@ static __always_inline void boot_init_stack_canary(void) /* Try to get a semi random initial value. */ get_random_bytes(&canary, sizeof(canary)); canary ^= LINUX_VERSION_CODE; + canary &= CANARY_MASK; current->stack_canary = canary; __stack_chk_guard = current->stack_canary;
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2017-05-24 18:40 +0200 |
| Subject | Re: [PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary |
| Message-ID | <tKHui-4G7-3@gated-at.bofh.it> |
| In reply to | #1649752 |
On Wed, May 24, 2017 at 9:34 AM, Rik van Riel <riel@redhat.com> wrote: > Use the ascii-armor canary to prevent unterminated C string overflows > from being able to successfully overwrite the canary, even if they > somehow obtain the canary value. > > Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. > > Signed-off-by: Rik van Riel <riel@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > arch/sh/include/asm/stackprotector.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/sh/include/asm/stackprotector.h b/arch/sh/include/asm/stackprotector.h > index d9df3a76847c..141515a43b78 100644 > --- a/arch/sh/include/asm/stackprotector.h > +++ b/arch/sh/include/asm/stackprotector.h > @@ -19,6 +19,7 @@ static __always_inline void boot_init_stack_canary(void) > /* Try to get a semi random initial value. */ > get_random_bytes(&canary, sizeof(canary)); > canary ^= LINUX_VERSION_CODE; > + canary &= CANARY_MASK; > > current->stack_canary = canary; > __stack_chk_guard = current->stack_canary; > -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | riel@redhat.com |
|---|---|
| Date | 2017-05-24 18:50 +0200 |
| Subject | [PATCH 5/5] sh64: ascii armor the sh64 boot init stack canary |
| Message-ID | <tKHDY-4Jq-23@gated-at.bofh.it> |
| In reply to | #1649725 |
From: Rik van Riel <riel@redhat.com> Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel <riel@redhat.com> --- arch/sh/include/asm/stackprotector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/sh/include/asm/stackprotector.h b/arch/sh/include/asm/stackprotector.h index d9df3a76847c..141515a43b78 100644 --- a/arch/sh/include/asm/stackprotector.h +++ b/arch/sh/include/asm/stackprotector.h @@ -19,6 +19,7 @@ static __always_inline void boot_init_stack_canary(void) /* Try to get a semi random initial value. */ get_random_bytes(&canary, sizeof(canary)); canary ^= LINUX_VERSION_CODE; + canary &= CANARY_MASK; current->stack_canary = canary; __stack_chk_guard = current->stack_canary; -- 2.9.3
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web