Skip to contentSkip to conversation

security_flags.inc: fix flags missing from SDK toolchain

PATCH In review Tom Hochstein 3 participants 8 messages Mar 24, 2020 – Mar 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security_flags.inc: fix flags missing from SDK toolchain

The security flags were missing from the SDK toolchain because they were added specifically to class-target. Add them to class-cross-canadian as well.

---
 meta/conf/distro/include/security_flags.inc | 2 ++
 1 file changed, 2 insertions(+)
meta/conf/distro/include/security_flags.inc +2 -0
index aaf04e9e59..568d03693c 100644
@@ -57,6 +57,8 @@ SECURITY_STRINGFORMAT_pn-gcc = ""
 
 TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
 TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
+TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"
 
 SECURITY_STACK_PROTECTOR_pn-gcc-runtime = ""
 SECURITY_STACK_PROTECTOR_pn-glibc = ""
Signature · 1 line
2.17.1
#1 lore raw

I've already sent this patch few months ago but not taken into account yet. AM

From : Antoine Manache <[email protected]>
Date: mer. 20 nov. 2019 at 16:44
Subject: [OE-core] [PATCH v2] sdk: environment script doesn't set security options in CC and LDFLAGS variables
To: <[email protected]>

When building a SDK from a DISTRO with security flags enabled, options added to
CC and LDFLAGS are not replicated in the SDK environment script. This could lead to some situations where an application compiled with the SDK and having some security weaknesses correctly runs on target but crashes once integrated to the core image built with the full Yocto stack.

---
 meta/conf/distro/include/security_flags.inc | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/meta/conf/distro/include/security_flags.inc
index 620978a8ed..329482bfa3 100644

meta/conf/distro/include/security_flags.inc +2 -0
@@ -56,7 +56,9 @@ SECURITY_STRINGFORMAT_pn-busybox = ""
 SECURITY_STRINGFORMAT_pn-gcc = ""
 
 TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
+TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
 TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"
 
 SECURITY_STACK_PROTECTOR_pn-gcc-runtime = ""
 SECURITY_STACK_PROTECTOR_pn-glibc = ""

--
2.11.0

Le mar. 24 mars 2020 à 18:03, Tom Hochstein <[email protected]> a écrit :

Quoted 28 lines

The security flags were missing from the SDK toolchain because they were added specifically to class-target. Add them to class-cross-canadian as well.

---
 meta/conf/distro/include/security_flags.inc | 2 ++
 1 file changed, 2 insertions(+)
meta/conf/distro/include/security_flags.inc +2 -1
index aaf04e9e59..568d03693c 100644
@@ -57,6 +57,8 @@ SECURITY_STRINGFORMAT_pn-gcc = ""
 
 TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"
 TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
+TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"
 
 SECURITY_STACK_PROTECTOR_pn-gcc-runtime = ""
 SECURITY_STACK_PROTECTOR_pn-glibc = ""
--

2.17.1

#2 lore raw
Quoted 2 lines · Antoine Manache

I've already sent this patch few months ago but not taken into account yet.

Can someone explain more about the issue here please?

Shouldn't these flags be added to the SDK toolchain environment files rather than coded into the compiler? Why aren't they being coded in? or is gcc being misconfigured?

Cheers,

Richard

#3 lore raw
Quoted 10 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: Tuesday, March 24, 2020 1:03 PM
To: Antoine Manache <[email protected]>; Tom Hochstein <[email protected]>
Cc: [email protected]
Subject: Re: [OE-core][PATCH] security_flags.inc: fix flags missing from SDK toolchain

On Tue, 2020-03-24 at 18:25 +0100, Antoine Manache wrote:

Quoted 8 lines
Quoted 2 lines

I've already sent this patch few months ago but not taken into account yet.

Can someone explain more about the issue here please?

Shouldn't these flags be added to the SDK toolchain environment files rather than coded into the compiler? Why aren't they being coded in? or is gcc being misconfigured?

The recipe meta-environment inherits cross-canadian and toolchain-scripts. The latter generates the SDK toolchain environment file using TARGET_CC_ARCH and TARGET_LDFLAGS like this:

	echo 'export CC="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} --sysroot=$SDKTARGETSYSROOT"' >> $script
	echo 'export LDFLAGS="${TARGET_LDFLAGS}"' >> $script

