LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-14-2003, 04:47 PM   #1
MaulingMonkey
Member
 
Registered: Aug 2003
Posts: 31

Rep: Reputation: 16
relocationg ld-linux.so without breaking programs?


I'm creating a homebrew linux setup from scratch, and being the dweeb that I am, I'm changing the filetree, too.

The Problem: dynamically linked programs have to specify the entire path to ld-config.so, making the movement of said file rather difficult...

The Question: Is there a utility for editing the libraries linked to by a binary? At the very least one could hex-edit a path of equal length to the original path... but that's sort of ugly, no?

Also, I noticed a rather interesting tidbit in my ld.so manpage... specifically the synopsis:

The dynamic linker can be run either indirectly through running some
dynamically linked program or library (in which case no command line
options to the dynamic linker can be passed and the dynamic linker
which is stored in the .interp section of the program is executed) or
directly by running:

/lib/ld-linux.so.* [OPTIONS] [PROGRAM [ARGUMENTS]]

Would there be adverse effects of running a staticly-linked program via ld-linux.so? A dynamicly-linked program using an older version?

Thanks for any/all replies....

-Mike
 
Old 11-14-2003, 05:01 PM   #2
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
Maybe I was wrong but I thought that the file /etc/ld.so.conf keeps the path track to all usable libaries which are checked if dynamic loading is done. See 'man ldconfig'.
 
Old 11-14-2003, 05:06 PM   #3
MaulingMonkey
Member
 
Registered: Aug 2003
Posts: 31

Original Poster
Rep: Reputation: 16
Quote:
Originally posted by dorian33
Maybe I was wrong but I thought that the file /etc/ld.so.conf keeps the path track to all usable libaries which are checked if dynamic loading is done. See 'man ldconfig'.
For most libraries. ld.so (or ld-linux.so) is a special library that has the code that implements the checking of said files. Running ldconfig using the -f and -C arguments can reconfigure ld.so/ld-linux.so to use alternatives to ld.so.conf and ld.so.cache.

Try this on a dynamic program:
panda@localhost panda]$ ldd /bin/bash
libtermcap.so.2 => /lib/libtermcap.so.2 (0x40020000)
libdl.so.2 => /lib/libdl.so.2 (0x40024000)
libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

notice the full path specified for ld-linux.so. This is because before the code there gets executed, it dosn't have a clue about /etc/ld.so.conf (and /etc/ld.so.cache) and thus has no clue where it would find it.
 
Old 11-14-2003, 05:59 PM   #4
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
Re: relocationg ld-linux.so without breaking programs?

Right. I see what is the matter. But why it is a problem? What for you need to change the location of ld-linux.so.2 ? (There is something like FHS).
 
Old 11-15-2003, 12:37 AM   #5
MaulingMonkey
Member
 
Registered: Aug 2003
Posts: 31

Original Poster
Rep: Reputation: 16
Re: Re: relocationg ld-linux.so without breaking programs?

