<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>3868</bug_id>
          
          <creation_ts>2013-02-07 21:46:34 +0000</creation_ts>
          <short_desc>Add gcc security flags</short_desc>
          <delta_ts>2017-06-21 20:13:43 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>1.4</version>
          <rep_platform>x86</rep_platform>
          <op_sys>x86</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>08 April 2014: Setting documentation flag to &quot;Done.&quot;</status_whiteboard>
          <keywords></keywords>
          <priority>High</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>1.5 M4</target_milestone>
          
          <blocked>4718</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Dave Stewart">david.c.stewart</reporter>
          <assigned_to name="Saul Wold">sgw</assigned_to>
          <cc>alexandru.c.georgescu</cc>
    
    <cc>alexandru.damian</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>mihai.lindner</cc>
    
    <cc>peterlei</cc>
    
    <cc>raj.khem</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>se.brink15</cc>
    
    <cc>sgw</cc>
    
    <cc>srifenbark</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Done (doc changes complete)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>29654</commentid>
    <comment_count>0</comment_count>
    <who name="Dave Stewart">david.c.stewart</who>
    <bug_when>2013-02-07 21:46:34 +0000</bug_when>
    <thetext>According to Ryan Ware, there are some flags to ld and gcc which would improve on making our code more secure:

LDFLAGS=&quot;-z relro -z now -pie&quot;
CFLAGS=&quot;-fstack-protector -fpic -fpie -D_FORTIFY_SOURCE=2&quot;


I don&apos;t know if we can compile any of the kernel or user space with these flags. Maybe add them as a distro feature?  Add them to an ADT option?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29695</commentid>
    <comment_count>1</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-02-08 22:06:43 +0000</bug_when>
    <thetext>First step for this is to look at the failures in eglibc, I have added Khem Raj to the list.  I am not sure if he has looked at any of these flags for the core libraries or not.

e will need to fix eglibc before we can full understand the failure modes of the other projects.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29696</commentid>
    <comment_count>2</comment_count>
    <who name="Khem Raj">raj.khem</who>
    <bug_when>2013-02-08 23:02:21 +0000</bug_when>
    <thetext>This is good intent and I would support making this global defaults, right now we tell eglibc to not use libssp for its own subsystems e.g. login, libresolve and libnscd but it should support other apps fine FORTIFY_SOURCES is glibc feature which should work fine too. 

There is a bit of performance hit when we enable these features cumulatively they could reduce the the performance by 2-3%

Kernel has its own version of ssp CONFIG_CC_STACKPROTECTOR needs to be set for that and IIRC linux-yocto does not enable that option in standard profiles

many linux ecosystems has been working and weeding out issues in apps when compiled with these options so we should get some benefit but I would still
expect some failures.

1.4 could be an aggressive goal for it but if it is deemed important we could try</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>29715</commentid>
    <comment_count>3</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-02-11 16:53:57 +0000</bug_when>
    <thetext>This bug will require multiple bugs to filed based on the failures that occur, first should be against eglibc (which could be assigned to khem), then we will have to build the complete system and see what else fails and file bugs appropriately.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>30986</commentid>
    <comment_count>4</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-03-21 15:07:37 +0000</bug_when>
    <thetext>This is being marked for 1.5 as an enchantment, due to it being late in the process for 1.4, this change would require testing the complete system.

The following could be used for the build:

LDFLAGS +=&quot;-z relro -z now -pie&quot;

BASECFLAGS := &quot;${CFLAGS}&quot;
CFLAGS_pn-eglibc = &quot;${BASECFLAGS}&quot;
CFLAGS =&quot;${BASECFLAGS} -fstack-protector -fpic -fpie -D_FORTIFY_SOURCE=2&quot;

Eglibc does not need to be built with the these flags.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31449</commentid>
    <comment_count>5</comment_count>
    <who name="Bogdan Marinescu">bogdan.a.marinescu</who>
    <bug_when>2013-04-03 13:25:04 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; This is being marked for 1.5 as an enchantment, due to it being late in the
