<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7438549283734029720</id><updated>2012-02-07T20:17:49.950+01:00</updated><title type='text'>siddhadev's blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://siddhadev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7438549283734029720/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://siddhadev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>siddhadev</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7438549283734029720.post-4237262369701228331</id><published>2012-02-03T23:57:00.001+01:00</published><updated>2012-02-04T01:21:34.402+01:00</updated><title type='text'>Relative INTERP in ELF and set-uid</title><content type='html'>The combination of a set-uid and a relative path in the INTERP section of an ELF binary is very dangerous. &lt;br /&gt;
&lt;br /&gt;
This seems to be general security issue/leak concerning how dynamic linking in linux/glibc works, so let me explain what it is: &lt;br /&gt;
&lt;br /&gt;
Consider building a dynamically linked binary and specifying a relative path in the ELF &lt;code&gt;INTERP&lt;/code&gt; section (using the &lt;code&gt;--dynamic-linker&lt;/code&gt; gcc option) so you could redistribute a custom glibc version with your dynamically linked commercial application (where you are not allowed to link statically against the LGPL glibc, but still need to make your binary work across different linux distribution having different glibc versions).&lt;br /&gt;
&lt;br /&gt;
If you chown the binary to root, and put the set-uid flag on your binary, it effectively becomes a rootkit. As executing it from a different directory, allows you to replace the dynamic linker executable, that will be executed with root permission.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, take a look at the following C code (issue.c): &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: c"&gt;// issue.c
//    
// build like this: 
//   DLINKER=.lib64/ld-linux-x86-64.so.2
//   gcc -DNAME=\"vulnarable\" -o issue -Wl,--dynamic-linker,$DLINKER issue.c 
//   sudo chown root issue 
//   sudo chmod u+s issue 
// now build the code to be executed with 
// root permissions (we use the same issue.c): 
//   mkdir -p .lib64/ 
//   gcc -DNAME=\"rootkit\" -o $DLINKER --static issue.c 
// 

#include &lt;stdio.h&gt;
    
int main(int argc, char* argv[]) 
{ 
    printf("(%s) euid:%d\n", NAME, geteuid()); 
} 
&lt;/pre&gt;&lt;br /&gt;
If you now execute the set-uid binary like this&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: bash"&gt;./issue
&lt;/pre&gt;&lt;br /&gt;
or even just do this&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: bash"&gt;ldd issue
&lt;/pre&gt;&lt;br /&gt;
instead of getting what you might expect, e.g.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: bash"&gt;(vulnarable) euid:0
&lt;/pre&gt;&lt;br /&gt;
you get&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: bash"&gt;(rootkit) euid:0
&lt;/pre&gt;&lt;br /&gt;
The point is you could replace the &lt;code&gt;ld-linux-x86-64.so.6&lt;/code&gt; binary with whatever you like, and it will get executed with root permissions.&lt;br /&gt;
&lt;br /&gt;
Similar issues seems to have been addressed by not resolving &lt;code&gt;$ORIGIN&lt;/code&gt; in &lt;code&gt;RPATH&lt;/code&gt; or ignoring &lt;code&gt;LD_LIBRARY_PATH&lt;/code&gt; if the set-uid flag is set. &lt;br /&gt;
&lt;br /&gt;
So I wonder if the &lt;code&gt;INTERP&lt;/code&gt; in ELF has to be ignored whenever the set-uid flag is set (i.e. by using the default dynamic linker - &lt;code&gt;/lib32/ld-linux.so.2&lt;/code&gt; or &lt;code&gt;/lib64/ld-linux-x86-64.so.2&lt;/code&gt;)?&lt;br /&gt;
&lt;br /&gt;
So what do you think, where should this be fixed or reported - in glibc or the kernel?&lt;br /&gt;
&lt;br /&gt;
The discussion at stackoverflow &lt;a href="http://stackoverflow.com/questions/9019083/security-issue-with-set-uid-and-a-relative-path-for-interp-dynamic-linker-in-e"&gt;security issue with set-uid and a relative path for INTERP (dynamic linker) in ELF&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7438549283734029720-4237262369701228331?l=siddhadev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://siddhadev.blogspot.com/feeds/4237262369701228331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7438549283734029720&amp;postID=4237262369701228331' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7438549283734029720/posts/default/4237262369701228331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7438549283734029720/posts/default/4237262369701228331'/><link rel='alternate' type='text/html' href='http://siddhadev.blogspot.com/2012/02/relative-interp-in-elf-and-set-uid.html' title='Relative INTERP in ELF and set-uid'/><author><name>siddhadev</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7438549283734029720.post-2619729174888681492</id><published>2009-07-02T09:57:00.004+02:00</published><updated>2012-02-07T20:17:49.973+01:00</updated><title type='text'>Joshua Bloch: Here's a Mystic Code Poem</title><content type='html'>The &lt;a href="http://java.sun.com/developer/technicalArticles/Interviews/devinsight_4/#1"&gt;Mystic Code Poem&lt;/a&gt; from Joshua Bloch could be written down in an even more mystical and funny way: &lt;br /&gt;
&lt;blockquote&gt;&lt;pre class="brush: c"&gt;int inverse(int __) { 
  int _=__; 
 
  _*= -~-~- (__*_); 
  _*= -~-~- (__*_); 
  _*= -~-~- (__*_); 
  _*= -~-~- (__*_); 
 
  return _; 
}&lt;/pre&gt;&lt;/blockquote&gt;Not quite obvious, but the code above will find the multiplicative inverse of its odd parameter, e.g. &lt;code&gt;N*inverse(N) = 1 mod 2^32&lt;/code&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7438549283734029720-2619729174888681492?l=siddhadev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://java.sun.com/developer/technicalArticles/Interviews/devinsight_4/#1' title='Joshua Bloch: Here&apos;s a Mystic Code Poem'/><link rel='replies' type='application/atom+xml' href='http://siddhadev.blogspot.com/feeds/2619729174888681492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7438549283734029720&amp;postID=2619729174888681492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7438549283734029720/posts/default/2619729174888681492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7438549283734029720/posts/default/2619729174888681492'/><link rel='alternate' type='text/html' href='http://siddhadev.blogspot.com/2009/07/joshua-bloch-heres-mystic-code-poem.html' title='Joshua Bloch: Here&apos;s a Mystic Code Poem'/><author><name>siddhadev</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
