Skip to contentSkip to conversation

SELinux and NFS --- a bit of a fight!

PATCH Stephen C. Tweedie 2 participants 3 messages Feb 27, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi all,

Looks like there is a rather nasty surprise lurking in the NFS code when using SELinux. I've been running with NFS-mounted homedirs, and an odd thing happens if you try to access those from sysadm_r and normal user contexts at the same time.

Basically, it looks as if the kernel's own internal NFS network sockets, used by the NFS client layer, are having SELinux controls applied to them. You end up with udp sockets created by one NFS process being unavailable to another process mounting the same filesystem, even if it's actually kernel-mode access to the socket which is being prohibited. AVC errors such as

        Feb 27 12:39:35 localhost kernel: avc:  denied  { write } for 
        pid=2365 exe=/bin/bash lport=800 scontext=sct:staff_r:staff_t
        tcontext=root:system_r:sshd_t tclass=udp_socket

and

        Feb 25 17:57:36 localhost kernel: avc:  denied  { write } for 
        pid=1817 exe=/bin/login lport=800
        scontext=system_u:system_r:local_login_t
        tcontext=user_u:user_r:user_t tclass=udp_socket

result.

This seems to be fixed by a fairly simple addition to sock_has_perm:

security/selinux/hooks.c renamed from security/selinux/hooks.c.=K0000=.orig +7 -0
@@ -2719,6 +2719,13 @@ static int socket_has_perm(struct task_s
 	struct avc_audit_data ad;
 	int err;
 
+	/* Special case: sunrpc and similar kernel users, sending kernel
+	 * data over a socket, don't want to get clobbered here when
+	 * trying to send over something like a kernel-internal NFS
+	 * socket. */
+	if (segment_eq(get_fs(), KERNEL_DS))
+		return 0;
+	
 	tsec = task->security;
 	isec = SOCK_INODE(sock)->i_security;
 

which simply skips the AVC test entirely if we've got get_ds() == KERNEL_DS (which is kernel-speak for "the data we're passing in here is coming directly from kernel space, not user space.)

I'm not convinced that this is the absolute best solution, but I can't see any cleaner methods off-hand.

--Stephen

--
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 2 lines · Stephen C. Tweedie

I'm not convinced that this is the absolute best solution, but I can't see any cleaner methods off-hand.

The policy already has a rule in can_network() to allow domains to share a socket created by mount:
allow $1 mount_t:udp_socket rw_socket_perms;

I'm not clear as to when the sockets you are referencing are being created; if they are created while in the context of the mount program (which should be running in the mount_t domain, unless we need additional domain transitions somewhere), then they should inherit that domain.

Of course, if possible, it would be preferable to have the kernel-created sockets use the kernel SID; this is already the case for things like the ICMP and TCP reset sockets.

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

Hi,

Quoted 10 lines · Stephen Smalley
Quoted 2 lines · Stephen C. Tweedie

I'm not convinced that this is the absolute best solution, but I can't see any cleaner methods off-hand.

The policy already has a rule in can_network() to allow domains to share a socket created by mount:
allow $1 mount_t:udp_socket rw_socket_perms;

I'm not clear as to when the sockets you are referencing are being created;

They appear with the label of the calling process, so it's not in mount itself. I'll be asking our resident NFS expert about the detailed lifetime rules for these sockets next week once he's back from Connectathon.

--Stephen

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