Quote:
Originally posted by dorian33
Right. I see what is the matter. But why it is a problem? What for you need to change the location of ld-linux.so.2 ? (There is something like FHS).
Quote:
Originally posted by myself
I'm creating a homebrew linux setup from scratch, and being the dweeb that I am, I'm changing the filetree, too.
Being a huge fan of organization, I abhor the fact that, for example, games, shells, and system utilities (well, the 'unimportant' half that don't go in /sbin) are all grouped into a single folder called /bin. Trying to see what's available in terms of shells on a system you just logged into? good luck having a quick skim... type ls and you'll have to sort out cat, echo, vi, freeciv, etc etc... not to mention ls itself. I find that methodology to be totally unacceptable.

The problem still exists, allthough is less prevalant, for libraries. For example, I don't like the idea of having, say, the libraries that consist of PAM (plugable authentication modules) in the same pile as, say, SDL, all the different image libraries, and basic important libraries such as libc, terminfo, etc. I could live with it if there was just a /slib as well as the allready existing /lib. Guess what though? ld-config.so would belong in that slib folder.

When it comes to computers, I'm a control freak. I want to know exactly where everything fits, and I want it nice and organized. Probably because I can barely get to my bed in my room. Clutter in one life, organization in another :-p.

As for running statically linked programs with ld-config.so, I found my answer. It segfaults, at least on my system. Bah humbug!!!

Still looking for answers to my question... anybody?
 
Old 11-15-2003, 05:01 AM   #6
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
Re: Re: Re: relocationg ld-linux.so without breaking programs?

Quote:
Originally posted by MaulingMonkey
Trying to see what's available [...] type ls and you'll have to sort out cat, echo, vi, freeciv, etc etc... not to mention ls itself. I find that methodology to be totally unacceptable.The problem still exists, although is less prevalant, for libraries.
As I understand the clue of your investigation is security. Am I right? If not pass the rest of the post.

Since all the /lib directory is root owned what will change if you get your target and create /slib & /lib ?
Both of them will be also root owned so an intruder can list them.
Would he find the problem since he doesn't know what to list? I don't think so. He can at any moment look at ELF binary and find the string with (as you wrote yourself) full path to the ld-config.so. It is a plain text.

The /bin & /sbin directory existence is not a matter of better security. So /lib & /slib won't be also.
Any user can run the program from /sbin and cannot run from /bin depending of privileges - not because of path.

I think the better solution is to use grsecurity.
But maybe I'm wrong. Try change my mind :)
Regarding your problem I have no solution at the moment.

Anyway I like to discuss such problems since I am fed up with with posts like '..help..', '... not working...' etc. Your question concerns new(?) idea. But let me to consider and know if the idea is valuable or not firstly (before thinking about the solution).

So although I haven't advice for you I will trace this post - maybe a linux guru answer.
 
Old 11-15-2003, 03:32 PM   #7
MaulingMonkey
Member
 
Registered: Aug 2003
Posts: 31

Original Poster
Rep: Reputation: 16
Re: Re: Re: Re: relocationg ld-linux.so without breaking programs?

Quote:
Originally posted by dorian33
As I understand the clue of your investigation is security. Am I right? If not pass the rest of the post.
The only way this relates to security is that by having everything nice and organized, it makes knowing what's installed on your system a lot easier. Having shells, commands, and even games all in the same directory is NOT my idea of organization.

I am well aware that /bin and /sbin (not to mention /usr/bin and /usr/sbin) derive their existance from non-security reasons. /sbin contains programs critical to the operation of the system, /bin utilities that are less critical.

The difference between /lib and /slib would be similar. /slib would hold libraries critical to the operation of the system (PAM modules, for example, for login and such) versus /lib which would hold libraries of lesser importance (such as SDL). But I want more organization than that anyways.

Heck, the main reason /sbin even exists is so that it can be put on it's own partition, which allows for putting /bin on a network, for example, and still being able to boot in case of network failure... you know, to try and fix the problem?

The end goal of changing around the file tree is simply organization. Organization leads to understanding. Understanding leads to ease of administration.

Also, a final note: "Both of them will be also root owned so an intruder can list them" (when talking about /lib and /slib): being owned by root does not make them listable. Setting the permissions to allow for entry is what makes them listable. And if it wasn't listable, then it wouldn't be accessable, anyways, which would defeat the purpouse of placing ld-config.so into /slib, because all dynamic programs would then have to be suid root to run!!! And that, as I'm sure you know, would be a very, very, very bad idea... I'm 99% sure that ls,cp,mv, and rm don't have safeguards against being suid root'ed.

It looks like I'm going to end up writing a wrapper... something like:

if [ `ldd $program | grep "/lib/ld-linux.so.2"` ]
#old style linking to ld-linux.so.2
/slib/ld-linux.so.2 $program $args
elif [ `ldd $program | grep "/lib/ld-linux.so.3"` ]
#old style linking to ld-linux.so.3
/slib/ld-linux.so.3 $program $args
else
#either static, or unknown style of linking. Try just runing it.
$program $args
fi

since it would seem (from the lack of replies to the contrary) that no tool for hacking a binary's paths exits. Most likely hardcoded in C++ into pxshell (the PandariX shell) rather than be in shell script... but you get the idea.

As for organization: ld-linux.so is a rather odd library, one that might almost belong in /sbin rather than /lib (it is, after all, a program!). One could argue for /bin instead, as that would place it into the path, allowing the low level code of an elf binary to instead of executing the ld-linux.so code internally, instead runs ld-linux.so (without having to specify a path, since it's in the $PATH) with itself as an argument.

If I'm correct, this would still list under ps as the program name, allows the program to be directly run, and removes the need to list the full path of ld-linux.so.

I think I'm onto something! ^_^. After lunch I'll go find out exactly how to implement that (for my own programs)... I assume it would have to do with overriding one of the base libraries (whichever one contains the entry point), and then creating a modified version appropriately (which would be over-ridden by ld-linux.so's entry point when relaunched).

Tata till after lunch.
-Mike
 
Old 11-16-2003, 12:06 AM   #8
teknomage1
LQ Newbie
 
Registered: Aug 2003
Posts: 17

Rep: Reputation: 0
since you're a huge fan of organization i gues something cludgy like symlinks is out of the question. Have you considered making a database out of your filestystem so you could sort files by purpose and whatever else and then present virtual trees that are more aestetically pleasing, while still maintaining the files legacy locations?
 
Old 11-16-2003, 04:53 AM   #9
MaulingMonkey
Member
 
Registered: Aug 2003
Posts: 31

Original Poster
Rep: Reputation: 16
Quote:
Originally posted by teknomage1
since you're a huge fan of organization i gues something cludgy like symlinks is out of the question.
Yup.
Quote:
[B}Have you considered making a database out of your filestystem so you could sort files by purpose and whatever else and then present virtual trees that are more aestetically pleasing, while still maintaining the files legacy locations?[/B]
I've considered it... but decided against. Too much of a hack :-/.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are these programs - or equivalent programs - available for Linux? voly Linux - Software 12 07-29-2005 03:44 AM
Breaking out of Chroot Aeiri Linux - Security 1 02-26-2005 03:10 PM
Slackware is breaking on me h1tman Slackware 8 08-18-2003 07:53 AM
It's this a breaking attent? hubergeek Linux - Security 1 11-27-2002 12:24 PM
Breaking Windows cli_man General 17 04-20-2002 03:35 AM


All times are GMT -5. The time now is 11:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration