Skip to contentSkip to conversation

Question about chsh/chfn/passwd patches

DISCUSSION Thorsten Kukuk 2 participants 8 messages Oct 15, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,

I have a question about the passwd/chfn/chsh patches.

passwd only calls checkAccess. chfn/chsh additional calls setupDefaultContext.

I don't understand what the last function makes. For what is it good, and why don't we need to call it from passwd?

Thanks,
Thorsten

Signature · 9 lines
Thorsten Kukuk       http://www.suse.de/~kukuk/        [email protected]
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

--
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 7 lines · Thorsten Kukuk

I have a question about the passwd/chfn/chsh patches.

passwd only calls checkAccess. chfn/chsh additional calls setupDefaultContext.

I don't understand what the last function makes. For what is it good, and why don't we need to call it from passwd?

IIRC, for the RH passwd program, this is handled by the libuser patch. The call is necessary to preserve the security attributes on /etc/passwd and /etc/shadow when they are rewritten for updates.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
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 6 lines · Stephen Smalley
Quoted 5 lines · Thorsten Kukuk

I have a question about the passwd/chfn/chsh patches.

passwd only calls checkAccess. chfn/chsh additional calls setupDefaultContext.

Quoted 6 lines
Quoted 2 lines

I don't understand what the last function makes. For what is it good, and why don't we need to call it from passwd?

IIRC, for the RH passwd program, this is handled by the libuser patch. The call is necessary to preserve the security attributes on /etc/passwd and /etc/shadow when they are rewritten for updates.

Ok, since I copy always all attributes if I modify /etc/passwd and /etc/shadow (to make sure to preserve ACLs and security attributes), I don't need it.

Thanks,
Thorsten

Signature · 9 lines
Thorsten Kukuk       http://www.suse.de/~kukuk/        [email protected]
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

--
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 3 lines · Thorsten Kukuk

Ok, since I copy always all attributes if I modify /etc/passwd and /etc/shadow (to make sure to preserve ACLs and security attributes), I don't need it.

The problem with simply preserving attributes via setxattr is that you cannot create the new file immediately with the desired attributes, so there is a window where the new file exists with the default attribute value, typically inherited from the parent directory. Note that this is particularly a concern for /etc/passwd and /etc/shadow, since they live in the same parent directory but have differing protection requirements.

The SELinux setfscreatecon() interface (implemented via the /proc/pid/attr/fscreate API) allows a process to set the desired security context for subsequent file creations, similar to the umask. You'll notice that many of the SELinux patches use this interface to set the desired context prior to creating the new file, so that files are immediately created with the right context and are protected accordingly. This is one of the reasons we don't just use the EA patch for coreutils and instead have our own.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
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 11 lines · Stephen Smalley
Quoted 3 lines · Thorsten Kukuk

Ok, since I copy always all attributes if I modify /etc/passwd and /etc/shadow (to make sure to preserve ACLs and security attributes), I don't need it.

The problem with simply preserving attributes via setxattr is that you cannot create the new file immediately with the desired attributes, so there is a window where the new file exists with the default attribute value, typically inherited from the parent directory. Note that this is particularly a concern for /etc/passwd and /etc/shadow, since they live in the same parent directory but have differing protection requirements.

Ok, I think it is trivial to do a getfscreatecon, call setfscreatecon with the permissions of the passwd file and restore the original fscreate values afterwards.

But it would be interesting to know how somebody could be able to do something forbidden with the following:

Create temporary file with mkstemp, mode 0600, owner root:root. Copy EA attributes.

Thorsten

Signature · 9 lines
Thorsten Kukuk       http://www.suse.de/~kukuk/        [email protected]
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

--
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.
#5 lore raw
Quoted 3 lines · Thorsten Kukuk

Ok, I think it is trivial to do a getfscreatecon, call setfscreatecon with the permissions of the passwd file and restore the original fscreate values afterwards.

Actually, this would be getfilecon() and then setfscreatecon(). getfilecon (which simply is a wrapper around getxattr that encapsulates the attribute name for SELinux and provides automatic allocation of the buffer) gets the context of a specified file, whereas getfscreatecon() gets the fscreate context of the current process.

Quoted 5 lines

But it would be interesting to know how somebody could be able to do something forbidden with the following:

Create temporary file with mkstemp, mode 0600, owner root:root. Copy EA attributes.

You're assuming that root is god. Not so with a mandatory access control scheme like SELinux.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
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.
#6 lore raw
Quoted 6 lines · Stephen Smalley
Quoted 3 lines · Thorsten Kukuk

Ok, I think it is trivial to do a getfscreatecon, call setfscreatecon with the permissions of the passwd file and restore the original fscreate values afterwards.

Actually, this would be getfilecon() and then setfscreatecon().

No, I mean at first getfscreatecon. You cannot assume that a program calling a library modifying /etc/passwd does not create any other files. And in the later case it could be that we don't wish that this files will be created with the passwd context. Only think about useradd and creating home directories.
So you have to backup the original values at first and restore them afterwards.

Quoted 8 lines
Quoted 5 lines

But it would be interesting to know how somebody could be able to do something forbidden with the following:

Create temporary file with mkstemp, mode 0600, owner root:root. Copy EA attributes.

You're assuming that root is god. Not so with a mandatory access control scheme like SELinux.

No, I don't assume that root is god.

Signature · 9 lines
Thorsten Kukuk       http://www.suse.de/~kukuk/        [email protected]
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

--
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.
#7 lore raw
Quoted 7 lines · Thorsten Kukuk

No, I mean at first getfscreatecon. You cannot assume that a program calling a library modifying /etc/passwd does not create any other files. And in the later case it could be that we don't wish that this files will be created with the passwd context. Only think about useradd and creating home directories.
So you have to backup the original values at first and restore them afterwards.

Sorry, I misunderstood you. Yes, the libuser and pam pwdb patches do this as well.

Quoted 1 line

No, I don't assume that root is god.

Then you're assuming full revocation support, which doesn't exist, at least not yet.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
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.