<?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>9488</bug_id>
          
          <creation_ts>2016-04-19 14:57:14 +0000</creation_ts>
          <short_desc>security_flags.inc does not use format string vulnerability prevention flags</short_desc>
          <delta_ts>2016-05-06 09:36:32 +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>Security - Recipe Upgrade</product>
          <component>security</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Elena Reshetova">elena.reshetova</reporter>
          <assigned_to name="Joshua Lock">joshuagloe</assigned_to>
          <cc>alex.kanavin</cc>
    
    <cc>jku</cc>
    
    <cc>joshuagloe</cc>
    
    <cc>juro.bystricky</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>61410</commentid>
    <comment_count>0</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-04-19 14:57:14 +0000</bug_when>
    <thetext>security_flags.inc should also add the following flags:

+# Add format string-specific flags
+SECURITY_CFLAGS += &quot;-Wformat -Wformat-security&quot;
+SECURITY_NO_PIE_CFLAGS += &quot;-Wformat -Wformat-security&quot;


These flags warn developers about potential security vulnerabilities with regards to format string issues.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61418</commentid>
    <comment_count>1</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2016-04-19 16:41:57 +0000</bug_when>
    <thetext>Why these flags in particular, and not -Wall -Wextra, or a broader subset of them?

Also, these should be enabled only after agreeing who will fix the resulting errors and send the fixes upstream: it&apos;s not a small task. Enabling these warnings and then ignoring them is worse than not enabling them at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61503</commentid>
    <comment_count>2</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-04-21 14:49:43 +0000</bug_when>
    <thetext>These flags do check for quite specific security issues which is why I think they&apos;re being suggested. I do share the concerns about how much work is potentially involved in this :/.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61518</commentid>
    <comment_count>3</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-04-21 16:23:21 +0000</bug_when>
    <thetext>I am trying to enable them now in Ostro scope: https://github.com/ostroproject/meta-ostro/pull/116/commits/a2779f89fc7f92b674053237326479352fd79c4f

That touches also in my understanding oe core packages that are used in Ostro. So far I found only small amount of packages that need exceptions, so it might not be that bad as it seems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61599</commentid>
    <comment_count>4</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2016-04-25 09:50:28 +0000</bug_when>
    <thetext>So can you enable it for oe-core, issue &apos;bitbake world&apos; and make a list of what starts to fail? It would be good to have some data, before making a decision of whether we proceed with this (against other things on our todo list).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61713</commentid>
    <comment_count>5</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-04-27 10:00:51 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; So can you enable it for oe-core, issue &apos;bitbake world&apos; and make a list of
&gt; what starts to fail? It would be good to have some data, before making a
&gt; decision of whether we proceed with this (against other things on our todo
&gt; list).

I did a `bitbake world -k` in poky with DISTRO = &quot;poky-lsb&quot; (because that uses security_flags) and the following diff applied to my poky tree:

diff --git a/meta/conf/distro/include/security_flags.inc b/meta/conf/distro/include/security_flags.inc
index ff5f34e..1a50d6f 100644
--- a/meta/conf/distro/include/security_flags.inc
+++ b/meta/conf/distro/include/security_flags.inc
@@ -9,8 +9,8 @@
 # -O0 which then results in a compiler warning.
 lcl_maybe_fortify = &quot;${@base_conditional(&apos;DEBUG_BUILD&apos;,&apos;1&apos;,&apos;&apos;,&apos;-D_FORTIFY_SOURCE=2&apos;,d)}&quot;
 
-SECURITY_CFLAGS ?= &quot;-fstack-protector-strong -pie -fpie ${lcl_maybe_fortify}&quot;
-SECURITY_NO_PIE_CFLAGS ?= &quot;-fstack-protector-strong ${lcl_maybe_fortify}&quot;
+SECURITY_CFLAGS ?= &quot;-fstack-protector-strong -pie -fpie ${lcl_maybe_fortify} -Wformat -Wformat-security&quot;
+SECURITY_NO_PIE_CFLAGS ?= &quot;-fstack-protector-strong ${lcl_maybe_fortify} -Wformat -Wformat-security&quot;
 
 SECURITY_LDFLAGS ?= &quot;-fstack-protector-strong -Wl,-z,relro,-z,now&quot;
 SECURITY_X_LDFLAGS ?= &quot;-fstack-protector-strong -Wl,-z,relro&quot;

and nothing failed. I know, I too am a little shocked.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61714</commentid>
    <comment_count>6</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2016-04-27 11:27:38 +0000</bug_when>
    <thetext>That&apos;s because it&apos;s only a warning, and will not make the build fail.
You need to use -Werror= to turn it into an error. 
https://gcc.gnu.org/onlinedocs/gcc-4.3.1/gcc/Warning-Options.html

Elena&apos;s Ostro patch has the same problem I believe, not sure how she found which packages need to be excepted from the check.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61765</commentid>
    <comment_count>7</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-04-28 08:28:59 +0000</bug_when>
    <thetext>Of course, thanks Alexander.

I tested a world build with &quot;-Wformat -Wformat-security -Werror=format-security&quot; added to the SECURITY_CFLAGS.

13 recipes failed to build and I was able to complete a world build by removing the flags for the recipes in question, i.e.:

