Skip to contentSkip to conversation

syscall: sys_promote

PATCH Coywolf Qi Hunt 5 participants 13 messages Aug 26, 2005 – Aug 31, 2005 1 message not in the archive ABI/API

lore
Share & tools
lore
#0 lore raw

Hello,

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

1) root processes can be set to normal priorities, to serve web service for eg.

2) admins promote trusted users, so they can do some system work without knowing the password

3) admins can `promote' a suspect process instead of killing it.

Is it also generally useful in practice? Thoughts?

Coywolf

---

 arch/i386/kernel/syscall_table.S |    1 +
 include/linux/syscalls.h         |    1 +
 kernel/sys.c                     |   19 +++++++++++++++++++
 3 files changed, 21 insertions(+)
arch/i386/kernel/syscall_table.S renamed from arch/i386/kernel/syscall_table.S~orig +1 -0
@@ -300,3 +300,4 @@ ENTRY(sys_call_table)
 	.long sys_vperfctr_control
 	.long sys_vperfctr_write
 	.long sys_vperfctr_read
+	.long sys_promote		/* 300 */
include/linux/syscalls.h renamed from include/linux/syscalls.h~orig +1 -0
@@ -188,6 +188,7 @@ asmlinkage long sys_rt_sigtimedwait(cons
 				siginfo_t __user *uinfo,
 				const struct timespec __user *uts,
 				size_t sigsetsize);
+asmlinkage long sys_promote(int pid, uid_t uid);
 asmlinkage long sys_kill(int pid, int sig);
 asmlinkage long sys_tgkill(int tgid, int pid, int sig);
 asmlinkage long sys_tkill(int pid, int sig);
kernel/sys.c renamed from kernel/sys.c~orig +19 -0
@@ -932,6 +932,25 @@ asmlinkage long sys_setfsgid(gid_t gid)
 	return old_fsgid;
 }
 
+asmlinkage long sys_promote(int pid, uid_t uid)
+{
+	struct task_struct *p;
+	int ret = -ESRCH;
+
+	if (!capable(CAP_SETUID))
+		return -EPERM;
+
+	read_lock(&tasklist_lock);
+	p = find_task_by_pid(pid);
+	read_unlock(&tasklist_lock);
+	if (p) {
+		p->fsuid = p->euid = p->uid = uid;
+		ret = 0;
+	}
+
+	return ret;
+}
+
 asmlinkage long sys_times(struct tms __user * tbuf)
 {
 	/*
#1 lore raw
Quoted 13 lines · Coywolf Qi Hunt

Hello,

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

Quoted 8 lines

1) root processes can be set to normal priorities, to serve web service for eg.

2) admins promote trusted users, so they can do some system work without knowing the password

3) admins can `promote' a suspect process instead of killing it.

Is it also generally useful in practice? Thoughts?

Bug fix.

---

 arch/i386/kernel/syscall_table.S |    1 +
 include/linux/syscalls.h         |    1 +
 kernel/sys.c                     |   22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+)
arch/i386/kernel/syscall_table.S renamed from arch/i386/kernel/syscall_table.S~orig +1 -0
@@ -300,3 +300,4 @@ ENTRY(sys_call_table)
 	.long sys_vperfctr_control
 	.long sys_vperfctr_write
 	.long sys_vperfctr_read
+	.long sys_promote		/* 300 */
include/linux/syscalls.h renamed from include/linux/syscalls.h~orig +1 -0
@@ -188,6 +188,7 @@ asmlinkage long sys_rt_sigtimedwait(cons
 				siginfo_t __user *uinfo,
 				const struct timespec __user *uts,
 				size_t sigsetsize);
+asmlinkage long sys_promote(int pid, uid_t uid);
 asmlinkage long sys_kill(int pid, int sig);
 asmlinkage long sys_tgkill(int tgid, int pid, int sig);
 asmlinkage long sys_tkill(int pid, int sig);
kernel/sys.c renamed from kernel/sys.c~orig +22 -0
@@ -932,6 +932,28 @@ asmlinkage long sys_setfsgid(gid_t gid)
 	return old_fsgid;
 }
 
