Skip to contentSkip to conversation

strange labeling problem

DISCUSSION Colin Walters 2 participants 5 messages Apr 7, 2004 – Apr 8, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,

I encountered this issue earlier today. It had me totally stumped:

root@optimus-prime:/home/walters$ ls -alZ /usr/libexec/gconfd-2
-rwxr-xr-x+ root     root     system_u:object_r:gconfd_exec_t  /usr/libexec/gconfd-2
walters@optimus-prime:~$ ls -alZ /usr/libexec/gconfd-2
ls: /usr/libexec/gconfd-2: Permission denied
audit(1081374706.094:0): avc:  denied  { getattr } for  pid=13695 exe=/bin/ls 
  path=/usr/libexec/gconfd-2 dev=hda2 ino=683045 scontext=user_u:user_r:user_t 
  tcontext=system_u:object_r:unlabeled_t tclass=file

I double-checked that I had a rule:

allow user_t gconfd_exec_t:file { getattr };

in policy. Even more baffling, when I added a rule:

allow user_t unlabeled_t:file { getattr };

and then did a ls -alZ as a user, it correctly showed up as gconfd_exec_t!

I had tried rerunning chcon -t gconfd_exec_t /usr/libexec/gconfd-2 several times. I verified that the stored xattr was correct; i.e. a getfattr -d -m . /usr/libexec/gconfd-2 showed gconfd_exec_t. After a bit of futzing around I gave up and rebooted. It worked correctly on reboot.

I haven't looked at the code, but my thought is that somehow the cached inode got out of sync with the xattr, and was really unlabeled_t.

Has anyone seen this before?

#1 lore raw
Quoted 11 lines · Colin Walters

Hi,

I encountered this issue earlier today. It had me totally stumped:

root@optimus-prime:/home/walters$ ls -alZ /usr/libexec/gconfd-2
-rwxr-xr-x+ root     root     system_u:object_r:gconfd_exec_t  /usr/libexec/gconfd-2
walters@optimus-prime:~$ ls -alZ /usr/libexec/gconfd-2
ls: /usr/libexec/gconfd-2: Permission denied
audit(1081374706.094:0): avc:  denied  { getattr } for  pid=13695 exe=/bin/ls 
  path=/usr/libexec/gconfd-2 dev=hda2 ino=683045 scontext=user_u:user_r:user_t 
  tcontext=system_u:object_r:unlabeled_t tclass=file

This typically means that the type wasn't defined in the policy when the inode was last brought in-core. So ls -Z (or getfilecon or getfattr) will continue to report the actual attribute value from the disk, but SELinux is handling it as unlabeled_t since it had no definition for the type when the inode was brought in-core.

Quoted 3 lines

I had tried rerunning chcon -t gconfd_exec_t /usr/libexec/gconfd-2 several times. I verified that the stored xattr was correct; i.e. a getfattr -d -m . /usr/libexec/gconfd-2 showed gconfd_exec_t.

chcon likely never called setfilecon at all, since getfilecon would have told it that the file already had the right context. Try setfilecon instead. If it had called setfilecon -> setxattr, then SELinux would have updated the inode SID accordingly.

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 4 lines · Stephen Smalley

chcon likely never called setfilecon at all, since getfilecon would have told it that the file already had the right context. Try setfilecon instead. If it had called setfilecon -> setxattr, then SELinux would have updated the inode SID accordingly.

This suggests that perhaps chcon should have a force option to force it to relabel even if it thinks that the file already has the correct context. Looks like '-f' is already taken.

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.
#3 lore raw
In reply to Stephen Smalley
Quoted 5 lines · Stephen Smalley

This typically means that the type wasn't defined in the policy when the inode was last brought in-core. So ls -Z (or getfilecon or getfattr) will continue to report the actual attribute value from the disk, but SELinux is handling it as unlabeled_t since it had no definition for the type when the inode was brought in-core.

Ahh, I see.

Quoted 6 lines
Quoted 3 lines

I had tried rerunning chcon -t gconfd_exec_t /usr/libexec/gconfd-2 several times. I verified that the stored xattr was correct; i.e. a getfattr -d -m . /usr/libexec/gconfd-2 showed gconfd_exec_t.

chcon likely never called setfilecon at all, since getfilecon would have told it that the file already had the right context.

Ok, and this is basically an optimization, so we don't have to rewrite the xattr on disk?

Quoted 1 line

Try setfilecon instead.

It's kind of confusing that there can be this kind of desynchronization between chcon and ls -Z. It will probably be a pretty rare case - it'll likely only hit people who are developing policy.

#4 lore raw
Quoted 6 lines · Colin Walters
Quoted 2 lines · Stephen Smalley

chcon likely never called setfilecon at all, since getfilecon would have told it that the file already had the right context.

Ok, and this is basically an optimization, so we don't have to rewrite the xattr on disk?

Yes. It would call getfilecon anyway to see whether the context is being changed for verbose mode, and to determine the full context if only a particular context field (e.g. -t) were specified. Also avoids any spurious permission denial, e.g. you do a chcon -R on a tree, and lack permission to relabel a file in that tree, but the file already has the right label.

Quoted 3 lines

It's kind of confusing that there can be this kind of desynchronization between chcon and ls -Z. It will probably be a pretty rare case - it'll likely only hit people who are developing policy.

Yes. This is a result of migrating to the xattr API; the old SELinux API obtained the context from the actual inode SID, and was always consistent. But the xattr API calls down into the filesystem code to obtain the context, not the security module. The security module only gets to mediate access before the call to the filesystem, and to update its internal state (i.e. the inode SID) after a successful call to the filesystem.

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.