Daemon, UID, EUID issues

Daemon, UID, EUID issues

Post by Mathieu DESPRIE » Thu, 29 Nov 2001 23:22:21



Hi,

I'm developping a deamon, that will be listening to TCP/IP connections.
It's constituted of several processes :
1- One process, sleeping, and forking into the server in case of
inexpected termination of it
2- The server itself, that listens to the TCP/IP socket
3- Many children talking with clients.

My question is : Should I setuid(), or seteuid() ?

If yes, what is the good moment to do this ? (in server process, just
before opening the socket I suppose ?)

Thanks in advance,

Mathieu D.

 
 
 

Daemon, UID, EUID issues

Post by Jim Patterso » Fri, 30 Nov 2001 13:06:14



> I'm developping a deamon, that will be listening to TCP/IP connections.
> It's constituted of several processes :
> 1- One process, sleeping, and forking into the server in case of
> inexpected termination of it
> 2- The server itself, that listens to the TCP/IP socket
> 3- Many children talking with clients.

> My question is : Should I setuid(), or seteuid() ?

First, do you need to run as root at all? If you can run as a non-root
user, that is an easier alternative.

The main reasons you might need to run as root are:
- you need to listen on a privileged port (port < 1024).
- you need to access files that have arbitrary ownerships e.g. user's
home directories

No doubt there are others, but if you aren't doing any of those things,
then just have the system startup script spawn your daemon under the
user ID that you want to use. That way you won't have to worry about
when to use setuid.

Quote:> If yes, what is the good moment to do this ? (in server process, just
> before opening the socket I suppose ?)

Actually, it's likely just after binding the socket if you use a
privileged socket. I'm assuming that your daemon starts up as root, so
you 'setuid' to your daemon user ID (and then back to root as
necessary). From that point on, you should run setuid to your daemon's
UID whenever possible.

----
Jim Patterson
Ottawa, Ont
CANADA

 
 
 

Daemon, UID, EUID issues

Post by TimC » Fri, 30 Nov 2001 13:55:56


Jim Patterson (aka Bruce) was almost, but not quite, entirely unlike tea:

Quote:> Actually, it's likely just after binding the socket if you use a
> privileged socket. I'm assuming that your daemon starts up as root, so
> you 'setuid' to your daemon user ID (and then back to root as
> necessary). From that point on, you should run setuid to your daemon's
> UID whenever possible.

I've always wondered what good this does. Say you have a buffer
overflow in a program that long ago dropped its privelages. And you
are using the POSIX setuid functions. Can't the buffer overflow be
exploited to first call setuid() to regain those privelages, then do
the rooty stuff?

Of couse, I am probably missing something entirely too obvious here.

--
TimC -- http://www.physics.usyd.edu.au/~tcon/

I'm sorry, but all questions must be in the form of a question.
-- pieceoftheuniverse

 
 
 

Daemon, UID, EUID issues

Post by Kasper Dupon » Fri, 30 Nov 2001 16:16:46



> Jim Patterson (aka Bruce) was almost, but not quite, entirely unlike tea:
> > Actually, it's likely just after binding the socket if you use a
> > privileged socket. I'm assuming that your daemon starts up as root, so
> > you 'setuid' to your daemon user ID (and then back to root as
> > necessary). From that point on, you should run setuid to your daemon's
> > UID whenever possible.

> I've always wondered what good this does. Say you have a buffer
> overflow in a program that long ago dropped its privelages. And you
> are using the POSIX setuid functions. Can't the buffer overflow be
> exploited to first call setuid() to regain those privelages, then do
> the rooty stuff?

> Of couse, I am probably missing something entirely too obvious here.

If the effective userid is 0 the setuid() function will set
all uid's, so there is no way to regain priveleges.

--
Kasper Dupont

 
 
 

1. [Fwd: Daemon, UID, EUID issues]

[ Attached Message ]

From:
To:
Date: Mon, 26 Nov 2001 11:37:12 +0000
Local: Mon, Nov 26 2001 6:37 am
Subject: Daemon, UID, EUID issues

Hi,

I'm developping a deamon, that will be listening to TCP/IP connections.
It's constituted of several processes :
1- One process, sleeping, and forking into the server in case of
inexpected termination of it
2- The server itself, that listens to the TCP/IP socket
3- Many children talking with clients.

My question is : Should I setuid(), or seteuid() ?

If yes, what is the good moment to do this ? (in server process, just
before opening the socket I suppose ?)

Thanks in advance,

Mathieu D.

2. Dump/Restore

3. Daemon, UID, EUID issues

4. rdump from linux to a tape device on a sun

5. How to find uid, gid, euid etc on a running process ?

6. srm.conf file and allowing cgi programs to run

7. Checking a PID's existance reguardless of uid/euid

8. SAMBA and NT Domains

9. Q:Can kernel/module code know uid+euid of calling process?

10. suidperl:Can't reswap uid and euid.

11. Question about UID and EUID and SUID attribute standards in UNIX

12. Failed to run chown when euid and uid is not the same

13. EUID (vs) UID in a suid to root C program