https://github.com/openembedded/openembedded-core/blob/master/meta/classes/toolchain-scripts.bbclass#L82

With class-cross-canadian as the applicable override, updating the security flags for class-target does nothing for the SDK toolchain, hence the proposed fix:

TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}" +TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"

Tom

#4 lore raw

Absolutely.
I would add an example of issue I've seen in a software project. Someone developing a new application and using the image-based SDK that I provided got the right functional behaviour on target.
Once this application was integrated into the core image of our Yocto project (new recipe), the same tests on target failed (application crash). The root cause was : the two binaries produced were different because the effective GCC options at compile time were different between both methods (security flags not enabled when compiling with the SDK). Antoine

Le mar. 24 mars 2020 à 19:34, Tom Hochstein <[email protected]> a écrit :

Quoted 43 lines
Quoted 6 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: Tuesday, March 24, 2020 1:03 PM
To: Antoine Manache <[email protected]>; Tom Hochstein <

[email protected]>

Quoted 2 lines

Cc: [email protected]
Subject: Re: [OE-core][PATCH] security_flags.inc: fix flags missing from

SDK toolchain

Quoted 10 lines · Antoine Manache
Quoted 2 lines

I've already sent this patch few months ago but not taken into account yet.

Can someone explain more about the issue here please?

Shouldn't these flags be added to the SDK toolchain environment files rather than coded into the compiler? Why aren't they being coded in? or is gcc being misconfigured?

The recipe meta-environment inherits cross-canadian and toolchain-scripts. The latter generates the SDK toolchain environment file using TARGET_CC_ARCH and TARGET_LDFLAGS like this:

        echo 'export CC="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH}
--sysroot=$SDKTARGETSYSROOT"' >> $script
        echo 'export LDFLAGS="${TARGET_LDFLAGS}"' >> $script

https://github.com/openembedded/openembedded-core/blob/master/meta/classes/toolchain-scripts.bbclass#L82

With class-cross-canadian as the applicable override, updating the security flags for class-target does nothing for the SDK toolchain, hence the proposed fix:

TARGET_CC_ARCH_append_class-target = " ${SECURITY_CFLAGS}"

meta/conf/distro/include/security_flags.inc +2 -0
+TARGET_CC_ARCH_append_class-cross-canadian = " ${SECURITY_CFLAGS}"
 TARGET_LDFLAGS_append_class-target = " ${SECURITY_LDFLAGS}"
+TARGET_LDFLAGS_append_class-cross-canadian = " ${SECURITY_LDFLAGS}"

Tom

#5 lore raw
Quoted 11 lines · Antoine Manache

Absolutely.
I would add an example of issue I've seen in a software project. Someone developing a new application and using the image-based SDK that I provided got the right functional behaviour on target. Once this application was integrated into the core image of our Yocto project (new recipe), the same tests on target failed (application crash).
The root cause was : the two binaries produced were different because the effective GCC options at compile time were different between both methods (security flags not enabled when compiling with the SDK). Antoine

Thanks. Antonine's emails/patches are coming through as html and hence are mangled and I can't apply them which is probably where things got lost previously.

I've therefore taken Tom's version with some tweaks to the commit message.

Cheers,

Richard

#6 lore raw
Quoted 11 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: Tuesday, March 24, 2020 5:58 PM
To: Antoine Manache <[email protected]>; Tom Hochstein <[email protected]>
Cc: [email protected]
Subject: Re: [OE-core][PATCH] security_flags.inc: fix flags missing from SDK toolchain

I've therefore taken Tom's version with some tweaks to the commit message.

Thanks. Can we get this on zeus? Do I need to cherry-pick and submit the patch?

Tom

#7 lore raw
Quoted 9 lines · Tom Hochstein
Quoted 9 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: Tuesday, March 24, 2020 5:58 PM
To: Antoine Manache <[email protected]>; Tom Hochstein < [email protected]>
Cc: [email protected]
Subject: Re: [OE-core][PATCH] security_flags.inc: fix flags missing from SDK toolchain

Quoted 5 lines
Quoted 2 lines

I've therefore taken Tom's version with some tweaks to the commit message.

Thanks. Can we get this on zeus? Do I need to cherry-pick and submit the patch?

Yes, please post it and then the stable maintainers can review it.

Cheers,

Richard