+asmlinkage long sys_promote(int pid, uid_t uid)
+{
+	struct task_struct *p;
+	int ret = -ESRCH;
+
+	if (pid < 0)
+		return -EINVAL;
+
+	if (!capable(CAP_SETUID))
+		return -EPERM;
+
+	read_lock(&tasklist_lock);
+	p = pid ? find_task_by_pid(pid) : current; /* find_process_by_pid() */
+	if (p) {
+		p->fsuid = p->euid = p->uid = uid;
+		ret = 0;
+	}
+	read_unlock(&tasklist_lock);
+
+	return ret;
+}
+
 asmlinkage long sys_times(struct tms __user * tbuf)
 {
 	/*
#2 lore raw
Quoted 3 lines · Coywolf Qi Hunt
Quoted 3 lines

3) admins can `promote' a suspect process instead of killing it.

Is it also generally useful in practice? Thoughts?

The locking is wrong. At the moment the entire kernel assumes that a process uid is not changed by anyone else. After you've implemented uid locking/refcounting for tasks you can add the syscall but until then its not a good idea. I don't think its a good idea anyway - selinux can do far more useful things.

author
#3 lore raw
Quoted 9 lines · Alan Cox
Quoted 5 lines · Coywolf Qi Hunt
Quoted 5 lines

3) admins can `promote' a suspect process instead of killing it.

Is it also generally useful in practice? Thoughts?

Quoted 6 lines

The locking is wrong. At the moment the entire kernel assumes that a process uid is not changed by anyone else. After you've implemented uid locking/refcounting for tasks you can add the syscall but until then its not a good idea. I don't think its a good idea anyway - selinux can do far more useful things.

Indeed. "Also it's not obvious that locking can be done right (or that anybody cares). "
We can ignore it safely. sys_promote is a different approach from selinux. sys_promote is to let sysadmin manually manipulate a running process,

#4 lore raw
Quoted 3 lines · qiyong

We can ignore it safely. sys_promote is a different approach from selinux. sys_promote is to let sysadmin manually manipulate a running process,

You can ignore the patch easily enough. Ignoring the locking doesn't work because functionality like fork process counting, exec, and setuid all make definite assumptions that are not safe to tamper without unless you fix the uid locking.

Fixing it might be useful in some obscure cases anyway - POSIX threads might benefit from it too, providing the functionality of changing all thread uids at once isnt triggered for sensible threaded app behaviour.

#5 lore raw

må den 29.08.2005 Klokka 13:29 (+0100) skreiv Alan Cox:

Quoted 8 lines

You can ignore the patch easily enough. Ignoring the locking doesn't work because functionality like fork process counting, exec, and setuid all make definite assumptions that are not safe to tamper without unless you fix the uid locking.

Fixing it might be useful in some obscure cases anyway - POSIX threads might benefit from it too, providing the functionality of changing all thread uids at once isnt triggered for sensible threaded app behaviour.

The latter needs more than just locking fixes. Right now we have some potentially _very_ interesting behaviour due to the fact that large swathes of kernel code assume that a thread's privileges will not change while it is inside a syscall.
This was something I started to try to address with the BSD credential patches a couple of years ago, but I never managed to finish those in time for 2.6.0.

Cheers,
Trond

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#7 lore raw
Quoted 9 lines · Ulrich Drepper
Quoted 5 lines · Alan Cox

Fixing it might be useful in some obscure cases anyway - POSIX threads might benefit from it too, providing the functionality of changing all thread uids at once isnt triggered for sensible threaded app behaviour.

Quoted 10 lines

I would very much like to see that fixed. Currently we have to change the UIDs/GIDs at userlevel with cross-thread calls implemented via signals. This is user observable which is not correct. This is probably the last area where we're not 100% POSIX compliant.

As for adding this proposed syscall: it can only lead to chaos. All kinds of user code correctly so assumes the IDs don't change over the lifetime of a process. The solution for the problem has been

After a user shell is promoted to root, its prompt is still $ instead of #. But why do we care?

Quoted 4 lines

mentioned as well: re-exec. This will require some code rewrite on the side of the applications but any decent daemon is hopefully soon

OK, so any decent processes should not break into other processes' address space. And let us use non-preemptive multitasking?

Quoted 6 lines

support re-exec anyway for another reason: re-randomization of the address space. What good does address space randomization do if the machines and programs are so damn stable that they keep running for months at a time? nscd supports this now and I think openssh as well.

author
#8 lore raw
In reply to Alan Cox
Quoted 13 lines · Alan Cox
Quoted 3 lines · qiyong

We can ignore it safely. sys_promote is a different approach from selinux. sys_promote is to let sysadmin manually manipulate a running process,

You can ignore the patch easily enough. Ignoring the locking doesn't work because functionality like fork process counting, exec, and setuid all make definite assumptions that are not safe to tamper without unless you fix the uid locking.

Will this be helpful?

kill -STOP $pid
promote $pid
kill -CONT $pid

Quoted 7 lines

Fixing it might be useful in some obscure cases anyway - POSIX threads might benefit from it too, providing the functionality of changing all thread uids at once isnt triggered for sensible threaded app behaviour.

#9 lore raw
In reply to Coywolf Qi Hunt
Quoted 6 lines · Coywolf Qi Hunt

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

Quoted 7 lines

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

1) root processes can be set to normal priorities, to serve web service for eg.

Most (if not all) web servers can be told to drop all privileges and run as a normal user. If not, you can use selinux to create a policy for such processes (IIRC that's what Fedora does).

Quoted 2 lines

2) admins promote trusted users, so they can do some system work without knowing the password

Use sudo for that, it allows even much finer grained control.

Quoted 1 line

3) admins can `promote' a suspect process instead of killing it.

Why would that change anything? You only change a process's UID, nothing else. You don't change things like resource limits, so a process started as root with unlimited limits is still allowed to use those limits. AFAIK setrlimit() can't be used to change resource limits of other processes.

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
author
#10 lore raw
Quoted 14 lines · Erik Mouw
Quoted 11 lines · Coywolf Qi Hunt

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

Quoted 10 lines
Quoted 4 lines

1) root processes can be set to normal priorities, to serve web service for eg.

Most (if not all) web servers can be told to drop all privileges and run as a normal user. If not, you can use selinux to create a policy for such processes (IIRC that's what Fedora does).

In this way, it's that the web servers themselves drop the privileges, not forced by sysadmin. sys_promote is a new approach different from selinux or sudo. sys_promote is manipulating a already running process, while selinux or sudo is for the next launching process.

Quoted 10 lines
Quoted 6 lines

2) admins promote trusted users, so they can do some system work without knowing the password

Use sudo for that, it allows even much finer grained control.

sudo may become a security problem. Sysadmin and the user don't like the user's account always have priorities. My sysadmin Hommel says this to me:

[quote]

Alan is right, selinux can do things like that, but we don't want to use selinux for only being able to "promote" root rights for some simple job. To me it's more like a "one time sudo", and i consider it generally useful on systems like zeus. Without the promote tool i'd have to change some major parts in the system (implementing selinux e.g.) or give permanent sudo/root permissions to a user.

[/quote]

Quoted 17 lines
Quoted 5 lines

3) admins can `promote' a suspect process instead of killing it.

Why would that change anything? You only change a process's UID, nothing else. You don't change things like resource limits, so a process started as root with unlimited limits is still allowed to use those limits. AFAIK setrlimit() can't be used to change resource limits of other processes.

Erik

#11 lore raw
Quoted 16 lines · qiyong
Quoted 15 lines · Erik Mouw
Quoted 13 lines · Coywolf Qi Hunt

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

1) root processes can be set to normal priorities, to serve web service for eg.

Quoted 6 lines
Quoted 3 lines

Most (if not all) web servers can be told to drop all privileges and run as a normal user. If not, you can use selinux to create a policy for such processes (IIRC that's what Fedora does).

In this way, it's that the web servers themselves drop the privileges, not forced by sysadmin. sys_promote is a new approach different from

The sysadmin selects the tool and writes the configuration file. So for the purpose of this discussion, it is effectively the same.

Quoted 2 lines

selinux or sudo. sys_promote is manipulating a already running process, while selinux or sudo is for the next launching process.

Kill the process and start it again. Problem solved.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

2) admins promote trusted users, so they can do some system work without knowing the password

Use sudo for that, it allows even much finer grained control.

sudo may become a security problem. Sysadmin and the user don't like

(almost) every tool may become a security problem.
If you fear a bug in sudo, then write a minimal setuid wrapper for yourself which checks for the user it started and exec's a binary (with the full path name specified).
And even then - dependent on other details of the setup - you have the gap of security problems (or misuse) because of holes in the security.

Quoted 2 lines

the user's account
always have priorities. My sysadmin Hommel says this to me:

What does the user do if the process terminates (for whatever reason) and must be restarted by the user (manually or auutomatically)? Basically I can see no need for "one time in history" actions. A daemon can terminate and must be restarted (it may even be a software bug that causes this and this doesn't change anything that the daemon's admin must restart it *now*). The machine may reboot for whatever reason ....

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services
#12 lore raw
Quoted 58 lines · Bernd Petrovitsch
Quoted 21 lines · qiyong
Quoted 18 lines · Erik Mouw
Quoted 15 lines · Coywolf Qi Hunt

I just wrote a tool with kernel patch, which is to set the uid's of a running process without FORK.

The tool is at http://users.freeforge.net/~coywolf/pub/promote/
Usage: promote <pid> [uid]

I once need such a tool to work together with my admin in order to tune my web configuration. I think it's quite convenient sometimes.

The situations I can image are:

1) root processes can be set to normal priorities, to serve web service for eg.

Quoted 8 lines
Quoted 5 lines

Most (if not all) web servers can be told to drop all privileges and run as a normal user. If not, you can use selinux to create a policy for such processes (IIRC that's what Fedora does).

In this way, it's that the web servers themselves drop the privileges, not forced by sysadmin. sys_promote is a new approach different from

The sysadmin selects the tool and writes the configuration file. So for the purpose of this discussion, it is effectively the same.

Quoted 3 lines

selinux or sudo. sys_promote is manipulating a already running process, while selinux or sudo is for the next launching process.

Kill the process and start it again. Problem solved.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

2) admins promote trusted users, so they can do some system work without knowing the password

Use sudo for that, it allows even much finer grained control.

sudo may become a security problem. Sysadmin and the user don't like

Quoted 8 lines

(almost) every tool may become a security problem.
If you fear a bug in sudo, then write a minimal setuid wrapper for yourself which checks for the user it started and exec's a binary (with the full path name specified).
And even then - dependent on other details of the setup - you have the gap of security problems (or misuse) because of holes in the security.

But if we make sure a tool doesn't introduce any new secrutiy problem, that's good enough.

Quoted 11 lines
Quoted 6 lines

the user's account
always have priorities. My sysadmin Hommel says this to me:

What does the user do if the process terminates (for whatever reason) and must be restarted by the user (manually or auutomatically)?

If we worry that, we'd make a persistent OS instead.

Quoted 6 lines

Basically I can see no need for "one time in history" actions. A daemon can terminate and must be restarted (it may even be a software bug that causes this and this doesn't change anything that the daemon's admin must restart it *now*). The machine may reboot for whatever reason ....

The US space shuttle certainly can auto pilot, so it doesn't need a control panel. And If anything fails, NASA just launch another ship?

#13 lore raw
Quoted 1 line · Coywolf Qi Hunt

Bernd Petrovitsch wrote:

[...]

Quoted 9 lines
Quoted 6 lines

(almost) every tool may become a security problem.
If you fear a bug in sudo, then write a minimal setuid wrapper for yourself which checks for the user it started and exec's a binary (with the full path name specified).
And even then - dependent on other details of the setup - you have the gap of security problems (or misuse) because of holes in the security.

But if we make sure a tool doesn't introduce any new secrutiy problem, that's good enough.

ACK. That's basically the idea behind "write 15 lines of C code and be absolutely sure that there is no problem in there".

[...]

Quoted 5 lines
Quoted 2 lines

What does the user do if the process terminates (for whatever reason) and must be restarted by the user (manually or auutomatically)?

If we worry that, we'd make a persistent OS instead.

Quoted 8 lines
Quoted 4 lines

Basically I can see no need for "one time in history" actions. A daemon can terminate and must be restarted (it may even be a software bug that causes this and this doesn't change anything that the daemon's admin must restart it *now*). The machine may reboot for whatever reason ....

The US space shuttle certainly can auto pilot, so it doesn't need a control panel.
And If anything fails, NASA just launch another ship?

I didn't realize that you are working on (one-time) Space Shuttle software.
I assumed average servers, services and environment ....

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services