SECURITY_CFLAGS_remove_pn-libuser = &quot;-Wformat -Wformat-security -Werror=format-security&quot;

The failing recipes are:
- busybox
- console-tools
- cmake
- expect
- gcc
- gettext
- kexec-tools
- leafpad
- libuser
- ltp
- makedevs
- oh-puzzles
- stat

I haven&apos;t begun to look at how much work fixing those recipes is, or if we get that work for free in an upgrade. 
I did discover that these are amongst the default flags in Fedora[1][2] (since ) and Ubuntu[3] and part of the Debian hardening options[4], so there may be patches floating around.

1. https://fedoraproject.org/wiki/Format-Security-FAQ
2. https://fedorahosted.org/fesco/ticket/1185
3. https://wiki.ubuntu.com/ToolChain/CompilerFlags
4. https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_FORMAT_.28gcc.2Fg.2B-.2B-_-Wformat_-Wformat-security_-Werror.3Dformat-security.29</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61770</commentid>
    <comment_count>8</comment_count>
    <who name="Jussi Kukkonen">jku</who>
    <bug_when>2016-04-28 10:31:01 +0000</bug_when>
    <thetext>(In reply to comment #7)

Documenting what I mentioned in chat already:

&gt; - leafpad

I&apos;m currently in process of updating oe-core to GTK+3 (at least for things in core-image-sato). This almost certainly includes getting rid of leafpad.

A possible replacement is l3afpad which is a fork and might still have the same problems.

&gt; - oh-puzzles

oh-puzzles will be removed (we already have &quot;puzzles&quot; in oe-core and according to your test that doesn&apos;t have this problem).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61783</commentid>
    <comment_count>9</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-04-28 10:49:41 +0000</bug_when>
    <thetext>I&apos;ve filed separate bugs (assigned to me) to resolve the string formatting issues in all of the identified recipes apart from Leafpad (where we should do the equivalent work on whatever replaces it, if required) and oh-puzzles (which will be removed).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61796</commentid>
    <comment_count>10</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-04-28 13:37:05 +0000</bug_when>
    <thetext>Patch submitted to OE-Core which elevates string-formatting issues to an error for all but 15 recipes. In addition to the 13 recipes mentioned earlier I also found zip and unzip fail to compile with -Werror=format-security

http://lists.openembedded.org/pipermail/openembedded-core/2016-April/120753.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61836</commentid>
    <comment_count>11</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-05-02 07:43:09 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; That&apos;s because it&apos;s only a warning, and will not make the build fail.
&gt; You need to use -Werror= to turn it into an error. 
&gt; https://gcc.gnu.org/onlinedocs/gcc-4.3.1/gcc/Warning-Options.html
&gt; 
&gt; Elena&apos;s Ostro patch has the same problem I believe, not sure how she found
&gt; which packages need to be excepted from the check.

Some packages turn Werror by default, this is how I found it. Having it as a warning it is a fist step.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61837</commentid>
    <comment_count>12</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-05-02 07:45:15 +0000</bug_when>
    <thetext>(In reply to comment #9)
&gt; I&apos;ve filed separate bugs (assigned to me) to resolve the string formatting
&gt; issues in all of the identified recipes apart from Leafpad (where we should
&gt; do the equivalent work on whatever replaces it, if required) and oh-puzzles
&gt; (which will be removed).

Thank you very much Joshua!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61840</commentid>
    <comment_count>13</comment_count>
    <who name="Alexander Kanavin">alex.kanavin</who>
    <bug_when>2016-05-02 09:54:25 +0000</bug_when>
    <thetext>(In reply to comment #11)
&gt; Some packages turn Werror by default, this is how I found it. Having it as a
&gt; warning it is a fist step.

Adding more compilation warnings is not useful in the context of openembedded build system. There are already hundreds of such warnings written into compile logs when packages are built, and nobody is going look at those logs until something fails.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61878</commentid>
    <comment_count>14</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-05-03 05:48:29 +0000</bug_when>
    <thetext>(In reply to comment #13)
&gt; (In reply to comment #11)
&gt; &gt; Some packages turn Werror by default, this is how I found it. Having it as a
&gt; &gt; warning it is a fist step.
&gt; 
&gt; Adding more compilation warnings is not useful in the context of
&gt; openembedded build system. There are already hundreds of such warnings
&gt; written into compile logs when packages are built, and nobody is going look
&gt; at those logs until something fails.

Sure, but now it is enabled with Werror, so I don&apos;t think we have an issue here. When the patch done by Joshua is merged, we can close this bug and track only separate components bugs. 

Joshua, could you please add me as a watcher to separate bugs?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61880</commentid>
    <comment_count>15</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-05-03 08:50:38 +0000</bug_when>
    <thetext>(In reply to comment #14)
&gt; Joshua, could you please add me as a watcher to separate bugs?

Done.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62012</commentid>
    <comment_count>16</comment_count>
    <who name="Joshua Lock">joshuagloe</who>
    <bug_when>2016-05-06 09:36:32 +0000</bug_when>
    <thetext>Patch to add format string vulnerability prevention flags to SECURITY_CFLAGS has been merged:

http://git.openembedded.org/openembedded-core/commit/?id=f335f8e744fb312b3eb599c331d08a9a6e5a8ff8

http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=30f9a5072d94f6c383b1ef5d25448af39691dce0</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>