Skip to contentSkip to conversation

Add a /proc/self/exedir link

PATCH In review Mike Hearn 8 participants 12 messages Apr 3, 2006 – Apr 8, 2006

lore
Share & tools
lore

Mike Hearn

author
#0 lore raw

PATCH 1/1 Add a /proc/self/exedir link

Alright, Andrew Morton indicated that he liked this patch but the idea needed discussion and mindshare. I asked Con Kolivas if it made sense to go in his desktop patchset for people to try: he said he liked it too but it's not his area, and that it should be discussed here.

To clarify, I'm proposing this patch for eventual mainline inclusion.

It adds a simple bit of API - a symlink in /proc/pid - which makes it easy to build relocatable software:

  ./configure --prefix=/proc/self/exedir/..

This is useful for a variety of purposes:

* Distributing programs that are runnable from CD or USB key (useful for Linux magazine cover disks)

* Binary packages that can be installed anywhere, for instance, to your home directory

* Network admins can more easily place programs on network mounts

I'm sure you can think of others. You can patch software to be relocatable today, but it's awkward and error prone. A simple patch can allow us to get it "for free" on any UNIX software that uses the idiomatic autotools build system.

So .... does anybody have any objections to this? Would you like to see it go in? Speak now or forever hold your peace! :)

thanks -mike

proc/base.c renamed from proc/base.c~ +9 -0
@@ -95,6 +95,7 @@
 	PROC_TGID_CWD,
 	PROC_TGID_ROOT,
 	PROC_TGID_EXE,
+	PROC_TGID_EXEDIR,
 	PROC_TGID_FD,
 	PROC_TGID_ENVIRON,
 	PROC_TGID_AUXV,
@@ -135,6 +136,7 @@
 	PROC_TID_CWD,
 	PROC_TID_ROOT,
 	PROC_TID_EXE,
+	PROC_TID_EXEDIR,
 	PROC_TID_FD,
 	PROC_TID_ENVIRON,
 	PROC_TID_AUXV,
@@ -200,6 +202,7 @@
 	E(PROC_TGID_CWD,       "cwd",     S_IFLNK|S_IRWXUGO),
 	E(PROC_TGID_ROOT,      "root",    S_IFLNK|S_IRWXUGO),
 	E(PROC_TGID_EXE,       "exe",     S_IFLNK|S_IRWXUGO),
+	E(PROC_TGID_EXEDIR,    "exedir",  S_IFLNK|S_IRWXUGO),
 	E(PROC_TGID_MOUNTS,    "mounts",  S_IFREG|S_IRUGO),
 #ifdef CONFIG_MMU
 	E(PROC_TGID_SMAPS,     "smaps",   S_IFREG|S_IRUGO),
@@ -242,6 +245,7 @@
 	E(PROC_TID_CWD,        "cwd",     S_IFLNK|S_IRWXUGO),
 	E(PROC_TID_ROOT,       "root",    S_IFLNK|S_IRWXUGO),
 	E(PROC_TID_EXE,        "exe",     S_IFLNK|S_IRWXUGO),
+	E(PROC_TID_EXEDIR,     "exedir",  S_IFLNK|S_IRWXUGO),
 	E(PROC_TID_MOUNTS,     "mounts",  S_IFREG|S_IRUGO),
 #ifdef CONFIG_MMU
 	E(PROC_TID_SMAPS,      "smaps",   S_IFREG|S_IRUGO),
@@ -1656,6 +1660,11 @@
 			inode->i_op = &proc_pid_link_inode_operations;
 			ei->op.proc_get_link = proc_exe_link;
 			break;
+		case PROC_TID_EXEDIR:
+		case PROC_TGID_EXEDIR:
+			inode->i_op = &proc_pid_link_inode_operations;
+			ei->op.proc_get_link = proc_exedir_link;
+			break;
 		case PROC_TID_CWD:
 		case PROC_TGID_CWD:
 			inode->i_op = &proc_pid_link_inode_operations;
proc/internal.h renamed from proc/internal.h~ +1 -0
@@ -32,6 +32,7 @@
 
 extern void create_seq_entry(char *name, mode_t mode, struct file_operations *f);
 extern int proc_exe_link(struct inode *, struct dentry **, struct vfsmount **);
