Skip to contentSkip to conversation

se-samba - a possible way to get round no seteuid

DISCUSSION Luke Kenneth Casson Leighton 2 participants 5 messages Jun 9, 2004 – Jun 11, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

i'm just investigating exim4 to put in some hacks to make it possible to transition between different executables.

exim4 does a lot of execve'ing about, but it's always to the same executable name (i.e. /usr/sbin/exim4).

russell's idea is to make exim4 execve to different executable names, and then a different context can be associated with each purpose.

then, a set of capabilities can be associated with each executable, which will of course do a straight execve to /usr/sbin/exim4 - taking the new context with it.

it occurred to me that a similar approach could be taken with samba.

instead of doing a seteuid back to root, you do an execve to an executable named samba-root.

or, in the main loop, you do an execve() to an executable named smbd-child, and then do a setuid, and when you're done, you do an execve back to smbd.

it's a hell of a lot simpler approach than messing about with proxying and a darn site simpler than doing a rewrite of samba to do user-space checking.

and you could potentially just leave this approach compiled in by default, and, like with exim4, just symbolic link /usr/sbin/smbd-child to /usr/sbin/smbd for non-selinux systems.

l.

Signature · 15 lines
-- 
expecting email to be received and understood is a bit like
picking up the telephone and immediately dialing without
checking for a dial-tone; speaking immediately without listening
for either an answer or ring-tone; hanging up immediately and
believing that you have actually started a conversation.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 8 lines · Luke Kenneth Casson Leighton

then, a set of capabilities can be associated with each executable, which will of course do a straight execve to /usr/sbin/exim4 - taking the new context with it.

it occurred to me that a similar approach could be taken with samba.

instead of doing a seteuid back to root, you do an execve to an executable named samba-root.

That doesn't work. There are more possible UIDs than the root file system may have Inodes...

We just need to have Samba know about SE Linux and tell the kernel what context it wants the child process to use.

Quoted 3 lines

or, in the main loop, you do an execve() to an executable named smbd-child, and then do a setuid, and when you're done, you do an execve back to smbd.

execve back to smbd is a bad idea. I believe that samba already has code to setuid() and then exit when finished with that UID, we should plan for the same design. Letting smbd go back to the main context provides no real benefit but a lot of work in serialisation.

Quoted 3 lines

it's a hell of a lot simpler approach than messing about with proxying and a darn site simpler than doing a rewrite of samba to do user-space checking.

This still doesn't cover the case of a single TCP connection having more than one identity...

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 5 lines · Russell Coker
Quoted 4 lines · Luke Kenneth Casson Leighton

then, a set of capabilities can be associated with each executable, which will of course do a straight execve to /usr/sbin/exim4 - taking the new context with it.

Quoted 7 lines
Quoted 4 lines

it occurred to me that a similar approach could be taken with samba.

instead of doing a seteuid back to root, you do an execve to an executable named samba-root.

That doesn't work. There are more possible UIDs than the root file system may have Inodes...

? i am confused. by execve'ing back to a context, shall we call it smbd_as_root_t, what connection does that have to UIDs?

Quoted 11 lines

We just need to have Samba know about SE Linux and tell the kernel what context it wants the child process to use.

Quoted 3 lines

or, in the main loop, you do an execve() to an executable named smbd-child, and then do a setuid, and when you're done, you do an execve back to smbd.

execve back to smbd is a bad idea. I believe that samba already has code to setuid() and then exit when finished with that UID, we should plan for the same design.

ah, remember that you can have several UIDs over the same TCP connection (and multiple SMBsessionsetupX's to represent each and you get these SMB-MIDs - multiplexing ids - to represent each SMB session over the same TCP session),

and at present, a single smbd process does a seteuid to that UID, and then back to root, and then seteuid to the other UID, and back to root, etc. etc.

only when the last SMBsessionsetupX has been matched with its SMBlogoff can you drop the connection [except if the SMBlogoff is with an SMB-MID of zero which is a special case job which says "drop the lot, we're off!"]

i thought that instead of having the seteuid and back to root, you could execve back to the "smbd_as_root_t context".

so you have three contexts:

- smbd_the_daemon (waiting for connections)

... which transitions on a fork to...

- smbd_as_root_t (dealing with "connections")

... which can transition to ...

- smbd_as_user_t (passing over the tcp socket filedescriptor?)

... which can transition to ...

- smbd_as_root_t (for it to deal with a different uid)

does that sound workable to you?

Quoted 2 lines

Letting smbd go back to the main context provides no real benefit but a lot of work in serialisation.

oh? oh. oh well :)

