SELinux and SMP
Greetings,
I have been playing with an SELinux setup for a couple of months and have been following this list. I haven't seen much talk lately about how well SELinux works on SMP machines. How SMP safe is SELinux? Has anybody made SMP performance measurements lately?
Thanks
Signature · 7 lines
George Wilson <[email protected]> IBM Linux Technology Center -- 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.
Quoted 4 lines · George C. Wilson
I have been playing with an SELinux setup for a couple of months and have been following this list. I haven't seen much talk lately about how well SELinux works on SMP machines. How SMP safe is SELinux? Has anybody made SMP performance measurements lately?
There is one known safety issue with SMP; a race in the sock_rcv_skb hook, apparently between closing a socket and packet receipt on the socket. The attached patch against 2.6.6 should fix, but is still undergoing testing. Otherwise, I don't know of any other SMP safety issues.
With regard to scalability, Hubertus Franke and Rajan Ravindran of IBM did some preliminary work on SELinux back in 2001 (e.g. see
http://marc.theaimsgroup.com/?l=selinux&m=99229517500418&w=2) but didn't follow up for some reason. I did request and get a patch from Rajan later in 2001, but it was still rather experimental (6 different approaches with 6 different config options), and turned out to be unsafe, and there was no further follow up. Last summer, James Morris of RedHat performed some benchmarking of SELinux and did some experimentation to try to improve scalability and performance, but didn't find a good solution at the time and had to defer further investigation until later.
The AVC spinlock is the chief stumbling block, and note that it protects more than just the cache itself; it also protects the AVC entry references embedded in the kernel object security structures.
Signature · 2 lines
Stephen Smalley <[email protected]> National Security Agency
Index: linux-2.6/security/selinux/hooks.c
security/selinux/hooks.c renamed from security/selinux/hooks.c:1.1.1.11 +21 -16
@@ -3094,12 +3173,12 @@char *addrp;int len, err =0 ;u32 netif_perm, node_perm, node_sid, recv_perm =0 ; +u32 sock_sid =0 ; +u16 sock_class =0 ;struct socket *sock; -struct inode *inode;struct net_device *dev;struct sel_netif *netif;struct netif_security_struct *nsec; -struct inode_security_struct *isec;struct avc_audit_data ad; family = sk->sk_family;
@@ -3110,15 +3189,21 @@if (family ==PF_INET6 && skb->protocol ==ntohs (ETH_P_IP )) family =PF_INET ; - sock = sk->sk_socket; - -/* TCP control messages don't always have a socket. */ -if (!sock) - goto out; - - inode =SOCK_INODE (sock); -if (!inode) - goto out; +read_lock_bh (&sk->sk_callback_lock); + sock = sk->sk_socket; +if (sock) { +struct inode *inode; + inode =SOCK_INODE (sock); +if (inode) { +struct inode_security_struct *isec; + isec = inode->i_security; + sock_sid = isec->sid; + sock_class = isec->sclass; + } + } +read_unlock_bh (&sk->sk_callback_lock); +if (!sock_sid) + goto out; dev = skb->dev;if (!dev)
@@ -3131,9 +3216,8 @@ } nsec = &netif->nsec; - isec = inode->i_security; -switch (isec->sclass) { +switch (sock_class) {case SECCLASS_UDP_SOCKET : netif_perm =NETIF__UDP_RECV ; node_perm =NODE__UDP_RECV ;
@@ -3162,7 +3246,7 @@ goto out; } - err =avc_has_perm (isec->sid, nsec->if_sid,SECCLASS_NETIF , + err =avc_has_perm (sock_sid, nsec->if_sid,SECCLASS_NETIF , netif_perm, &nsec->avcr, &ad);sel_netif_put (netif);if (err)
@@ -3173,7 +3257,7 @@if (err) goto out; - err =avc_has_perm (isec->sid, node_sid,SECCLASS_NODE , node_perm,NULL , &ad); + err =avc_has_perm (sock_sid, node_sid,SECCLASS_NODE , node_perm,NULL , &ad);if (err) goto out;
@@ -3187,7 +3271,7 @@if (err) goto out; - err =avc_has_perm (isec->sid, port_sid, isec->sclass, + err =avc_has_perm (sock_sid, port_sid, sock_class, recv_perm,NULL , &ad); } out: