2023-02-08 06:52:28

by Eric Biggers

[permalink] [raw]
Subject: [PATCH] randstruct: disable Clang 15 support

From: Eric Biggers <[email protected]>

The randstruct support released in Clang 15 is unsafe to use due to a
bug that can cause miscompilations: "-frandomize-layout-seed
inconsistently randomizes all-function-pointers structs"
(https://github.com/llvm/llvm-project/issues/60349). It has been fixed
on the Clang 16 release branch, so add a Clang version check.

Fixes: 035f7f87b729 ("randstruct: Enable Clang support")
Cc: [email protected]
Signed-off-by: Eric Biggers <[email protected]>
---
security/Kconfig.hardening | 3 +++
1 file changed, 3 insertions(+)

diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
index 53baa95cb644f..0f295961e7736 100644
--- a/security/Kconfig.hardening
+++ b/security/Kconfig.hardening
@@ -281,6 +281,9 @@ endmenu

config CC_HAS_RANDSTRUCT
def_bool $(cc-option,-frandomize-layout-seed-file=/dev/null)
+ # Randstruct was first added in Clang 15, but it isn't safe to use until
+ # Clang 16 due to https://github.com/llvm/llvm-project/issues/60349
+ depends on !CC_IS_CLANG || CLANG_VERSION >= 160000

choice
prompt "Randomize layout of sensitive kernel structures"

base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
--
2.39.1



2023-02-08 14:32:56

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] randstruct: disable Clang 15 support

On Tue, Feb 07, 2023 at 10:51:33PM -0800, Eric Biggers wrote:
> From: Eric Biggers <[email protected]>
>
> The randstruct support released in Clang 15 is unsafe to use due to a
> bug that can cause miscompilations: "-frandomize-layout-seed
> inconsistently randomizes all-function-pointers structs"
> (https://github.com/llvm/llvm-project/issues/60349). It has been fixed
> on the Clang 16 release branch, so add a Clang version check.
>
> Fixes: 035f7f87b729 ("randstruct: Enable Clang support")
> Cc: [email protected]
> Signed-off-by: Eric Biggers <[email protected]>

Reviewed-by: Nathan Chancellor <[email protected]>

> ---
> security/Kconfig.hardening | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
> index 53baa95cb644f..0f295961e7736 100644
> --- a/security/Kconfig.hardening
> +++ b/security/Kconfig.hardening
> @@ -281,6 +281,9 @@ endmenu
>
> config CC_HAS_RANDSTRUCT
> def_bool $(cc-option,-frandomize-layout-seed-file=/dev/null)
> + # Randstruct was first added in Clang 15, but it isn't safe to use until
> + # Clang 16 due to https://github.com/llvm/llvm-project/issues/60349
> + depends on !CC_IS_CLANG || CLANG_VERSION >= 160000
>
> choice
> prompt "Randomize layout of sensitive kernel structures"
>
> base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
> --
> 2.39.1
>
>

2023-02-08 18:05:02

by Bill Wendling

[permalink] [raw]
Subject: Re: [PATCH] randstruct: disable Clang 15 support

On Wed, Feb 8, 2023 at 6:32 AM Nathan Chancellor <[email protected]> wrote:
>
> On Tue, Feb 07, 2023 at 10:51:33PM -0800, Eric Biggers wrote:
> > From: Eric Biggers <[email protected]>
> >
> > The randstruct support released in Clang 15 is unsafe to use due to a
> > bug that can cause miscompilations: "-frandomize-layout-seed
> > inconsistently randomizes all-function-pointers structs"
> > (https://github.com/llvm/llvm-project/issues/60349). It has been fixed
> > on the Clang 16 release branch, so add a Clang version check.
> >
> > Fixes: 035f7f87b729 ("randstruct: Enable Clang support")
> > Cc: [email protected]
> > Signed-off-by: Eric Biggers <[email protected]>
>
> Reviewed-by: Nathan Chancellor <[email protected]>
>
Reviewed-by: Bill Wendling <[email protected]>

> > ---
> > security/Kconfig.hardening | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
> > index 53baa95cb644f..0f295961e7736 100644
> > --- a/security/Kconfig.hardening
> > +++ b/security/Kconfig.hardening
> > @@ -281,6 +281,9 @@ endmenu
> >
> > config CC_HAS_RANDSTRUCT
> > def_bool $(cc-option,-frandomize-layout-seed-file=/dev/null)
> > + # Randstruct was first added in Clang 15, but it isn't safe to use until
> > + # Clang 16 due to https://github.com/llvm/llvm-project/issues/60349
> > + depends on !CC_IS_CLANG || CLANG_VERSION >= 160000
> >
> > choice
> > prompt "Randomize layout of sensitive kernel structures"
> >
> > base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
> > --
> > 2.39.1
> >
> >

2023-02-08 18:53:51

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] randstruct: disable Clang 15 support

On Tue, Feb 7, 2023 at 10:52 PM Eric Biggers <[email protected]> wrote:
>
> From: Eric Biggers <[email protected]>
>
> The randstruct support released in Clang 15 is unsafe to use due to a
> bug that can cause miscompilations: "-frandomize-layout-seed
> inconsistently randomizes all-function-pointers structs"
> (https://github.com/llvm/llvm-project/issues/60349). It has been fixed
> on the Clang 16 release branch, so add a Clang version check.
>
> Fixes: 035f7f87b729 ("randstruct: Enable Clang support")
> Cc: [email protected]
> Signed-off-by: Eric Biggers <[email protected]>

Thanks for the patch and report. Guessing that wasn't fun to debug.
Acked-by: Nick Desaulniers <[email protected]>

> ---
> security/Kconfig.hardening | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
> index 53baa95cb644f..0f295961e7736 100644
> --- a/security/Kconfig.hardening
> +++ b/security/Kconfig.hardening
> @@ -281,6 +281,9 @@ endmenu
>
> config CC_HAS_RANDSTRUCT
> def_bool $(cc-option,-frandomize-layout-seed-file=/dev/null)
> + # Randstruct was first added in Clang 15, but it isn't safe to use until
> + # Clang 16 due to https://github.com/llvm/llvm-project/issues/60349
> + depends on !CC_IS_CLANG || CLANG_VERSION >= 160000
>
> choice
> prompt "Randomize layout of sensitive kernel structures"
>
> base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
> --
> 2.39.1
>
>


--
Thanks,
~Nick Desaulniers

2023-02-08 18:58:36

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] randstruct: disable Clang 15 support

On Tue, 7 Feb 2023 22:51:33 -0800, Eric Biggers wrote:
> From: Eric Biggers <[email protected]>
>
> The randstruct support released in Clang 15 is unsafe to use due to a
> bug that can cause miscompilations: "-frandomize-layout-seed
> inconsistently randomizes all-function-pointers structs"
> (https://github.com/llvm/llvm-project/issues/60349). It has been fixed
> on the Clang 16 release branch, so add a Clang version check.
>
> [...]

Applied to for-next/hardening, thanks!

[1/1] randstruct: disable Clang 15 support
https://git.kernel.org/kees/c/7ee3819f2ba9

--
Kees Cook