just a thought.

l.

Signature · 14 lines
-- 
Information I post is with honesty, integrity, and the expectation that
you will take full responsibility for acting on the information contained,
and that, should you find it to be flawed or even mildly useful, you
will act with both honesty and integrity in return - and tell me.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 8 lines · Luke Kenneth Casson Leighton
Quoted 5 lines
Quoted 2 lines

instead of doing a seteuid back to root, you do an execve to an executable named samba-root.

That doesn't work. There are more possible UIDs than the root file system may have Inodes...

? i am confused. by execve'ing back to a context, shall we call it smbd_as_root_t, what connection does that have to UIDs?

The idea for Exim is that you have a set of wrapper binaries already there on disk. If a particular installation of Exim doesn't use one of the ~6 wrappers that are installed then it's only a waste of 4K of disk space.

If we do the same mechanism for each UID then we have many more executables, or we have to allow the daemon to create new executables which also adds more coding.

Quoted 4 lines

ah, remember that you can have several UIDs over the same TCP connection (and multiple SMBsessionsetupX's to represent each and you get these SMB-MIDs - multiplexing ids - to represent each SMB session over the same TCP session),

[...]

Quoted 2 lines

i thought that instead of having the seteuid and back to root, you could execve back to the "smbd_as_root_t context".

True, but re-execing requires serialising all the data to a file, shared memory region, or something else that will survive past an exec. That's pain that we don't want to go through any more often than is necessary.

Quoted 7 lines

- smbd_the_daemon (waiting for connections)

... which transitions on a fork to...

- smbd_as_root_t (dealing with "connections")

... which can transition to ...

How about just smbd_the_daemon which can transition to smbd_as_a_user?

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
Quoted 7 lines · Russell Coker
Quoted 6 lines · Luke Kenneth Casson Leighton
Quoted 5 lines
Quoted 2 lines

instead of doing a seteuid back to root, you do an execve to an executable named samba-root.

That doesn't work. There are more possible UIDs than the root file system may have Inodes...

Quoted 8 lines
Quoted 2 lines

? i am confused. by execve'ing back to a context, shall we call it smbd_as_root_t, what connection does that have to UIDs?

The idea for Exim is that you have a set of wrapper binaries already there on disk. If a particular installation of Exim doesn't use one of the ~6 wrappers that are installed then it's only a waste of 4K of disk space.

If we do the same mechanism for each UID then we have many more executables,

nono, i definitely didn't mean to suggest to have executables per UID.

Quoted 8 lines

or we have to allow the daemon to create new executables which also adds more coding.

Quoted 4 lines

ah, remember that you can have several UIDs over the same TCP connection (and multiple SMBsessionsetupX's to represent each and you get these SMB-MIDs - multiplexing ids - to represent each SMB session over the same TCP session),

Quoted 7 lines

[...]

Quoted 2 lines

i thought that instead of having the seteuid and back to root, you could execve back to the "smbd_as_root_t context".

True, but re-execing requires serialising all the data to a file, shared memory region, or something else that will survive past an exec.

in samba, locks are already in shared memory because of the way that SMB file locking has to be done (e.g. global "opportunistic locks" whic are more of a write-cache plus notification of other people wanting write access to the same file thing)

iirc correctly, the only things that need to be passed over are the open file handles.

Quoted 1 line

How about just smbd_the_daemon which can transition to smbd_as_a_user?

fine for non-multi-connection stuff.

l.

Quoted 5 lines
Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
Signature · 14 lines
-- 
Information I post is with honesty, integrity, and the expectation that
you will take full responsibility for acting on the information contained,
and that, should you find it to be flawed or even mildly useful, you
will act with both honesty and integrity in return - and tell me.
--
<a href="http://lkcl.net">      lkcl.net      </a> <br />
<a href="mailto:[email protected]"> [email protected] </a> <br />


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.