<?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>10518</bug_id>
          
          <creation_ts>2016-10-28 06:50:40 +0000</creation_ts>
          <short_desc>swupd compatibility with image-prelink</short_desc>
          <delta_ts>2018-10-11 15:25:59 +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>Other YP Layers</product>
          <component>meta-swupd</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>OBSOLETE</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>Future</target_milestone>
          <dependson>10268</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Patrick Ohly">patrick.ohly</reporter>
          <assigned_to name="Patrick Ohly">patrick.ohly</assigned_to>
          <cc>brian.avery</cc>
    
    <cc>elena.reshetova</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</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>67708</commentid>
    <comment_count>0</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-10-28 06:50:40 +0000</bug_when>
    <thetext>When prelinking is active (for example, due to USER_CLASSES ?= &quot;buildstats image-mklibs image-prelink&quot; as in Ostro OS&apos; local.conf.sample), then binaries that were not recompiled still change during image construction.

Prelinking seems to be a bit non-reproducible. For example, configure a build of Ostro OS for qemux86 with BUNDLE_CONTENTS_WORLD=&quot;gdb&quot;. Build &quot;ostro-image-swupd&quot;. Change to BUNDLE_CONTENTS_WORLD=&quot;strace&quot;. Build again (may need some manual cleanup to work around issues in meta-swupd; I have fixes for those problems).

In this example, /usr/lib/liblzma.so.5.2.2 is different in the resulting images (and several more, 226 files in total).

I suspect that this is because prelink needs to lay out shared libraries so that they don&apos;t overlap when used by any of the binaries available in the system (https://linux.die.net/man/8/prelink). Adding a new binary adds another combination of libs which then changes how libraries need to be laid out.

This makes updates larger than they could be.

It is unclear whether prelinking works at all in combination with swupd: swupd excludes time stamps from its hashing, so if only the modification time of a file changes, then swupd won&apos;t update it on the target. That means there&apos;s no guarantee that time stamps of files match the ones in the prelinked image. But prelink depends on time stamps while checking whether the prelinking is still valid.

Whether that really breaks prelinking in practice might be worth checking.

Overall it seems that it might simpler to just disable prelinking.

Depending on the analysis of the this problem, different changes may be needed:
- warn (or error?) in meta-swupd when prelinking is active
- fix swupd to ensure that time stamps are preserved (major change!)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67710</commentid>
    <comment_count>1</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-10-28 07:01:06 +0000</bug_when>
    <thetext>Elena, can you provide some advice on prelinking (https://linux.die.net/man/8/prelink) and its security implications vs. expected performance increase? See also https://lwn.net/Articles/341244/ for some (very old!) discussion. I&apos;m wondering what the current thinking about this feature is in the security community.

See also 
http://lists.openembedded.org/pipermail/openembedded-core/2015-October/112004.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67773</commentid>
    <comment_count>2</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-10-31 07:21:49 +0000</bug_when>
    <thetext>So, in short nothing really changed much in prelink world. It is still bad from security point of view since it removes ASLR almost fully. Nowadays prelink comes with -R random option that attempts to randomize load address to be not so horrible from security point of view, but it seems that this address is pretty easy to discoved on running system, so it doesn&apos;t add any additional protection in practice. 

So, conclusion from security point of view: do not use prelink unless absolutely required and be aware of its security implications: mainly return into libc attacks become rather trivial.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67920</commentid>
    <comment_count>3</comment_count>
    <who name="brian avery">brian.avery</who>
    <bug_when>2016-11-03 16:10:15 +0000</bug_when>
    <thetext>In Bug 10268 I outline the 2 things that introduce the randomization.
1) We *do* use -R by default and this does introduce binary differences.
2) Prelink includes a timestamp for when each library was prelinked. This cannot currently br turned off with an option so this will always introduce binary differences unless we patch prelink.

You can also use prelink itself to do binary compares which essentially unlink compare and relink the binaries.

More info at https://wiki.yoctoproject.org/wiki/TipsAndTricks/PrelinkSomePointersAndWorkarounds</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67962</commentid>
    <comment_count>4</comment_count>
    <who name="Elena Reshetova">elena.reshetova</who>
    <bug_when>2016-11-04 07:08:14 +0000</bug_when>
    <thetext>Default usage of -R flag is certainly better than not using it from security point of view,  but it should not be confused with having proper security that ALSR can give in run-time. 

Just want to make sure everyone understands this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67964</commentid>
    <comment_count>5</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2016-11-04 07:30:32 +0000</bug_when>
    <thetext>My conclusion is that supporting prelinking in combination with swupd updates is neither required nor recommended. A device where prelinking is useful enough to justify the disadvantages is likely too small to run swupd.

Therefore I intend to resolve this issue here by adding a check in meta-swupd which warns when prelinking is enabled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67991</commentid>
    <comment_count>6</comment_count>
    <who name="brian avery">brian.avery</who>
    <bug_when>2016-11-04 18:14:03 +0000</bug_when>
    <thetext>That works for me.  If someone really needs it to work with prelinking, the 2 things that need to be changed are straightforward, though, as Elena points out, 1 of them makes it even less secure. (no -R, patch to remove timestamp data which is only used for an on target  re prelinking optimization)

Basic gain on QEMU system was ~ 10-15% faster.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81812</commentid>
    <comment_count>7</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2018-10-11 15:25:59 +0000</bug_when>
    <thetext>Upstream swupd has changed a lot and integration with the Yocto Project would be tricky and need rework to the layer. Closing this as obsolete since any new integration would need rework and have its own issues.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>