+extern int proc_exedir_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt);
 extern int proc_tid_stat(struct task_struct *,  char *);
 extern int proc_tgid_stat(struct task_struct *, char *);
 extern int proc_pid_status(struct task_struct *, char *);
proc/task_mmu.c renamed from proc/task_mmu.c~ +14 -0
@@ -101,6 +101,20 @@
 	return result;
 }
 
+int proc_exedir_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
+{
+	struct dentry *exe;
+	int result = proc_exe_link(inode, &exe, mnt);
+
+	if (result < 0)
+		return result;
+
+	*dentry = dget_parent(exe);
+	dput(exe);
+
+	return result;
+}
+
 static void pad_len_spaces(struct seq_file *m, int len)
 {
 	len = 25 + sizeof(void*) * 6 - len;
proc/task_nommu.c renamed from proc/task_nommu.c~ +14 -0
@@ -137,6 +137,20 @@
 	return result;
 }
 
+int proc_exedir_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
+{
+	struct dentry *exe;
+	int result = proc_exe_link(inode, &exe, mnt);
+	
+	if (result < 0)
+		return result;
+
+	*dentry = dget_parent(exe);
+	dput(exe);
+
+       return result;
+}
+
 /*
  * Albert D. Cahalan suggested to fake entries for the traditional
  * sections here.  This might be worth investigating.
#1 lore raw
Quoted 27 lines · Mike Hearn

Alright, Andrew Morton indicated that he liked this patch but the idea needed discussion and mindshare. I asked Con Kolivas if it made sense to go in his desktop patchset for people to try: he said he liked it too but it's not his area, and that it should be discussed here.

To clarify, I'm proposing this patch for eventual mainline inclusion.

It adds a simple bit of API - a symlink in /proc/pid - which makes it easy to build relocatable software:

   ./configure --prefix=/proc/self/exedir/..

This is useful for a variety of purposes:

* Distributing programs that are runnable from CD or USB key (useful for Linux magazine cover disks)

* Binary packages that can be installed anywhere, for instance, to your home directory

* Network admins can more easily place programs on network mounts

I'm sure you can think of others. You can patch software to be relocatable today, but it's awkward and error prone. A simple patch can allow us to get it "for free" on any UNIX software that uses the idiomatic autotools build system.

Quoted 4 lines

So .... does anybody have any objections to this? Would you like to see it go in? Speak now or forever hold your peace! :)

thanks -mike

Love it. I hope it doesn't get shot down.

#2 lore raw
In reply to Mike Hearn
Quoted 18 lines · On Tuesday April 4, [email protected] wrote:

To clarify, I'm proposing this patch for eventual mainline inclusion.

It adds a simple bit of API - a symlink in /proc/pid - which makes it easy to build relocatable software:

   ./configure --prefix=/proc/self/exedir/..

This is useful for a variety of purposes:

* Distributing programs that are runnable from CD or USB key (useful for Linux magazine cover disks)

* Binary packages that can be installed anywhere, for instance, to your home directory

* Network admins can more easily place programs on network mounts

Quoted 7 lines

I'm sure you can think of others. You can patch software to be relocatable today, but it's awkward and error prone. A simple patch can allow us to get it "for free" on any UNIX software that uses the idiomatic autotools build system.

So .... does anybody have any objections to this? Would you like to see it go in? Speak now or forever hold your peace! :)

It strikes me that this is very fragile. If the application calls anything out of /bin or /usr/bin etc passing a path name which works for the application, it will break for the helper.
It also requires all binaries use by the application to live in the same directory. This would be OK for some applications, but not for everything.

It sounds to me like you want a private, inherited, name space, and Linux provides those via CLONE_NEWNS, however you probably need root access to make that work, which isn't ideal.

I think you'd have move luck (ab)using an environment variable. Make
/proc/self/env_prefix
be a symlink pointing to whatever the "PREFIX" environment variable stores.
Then you just need a little shell wrapper around the app with something like
path=readlink /proc/$$/fd/255
export PREFIX=dirname $path
exec $PREFIX/$APPLICATION

and build the application with
./configure --prefix=/proc/self/env_prefix

I'm not saying this is a "nice" solution, but I think it is no worse than /proc/self/exedir/, and it should be more robust.

NeilBrown

#3 lore raw
In reply to Mike Hearn
Quoted 5 lines

./configure --prefix=/proc/self/exedir/..

So .... does anybody have any objections to this? Would you like to see it go in? Speak now or forever hold your peace! :)

(Obligatory answer from fs/proc/base.c):
/*
* Yes, it does not scale. And it should not. Don't add
* new entries into /proc/<tgid>/ without very good reasons. */