&gt; process for 1.4, this change would require testing the complete system.
&gt; 
&gt; The following could be used for the build:
&gt; 
&gt; LDFLAGS +=&quot;-z relro -z now -pie&quot;
&gt; 
&gt; BASECFLAGS := &quot;${CFLAGS}&quot;
&gt; CFLAGS_pn-eglibc = &quot;${BASECFLAGS}&quot;
&gt; CFLAGS =&quot;${BASECFLAGS} -fstack-protector -fpic -fpie -D_FORTIFY_SOURCE=2&quot;
&gt; 
&gt; Eglibc does not need to be built with the these flags.

Shouldn&apos;t eglibc be built at least with RELRO enabled? This is what happens on my desktop:

$ cat /proc/self/maps 
00400000-0040b000 r-xp 00000000 08:11 1458817                            /bin/cat
0060a000-0060b000 r--p 0000a000 08:11 1458817                            /bin/cat
0060b000-0060c000 rw-p 0000b000 08:11 1458817                            /bin/cat
00ea1000-00ec2000 rw-p 00000000 00:00 0                                  [heap]
7fa6a5ae6000-7fa6a5db2000 r--p 00000000 08:11 41750                      /usr/lib/locale/locale-archive
7fa6a5db2000-7fa6a5f67000 r-xp 00000000 08:11 295722                     /lib/x86_64-linux-gnu/libc-2.15.so
7fa6a5f67000-7fa6a6166000 ---p 001b5000 08:11 295722                     /lib/x86_64-linux-gnu/libc-2.15.so
7fa6a6166000-7fa6a616a000 r--p 001b4000 08:11 295722                     /lib/x86_64-linux-gnu/libc-2.15.so
7fa6a616a000-7fa6a616c000 rw-p 001b8000 08:11 295722                     /lib/x86_64-linux-gnu/libc-2.15.so
7fa6a616c000-7fa6a6171000 rw-p 00000000 00:00 0 
7fa6a6171000-7fa6a6193000 r-xp 00000000 08:11 169347                     /lib/x86_64-linux-gnu/ld-2.15.so
7fa6a6368000-7fa6a636b000 rw-p 00000000 00:00 0 
7fa6a6391000-7fa6a6393000 rw-p 00000000 00:00 0 
7fa6a6393000-7fa6a6394000 r--p 00022000 08:11 169347                     /lib/x86_64-linux-gnu/ld-2.15.so
7fa6a6394000-7fa6a6396000 rw-p 00023000 08:11 169347                     /lib/x86_64-linux-gnu/ld-2.15.so
7fffc9dce000-7fffc9df0000 rw-p 00000000 00:00 0                          [stack]
7fffc9dff000-7fffc9e00000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

This line:

7fa6a6166000-7fa6a616a000 r--p 001b4000 08:11 295722                     /lib/x86_64-linux-gnu/libc-2.15.so

suggests that glibc was also compiled with RELRO enabled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31520</commentid>
    <comment_count>6</comment_count>
    <who name="Bogdan Marinescu">bogdan.a.marinescu</who>
    <bug_when>2013-04-04 13:36:13 +0000</bug_when>
    <thetext>Sorry, moved this to &quot;accepted&quot; by mistake.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>31698</commentid>
    <comment_count>7</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-04-08 15:00:46 +0000</bug_when>
    <thetext>*** Bug 4212 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33131</commentid>
    <comment_count>8</comment_count>
    <who name="Bogdan Marinescu">bogdan.a.marinescu</who>
    <bug_when>2013-05-17 08:02:31 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; This is being marked for 1.5 as an enchantment, due to it being late in the