No objections. We'll see what it can buy us, when we get the chance to use it. If it sucks, it will find its way out again. :)

Jan Engelhardt

#4 lore raw

On 4 Apr 2006, Jan Engelhardt whispered secretively:

Quoted 2 lines

No objections. We'll see what it can buy us, when we get the chance to use it. If it sucks, it will find its way out again. :)

In my experience, if it sucks, it'll be part of the ABI and can't be removed without breaking userspace code (to wit, /proc/{pid}/smaps, whose only likely widespread user has declared it too horribly-formatted to use (i.e. acahalan and procps), but it's still there...)

Stuff in /proc/{pid}/ doesn't die easily...

Signature · 3 lines
`Come now, you should know that whenever you plan the duration of your
 unplanned downtime, you should add in padding for random management
 freakouts.'
#5 lore raw
In reply to Mike Hearn
Quoted 20 lines · Mike Hearn

Alright, Andrew Morton indicated that he liked this patch but the idea needed discussion and mindshare. I asked Con Kolivas if it made sense to go in his desktop patchset for people to try: he said he liked it too but it's not his area, and that it should be discussed here.

To clarify, I'm proposing this patch for eventual mainline inclusion.

It adds a simple bit of API - a symlink in /proc/pid - which makes it easy to build relocatable software:

   ./configure --prefix=/proc/self/exedir/..

This is useful for a variety of purposes:

* Distributing programs that are runnable from CD or USB key (useful for Linux magazine cover disks)

* Binary packages that can be installed anywhere, for instance, to your home directory

Quoted 8 lines

* Network admins can more easily place programs on network mounts

I'm sure you can think of others. You can patch software to be relocatable today, but it's awkward and error prone. A simple patch can allow us to get it "for free" on any UNIX software that uses the idiomatic autotools build system.

So .... does anybody have any objections to this? Would you like to see it go in? Speak now or forever hold your peace! :)

You patch needs to move proc_exedir_link into base.c instead of replicating it twice (that is a maintenance problem).

I think if we can fix namespaces you don't have to be root to use them that is a superioir approach, and will cover more cases.

I have concerns about security policy in this case because a proc symlink is not a symlink. So if you chmod an intermediate directory in your prefix to 000 you will still be able to access it.

I'm not at all certain I like applications depending on the fact that I have procfs mounted on /proc. It's bad enough that system
libraries are beginning to care. This means I can not run any of
your relocatable executalbes in a chroot environment unless I mount proc.

If we add this it will never be removed from /proc, so we should be certain we want this.

Given how long we have been without this I doubt many people actually care, or their software would be written so it was relocatable from day one.

I'm not certain the directory of an inode even makes sense, and that is what you are asking for us to export.

Eric

author
#6 lore raw
Quoted 2 lines

I think if we can fix namespaces you don't have to be root to use them that is a superioir approach, and will cover more cases.

That would be nice. I assumed they needed root for security reasons rather than architectural reasons.

Quoted 1 line

I have concerns about security policy ...

I'm not sure I understand. Only if you run that program, and if you don't have access to the intermediate directory, how do you run it?

Quoted 2 lines

This means I can not run any of your relocatable executalbes in a chroot environment unless I mount proc.

Why is mounting proc a bad thing? I have never seen a Linux distro that does not provide proc and many desktop-level things depend on it.

Quoted 2 lines

Given how long we have been without this I doubt many people actually care

You could argue the same for any new feature. Writing relocatable software on UNIX is absolutely standard, except it's done at source compile time not runtime. That fits with the traditional UNIX culture of compiling software to install it, but the times they are a changin :)

Quoted 2 lines

I'm not certain the directory of an inode even makes sense, and that is what you are asking for us to export.

How so? The code does work, though I guess you could devise a scenario in which there is a running executable that is not attached to any directory.

thanks -mike

#7 lore raw
Quoted 4 lines
Quoted 1 line

I have concerns about security policy ...

I'm not sure I understand. Only if you run that program, and if you don't have access to the intermediate directory, how do you run it?

It leaks information about the parts of the pathname below the directory that you otherwise would not be able to see. E.g. if I have $HOME/top-secret-projects/secret-code-name1/binary where the top-secret-projects directory isn't readable by you, then you may find out secret-code-name1 by reading the /proc/{pid}/exedir symlink.

-Tony

#8 lore raw
Quoted 11 lines · On Thursday April 6, [email protected] wrote:
Quoted 4 lines
Quoted 1 line

I have concerns about security policy ...

I'm not sure I understand. Only if you run that program, and if you don't have access to the intermediate directory, how do you run it?

It leaks information about the parts of the pathname below the directory that you otherwise would not be able to see. E.g. if I have $HOME/top-secret-projects/secret-code-name1/binary where the top-secret-projects directory isn't readable by you, then you may find out secret-code-name1 by reading the /proc/{pid}/exedir symlink.

But we already have /proc/{pid}/exe which is a symlink to the executable, thus exposing all the directory names already.

NeilBrown

#9 lore raw
Quoted 13 lines · Neil Brown
Quoted 11 lines · On Thursday April 6, [email protected] wrote:
Quoted 4 lines
Quoted 1 line

I have concerns about security policy ...

I'm not sure I understand. Only if you run that program, and if you don't have access to the intermediate directory, how do you run it?

It leaks information about the parts of the pathname below the directory that you otherwise would not be able to see. E.g. if I have $HOME/top-secret-projects/secret-code-name1/binary where the top-secret-projects directory isn't readable by you, then you may find out secret-code-name1 by reading the /proc/{pid}/exedir symlink.

Quoted 2 lines

But we already have /proc/{pid}/exe which is a symlink to the executable, thus exposing all the directory names already.

Neither of which should be readable by anyone but the owner of the process, which is the one who was able to read the secret directory in the first place.

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#10 lore raw
Quoted 15 lines · Andreas Schwab
Quoted 13 lines · Neil Brown
Quoted 11 lines · On Thursday April 6, [email protected] wrote:
Quoted 4 lines
Quoted 1 line

I have concerns about security policy ...

I'm not sure I understand. Only if you run that program, and if you don't have access to the intermediate directory, how do you run it?

It leaks information about the parts of the pathname below the directory that you otherwise would not be able to see. E.g. if I have $HOME/top-secret-projects/secret-code-name1/binary where the top-secret-projects directory isn't readable by you, then you may find out secret-code-name1 by reading the /proc/{pid}/exedir symlink.

Quoted 6 lines
Quoted 2 lines

But we already have /proc/{pid}/exe which is a symlink to the executable, thus exposing all the directory names already.

Neither of which should be readable by anyone but the owner of the process, which is the one who was able to read the secret directory in the first place.

In most cases. It is possible you got the executable through file descriptor passing and the like.

The security check in -mm allows anyone who may ptrace the process to have read access. In 2.6.17-rc1 the check is still the owner of the process and anyone with CAP_DAC_ACCESS may read or use the link.

Eric

#11 lore raw
In reply to Andreas Schwab
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

It leaks information about the parts of the pathname below the directory that you otherwise would not be able to see. E.g. if I have $HOME/top-secret-projects/secret-code-name1/binary where the top-secret-projects directory isn't readable by you, then you may find out secret-code-name1 by reading the /proc/{pid}/exedir symlink.

But we already have /proc/{pid}/exe which is a symlink to the executable, thus exposing all the directory names already.

In which case the administrator of the machine should make /proc/xyz directories mode 0700. (Patches are floating around.)

Jan Engelhardt