&gt; &gt; process for 1.4, this change would require testing the complete system.
&gt; &gt; 
&gt; &gt; The following could be used for the build:
&gt; &gt; 
&gt; &gt; LDFLAGS +=&quot;-z relro -z now -pie&quot;
&gt; &gt; 
&gt; &gt; BASECFLAGS := &quot;${CFLAGS}&quot;
&gt; &gt; CFLAGS_pn-eglibc = &quot;${BASECFLAGS}&quot;
&gt; &gt; CFLAGS =&quot;${BASECFLAGS} -fstack-protector -fpic -fpie -D_FORTIFY_SOURCE=2&quot;
&gt; &gt; 
&gt; &gt; Eglibc does not need to be built with the these flags.
&gt; 
&gt; Shouldn&apos;t eglibc be built at least with RELRO enabled? This is what happens
&gt; on my desktop:
&gt; 
&gt; $ cat /proc/self/maps 
&gt; 00400000-0040b000 r-xp 00000000 08:11 1458817                           
&gt; /bin/cat
&gt; 0060a000-0060b000 r--p 0000a000 08:11 1458817                           
&gt; /bin/cat
&gt; 0060b000-0060c000 rw-p 0000b000 08:11 1458817                           
&gt; /bin/cat
&gt; 00ea1000-00ec2000 rw-p 00000000 00:00 0                                 
&gt; [heap]
&gt; 7fa6a5ae6000-7fa6a5db2000 r--p 00000000 08:11 41750                     
&gt; /usr/lib/locale/locale-archive
&gt; 7fa6a5db2000-7fa6a5f67000 r-xp 00000000 08:11 295722                    
&gt; /lib/x86_64-linux-gnu/libc-2.15.so
&gt; 7fa6a5f67000-7fa6a6166000 ---p 001b5000 08:11 295722                    
&gt; /lib/x86_64-linux-gnu/libc-2.15.so
&gt; 7fa6a6166000-7fa6a616a000 r--p 001b4000 08:11 295722                    
&gt; /lib/x86_64-linux-gnu/libc-2.15.so
&gt; 7fa6a616a000-7fa6a616c000 rw-p 001b8000 08:11 295722                    
&gt; /lib/x86_64-linux-gnu/libc-2.15.so
&gt; 7fa6a616c000-7fa6a6171000 rw-p 00000000 00:00 0 
&gt; 7fa6a6171000-7fa6a6193000 r-xp 00000000 08:11 169347                    
&gt; /lib/x86_64-linux-gnu/ld-2.15.so
&gt; 7fa6a6368000-7fa6a636b000 rw-p 00000000 00:00 0 
&gt; 7fa6a6391000-7fa6a6393000 rw-p 00000000 00:00 0 
&gt; 7fa6a6393000-7fa6a6394000 r--p 00022000 08:11 169347                    
&gt; /lib/x86_64-linux-gnu/ld-2.15.so
&gt; 7fa6a6394000-7fa6a6396000 rw-p 00023000 08:11 169347                    
&gt; /lib/x86_64-linux-gnu/ld-2.15.so
&gt; 7fffc9dce000-7fffc9df0000 rw-p 00000000 00:00 0                         
&gt; [stack]
&gt; 7fffc9dff000-7fffc9e00000 r-xp 00000000 00:00 0                         
&gt; [vdso]
&gt; ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                 
&gt; [vsyscall]
&gt; 
&gt; This line:
&gt; 
&gt; 7fa6a6166000-7fa6a616a000 r--p 001b4000 08:11 295722                    
&gt; /lib/x86_64-linux-gnu/libc-2.15.so
&gt; 
&gt; suggests that glibc was also compiled with RELRO enabled.

Turns out that eglibc is compiled with RELRO support by default, so we don&apos;t have to worry about that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34491</commentid>
    <comment_count>9</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-07-10 18:44:36 +0000</bug_when>
    <thetext>http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=723ab4a892f59f0307599eabfff1dcbc9da80edb</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35876</commentid>
    <comment_count>10</comment_count>
    <who name="Mihai Lindner">mihai.lindner</who>
    <bug_when>2013-08-23 05:52:02 +0000</bug_when>
    <thetext>Does this need documentation change or has some in progress? Maybe we should have something about how can the security flags be enabled and what they do.
It took me some time to figure it out, but by reading bugs and local.conf.sample.extended.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>37650</commentid>
    <comment_count>11</comment_count>
    <who name="Saul Wold">sgw</who>
    <bug_when>2013-10-04 18:04:52 +0000</bug_when>
    <thetext>What additional documentation do you want, something in the manual, I am not sure where that would go, maybe ScottR can give some advice on where to document the usage of the security_flags.inc file.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>37652</commentid>
    <comment_count>12</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2013-10-04 19:56:18 +0000</bug_when>
    <thetext>Hi, 

Is this a completely separate topic?  Something like &quot;Making your Images more secure&quot;?  I am not sure.  Right now it looks that way.  In addition to having a section (if it warrants that), you would likely need to add some new variable descriptions or perhaps include some variable flag descriptions for the existing variables in the glossary (e.g. CFLAGS).  

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>37740</commentid>
    <comment_count>13</comment_count>
    <who name="Alexandru Georgescu">alexandru.c.georgescu</who>
    <bug_when>2013-10-08 12:46:09 +0000</bug_when>
    <thetext>(In reply to comment #12)
&gt; Hi, 
&gt; 
&gt; Is this a completely separate topic?  Something like &quot;Making your Images
&gt; more secure&quot;?  I am not sure.  Right now it looks that way.  In addition to
&gt; having a section (if it warrants that), you would likely need to add some
&gt; new variable descriptions or perhaps include some variable flag descriptions
&gt; for the existing variables in the glossary (e.g. CFLAGS).  
&gt; 
&gt; Scott

There&apos;s an indication on how to enable the security flags in the meta-yocto/conf/local.conf.sample.extended file:
require conf/distro/include/security_flags.inc must be added in local.conf in order to enable them.
I think the doc should mention this (how to enable them even if it&apos;s in the sample conf file) and like Mihai mentioned before, some description of what they actually do may be very helpful for the community.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>37909</commentid>
    <comment_count>14</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2013-10-14 17:48:06 +0000</bug_when>
    <thetext>Hi, 

Right now we do not document all the various settings that both local.conf and local.conf.extended offer in a dedicated spot within the YP manual set.  There are common settings that are called out and explained in the context of certain situations (e.g. setting the parallelism up for builds).  Also, there is not a section right now that addresses making a built image more secure using these flags.  So I think if the topic is important enough to call it out in the YP doc set, we will have to create a new section that addresses the topic.  Is this particular topic that important?  If so, I can create the separate topic in the dev-manual as a topic in the &quot;Common Tasks&quot; chapter. 

The alternative is to beef up the description in the comments of the local.conf.sample.extended file so that some more explanation appears there to describe the use of these flags.  I can also mention the ability to affect the image security through these files in a couple existing places in the manual.  We have a spot that discusses the local.conf file in general in the reference manual and we have an area in the &quot;Closer Look&quot; section that discusses the role of the local.conf file.  However, going into a full-blown discussion of the flags and how to use them would not be appropriate in these sections.  We could point to the actual sample files though.

So the question I need answered is this - Does this topic warrant a separate section in the development manual?  From Alexandru&apos;s last comment, I would say &quot;yes&quot;.  Are there any other opinions?

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42165</commentid>
    <comment_count>15</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2014-04-02 13:50:35 +0000</bug_when>
    <thetext>Hi, 

I have added a couple new areas to the YP docs to address the documentation part of this bug.  One section is a short, general description of how to enable the security flags in the security_flags.inc file.  The other is a reference from CFLAGS variable description back to the user section.  

Please review these and see if this is adequate for documenting this stuff.  

http://www.yoctoproject.org/docs/1.6/dev-manual/dev-manual.html#making-images-more-secure

http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-CFLAGS

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42382</commentid>
    <comment_count>16</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2014-04-08 14:18:10 +0000</bug_when>
    <thetext>Hi, 

After reviewing this bug with Richard and Paul the conclusion is we are done here for the documentation part.  I am marking the bug&apos;s documentation flag as &quot;Done.&quot;

Scott</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>