SELinux UNIX domain socket fixes/cleanup
cover SELinux UNIX domain socket fixes/cleanup
I finally got a chance to cobble together some tests to verify both getpeercon() on the client end of a connected UNIX domain socket as well as the proper operation of fsetxattr() on sockets. I'm happy to report that everything worked as I expected it to (UNIX sockets now behave like INET sockets) and nothing exploded. This latest version of the patchset should include all the feedback I've received so far as well as my sign-off on each patch so I think we should be in good shape at this point. As a result, I'm submitting these patches for whatever kernel release looks most appropriate - maybe to late for .35, but you might be able to make a weak argument that some of the patches are bugfixes - regardless, I'll let you guys make that call; as long as they go somewhere I'll be happy.
For those of you using git, you can also find a copy of the patches at the URL below.
* git://git.infradead.org/users/pcmoore/lblnet-2.6_testing
Thanks.
---
Paul Moore (6):
selinux: Update socket's label alongside inode's label
selinux: Set the peer label correctly on connected UNIX domain sockets
selinux: Consolidate sockcreate_sid logic
selinux: Shuffle the sk_security_struct alloc and free routines
selinux: Convert socket related access controls to use socket labels
selinux: Use current_security() when possible
security/selinux/hooks.c | 286 +++++++++++++++++------------------ security/selinux/include/netlabel.h | 5 - security/selinux/netlabel.c | 8 + 3 files changed, 144 insertions(+), 155 deletions(-)
--
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.
PATCH 1/6 selinux: Update socket's label alongside inode's label
We have always had a potential disconnect between the label on socket and the label on the associated inode when a user calls fsetxattr() on a socket. The problem is that the fsetxattr() call would only relabel the inode and not the corresponding socket; the good news is that the mainstream SELinux policies have always prevented this, but better safe than sorry ...
This patch fixes this problem by adding the necessary socket labeling code to selinux_inode_setsecurity() so that if a user did relabel a socket via fsetxattr() both the inode and socket would be relabeled.
--- security/selinux/hooks.c | 43 ++++++++++++++++++++++++++++++++++- security/selinux/include/netlabel.h | 5 ++-- security/selinux/netlabel.c | 8 +++++-- 3 files changed, 50 insertions(+), 6 deletions(-)
security/selinux/hooks.c +42 -1
@@ -2898,6 +2898,47 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,if (rc)return rc; +if (inode->i_sb->s_magic ==SOCKFS_MAGIC ) { +u32 oldsid; +struct sock *sk =SOCKET_I (inode)->sk; +struct sk_security_struct *sksec = sk->sk_security; + +/* XXX - In order to safely relabel a socket when labeled IPsec +* is in use we need to also change the corresponding +* flow secid (if any), if we don't change the flow's +* secid then we run the risk of mislabeling traffic which +* is not good. Since the odds of us hitting this code +* are very low (actually zero given refpolicy circa 2010) +* we're not going to expend the effort in relabeling the +* flow, just cause the fsetxattr() operation to fail +* which should guarantee labeling safety. */ +if (selinux_xfrm_enabled ()) +return -EPERM ; + +/* It is worth mentioning here that you could potentially see a +* labeling race condition if the socket being relabeled is +* undergoing lots of writes at the same time, as writes sent +* before the fsetxattr() operation may not receive their +* on-the-wire security label until after the fsetxattr() +* completes resulting in pre-fsetxattr() data getting labeled +* with a post-fsetxattr() security label. However, we're just +* going to assume that if someone is silly enough to try and +* relabel a socket mid-stream then they should bear the +* responsibility of dealing with the potential problems. It +* is also worth mentioning that this operation is forbidden by +* the 2010 refpolicy for this very reason. */ + oldsid = sksec->sid; + sksec->sid = newsid; +lock_sock (sk); +selinux_netlbl_sk_security_reset (sksec); + rc =selinux_netlbl_socket_setsid (sk, sk->sk_family); +release_sock (sk); +if (rc) { + sksec->sid = oldsid; +return rc; + } + } + isec->sid = newsid; isec->initialized =1 ;return 0 ;
@@ -3744,7 +3785,7 @@ static int selinux_socket_post_create(struct socket *sock, int family, sksec = sock->sk->sk_security; sksec->sid = isec->sid; sksec->sclass = isec->sclass; - err =selinux_netlbl_socket_post_create (sock->sk, family); + err =selinux_netlbl_socket_setsid (sock->sk, family); }return err;
security/selinux/include/netlabel.h +2 -3
@@ -55,7 +55,7 @@ int selinux_netlbl_skbuff_setsid(struct sk_buff *skb,int selinux_netlbl_inet_conn_request (struct request_sock *req,u16 family);void selinux_netlbl_inet_csk_clone (struct sock *sk,u16 family); -int selinux_netlbl_socket_post_create (struct sock *sk,u16 family); +int selinux_netlbl_socket_setsid (struct sock *sk,u16 family); int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, struct sk_buff *skb, u16 family,
@@ -121,8 +121,7 @@ static inline void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family) {return ; } -static inline int selinux_netlbl_socket_post_create (struct sock *sk, -u16 family) +static inline int selinux_netlbl_socket_setsid (struct sock *sk,u16 family) {return 0 ; }
security/selinux/netlabel.c +6 -2
@@ -157,6 +157,10 @@ void selinux_netlbl_sk_security_free(struct sk_security_struct *sksec)void selinux_netlbl_sk_security_reset (struct sk_security_struct *sksec) { sksec->nlbl_state =NLBL_UNSET ; +if (sksec->nlbl_secattr !=NULL ) { +netlbl_secattr_free (sksec->nlbl_secattr); + sksec->nlbl_secattr =NULL ; + } }/**
@@ -292,7 +296,7 @@ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family) }/** -* selinux_netlbl_socket_post_create - Label a socket using NetLabel +* selinux_netlbl_socket_setsid - Label a socket using NetLabel * @sock: the socket to label * @family: protocol family *
@@ -301,7 +305,7 @@ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)* SID. Returns zero values on success, negative values on failure. * */ -int selinux_netlbl_socket_post_create (struct sock *sk,u16 family) +int selinux_netlbl_socket_setsid (struct sock *sk,u16 family) {int rc;struct sk_security_struct *sksec = sk->sk_security;
--
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.
PATCH 2/6 selinux: Set the peer label correctly on connected UNIX domain sockets
In reply to Paul MooreCorrect a problem where we weren't setting the peer label correctly on the client end of a pair of connected UNIX sockets.
--- security/selinux/hooks.c | 30 ++++++++++++++---------------- 1 files changed, 14 insertions(+), 16 deletions(-)
security/selinux/hooks.c +14 -16
@@ -4021,34 +4021,32 @@ static int selinux_socket_unix_stream_connect(struct socket *sock,struct socket *other, struct sock *newsk) { - struct sk_security_struct *sksec; -struct inode_security_struct *isec; -struct inode_security_struct *other_isec; + struct sk_security_struct *sksec_sock = sock->sk->sk_security; +struct sk_security_struct *sksec_other = other->sk->sk_security; +struct sk_security_struct *sksec_new = newsk->sk_security;struct common_audit_data ad;int err; - isec =SOCK_INODE (sock)->i_security; - other_isec =SOCK_INODE (other)->i_security; -COMMON_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.sk = other->sk; - err =avc_has_perm (isec->sid, other_isec->sid, - isec->sclass, + err =avc_has_perm (sksec_sock->sid, sksec_other->sid, + sksec_other->sclass,UNIX_STREAM_SOCKET__CONNECTTO , &ad);if (err)return err; -/* connecting socket */ - sksec = sock->sk->sk_security; - sksec->peer_sid = other_isec->sid; -/* server child socket */ - sksec = newsk->sk_security; - sksec->peer_sid = isec->sid; - err =security_sid_mls_copy (other_isec->sid, sksec->peer_sid, &sksec->sid); + sksec_new->peer_sid = sksec_sock->sid; + err =security_sid_mls_copy (sksec_other->sid, sksec_sock->sid, + &sksec_new->sid); +if (err) +return err; -return err; +/* connecting socket */ + sksec_sock->peer_sid = sksec_new->sid; + +return 0 ; } static int selinux_socket_unix_may_send(struct socket *sock,
--
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.
PATCH 3/6 selinux: Consolidate sockcreate_sid logic
In reply to Paul MooreConsolidate the basic sockcreate_sid logic into a single helper function which allows us to do some cleanups in the related code.
--- security/selinux/hooks.c | 32 ++++++++++++-------------------- 1 files changed, 12 insertions(+), 20 deletions(-)
security/selinux/hooks.c +12 -20
@@ -3712,6 +3712,12 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid) }/* socket security operations */ + +static u32 socket_sockcreate_sid (const struct task_security_struct *tsec) +{ +return tsec->sockcreate_sid ? : tsec->sid; +} +static int socket_has_perm (struct task_struct *task,struct socket *sock,u32 perms) {
@@ -3739,21 +3745,15 @@ static int selinux_socket_create(int family, int type, {const struct cred *cred =current_cred ();const struct task_security_struct *tsec = cred->security; -u32 sid, newsid; +u32 newsid;u16 secclass; -int err =0 ;if (kern) - goto out; - - sid = tsec->sid; - newsid = tsec->sockcreate_sid ?: sid; +return 0 ; + newsid =socket_sockcreate_sid (tsec); secclass =socket_type_to_security_class (family, type, protocol); - err =avc_has_perm (sid, newsid, secclass,SOCKET__CREATE ,NULL ); - -out: -return err; +return avc_has_perm (tsec->sid, newsid, secclass,SOCKET__CREATE ,NULL ); } static int selinux_socket_post_create(struct socket *sock, int family,
@@ -3761,22 +3761,14 @@ static int selinux_socket_post_create(struct socket *sock, int family, {const struct cred *cred =current_cred ();const struct task_security_struct *tsec = cred->security; -struct inode_security_struct *isec; +struct inode_security_struct *isec =SOCK_INODE (sock)->i_security;struct sk_security_struct *sksec; -u32 sid, newsid;int err =0 ; - sid = tsec->sid; - newsid = tsec->sockcreate_sid; - - isec =SOCK_INODE (sock)->i_security; -if (kern) isec->sid =SECINITSID_KERNEL ; -else if (newsid) - isec->sid = newsid;else - isec->sid = sid; + isec->sid =socket_sockcreate_sid (tsec); isec->sclass =socket_type_to_security_class (family, type, protocol); isec->initialized =1 ;
--
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.
PATCH 4/6 selinux: Shuffle the sk_security_struct alloc and free routines
In reply to Paul MooreThe sk_alloc_security() and sk_free_security() functions were only being called by the selinux_sk_alloc_security() and selinux_sk_free_security() functions so we just move the guts of the alloc/free routines to the callers and eliminate a layer of indirection.
--- security/selinux/hooks.c | 45 +++++++++++++++++---------------------------- 1 files changed, 17 insertions(+), 28 deletions(-)
security/selinux/hooks.c +17 -28
@@ -279,32 +279,6 @@ static void superblock_free_security(struct super_block *sb)kfree (sbsec); } -static int sk_alloc_security (struct sock *sk,int family,gfp_t priority) -{ -struct sk_security_struct *sksec; - - sksec =kzalloc (sizeof (*sksec), priority); -if (!sksec) -return -ENOMEM ; - - sksec->peer_sid =SECINITSID_UNLABELED ; - sksec->sid =SECINITSID_UNLABELED ; - sk->sk_security = sksec; - -selinux_netlbl_sk_security_reset (sksec); - -return 0 ; -} - -static void sk_free_security (struct sock *sk) -{ -struct sk_security_struct *sksec = sk->sk_security; - - sk->sk_security =NULL ; -selinux_netlbl_sk_security_free (sksec); -kfree (sksec); -} -/* The security server must be initialized before any labeling or access decisions can be provided. */ extern int ss_initialized;
@@ -4265,12 +4239,27 @@ out:static int selinux_sk_alloc_security (struct sock *sk,int family,gfp_t priority) { -return sk_alloc_security (sk, family, priority); +struct sk_security_struct *sksec; + + sksec =kzalloc (sizeof (*sksec), priority); +if (!sksec) +return -ENOMEM ; + + sksec->peer_sid =SECINITSID_UNLABELED ; + sksec->sid =SECINITSID_UNLABELED ; +selinux_netlbl_sk_security_reset (sksec); + sk->sk_security = sksec; + +return 0 ; }static void selinux_sk_free_security (struct sock *sk) { -sk_free_security (sk); +struct sk_security_struct *sksec = sk->sk_security; + + sk->sk_security =NULL ; +selinux_netlbl_sk_security_free (sksec); +kfree (sksec); }static void selinux_sk_clone_security (const struct sock *sk,struct sock *newsk)
--
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.
PATCH 5/6 selinux: Convert socket related access controls to use socket labels
In reply to Paul MooreAt present, the socket related access controls use a mix of inode and socket labels; while there should be no practical difference (they _should_ always be the same), it makes the code more confusing. This patch attempts to convert all of the socket related access control points (with the exception of some of the inode/fd based controls) to use the socket's own label. In the process, I also converted the socket_has_perm() function to take a 'sock' argument instead of a 'socket' since that was adding a bit more overhead in some cases.
--- security/selinux/hooks.c | 119 +++++++++++++++++----------------------------- 1 files changed, 45 insertions(+), 74 deletions(-)
security/selinux/hooks.c +45 -74
@@ -3692,26 +3692,19 @@ static u32 socket_sockcreate_sid(const struct task_security_struct *tsec)return tsec->sockcreate_sid ? : tsec->sid; } -static int socket_has_perm (struct task_struct *task,struct socket *sock, -u32 perms) +static int sock_has_perm (struct task_struct *task,struct sock *sk,u32 perms) { -struct inode_security_struct *isec; +struct sk_security_struct *sksec = sk->sk_security;struct common_audit_data ad; -u32 sid; -int err =0 ; +u32 tsid =task_sid (task); - isec =SOCK_INODE (sock)->i_security; - -if (isec->sid ==SECINITSID_KERNEL ) - goto out; - sid =task_sid (task); +if (sksec->sid ==SECINITSID_KERNEL ) +return 0 ;COMMON_AUDIT_DATA_INIT (&ad,NET ); - ad.u.net.sk = sock->sk; - err =avc_has_perm (sid, isec->sid, isec->sclass, perms, &ad); + ad.u.net.sk = sk; -out: -return err; +return avc_has_perm (tsid, sksec->sid, sksec->sclass, perms, &ad); } static int selinux_socket_create(int family, int type,
@@ -3763,10 +3756,11 @@ static int selinux_socket_post_create(struct socket *sock, int family,static int selinux_socket_bind (struct socket *sock,struct sockaddr *address,int addrlen) { +struct sock *sk = sock->sk;u16 family;int err; - err =socket_has_perm (current, sock,SOCKET__BIND ); + err =sock_has_perm (current, sk,SOCKET__BIND );if (err) goto out;
@@ -3775,19 +3769,16 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in* Multiple address binding for SCTP is not supported yet: we just * check the first address now. */ - family = sock->sk->sk_family; + family = sk->sk_family;if (family ==PF_INET || family ==PF_INET6 ) {char *addrp; -struct inode_security_struct *isec; +struct sk_security_struct *sksec = sk->sk_security;struct common_audit_data ad;struct sockaddr_in *addr4 =NULL ;struct sockaddr_in6 *addr6 =NULL ;unsigned short snum; -struct sock *sk = sock->sk;u32 sid, node_perm; - isec =SOCK_INODE (sock)->i_security; -if (family ==PF_INET ) { addr4 = (struct sockaddr_in *)address; snum =ntohs (addr4->sin_port);
@@ -3811,15 +3802,15 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, inCOMMON_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.sport =htons (snum); ad.u.net.family = family; - err =avc_has_perm (isec->sid, sid, - isec->sclass, + err =avc_has_perm (sksec->sid, sid, + sksec->sclass,SOCKET__NAME_BIND , &ad);if (err) goto out; } } -switch (isec->sclass) { +switch (sksec->sclass) {case SECCLASS_TCP_SOCKET : node_perm =TCP_SOCKET__NODE_BIND ;break ;
@@ -3850,8 +3841,8 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, inelse ipv6_addr_copy (&ad.u.net.v6info.saddr, &addr6->sin6_addr); - err =avc_has_perm (isec->sid, sid, - isec->sclass, node_perm, &ad); + err =avc_has_perm (sksec->sid, sid, + sksec->sclass, node_perm, &ad);if (err) goto out; }
@@ -3862,19 +3853,18 @@ out:static int selinux_socket_connect (struct socket *sock,struct sockaddr *address,int addrlen) {struct sock *sk = sock->sk; -struct inode_security_struct *isec; +struct sk_security_struct *sksec = sk->sk_security;int err; - err =socket_has_perm (current, sock,SOCKET__CONNECT ); + err =sock_has_perm (current, sk,SOCKET__CONNECT );if (err)return err;/* * If a TCP or DCCP socket, check name_connect permission for the port. */ - isec =SOCK_INODE (sock)->i_security; -if (isec->sclass ==SECCLASS_TCP_SOCKET || - isec->sclass ==SECCLASS_DCCP_SOCKET ) { +if (sksec->sclass ==SECCLASS_TCP_SOCKET || + sksec->sclass ==SECCLASS_DCCP_SOCKET ) {struct common_audit_data ad;struct sockaddr_in *addr4 =NULL ;struct sockaddr_in6 *addr6 =NULL ;
@@ -3897,13 +3887,13 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,if (err) goto out; - perm = (isec->sclass ==SECCLASS_TCP_SOCKET ) ? + perm = (sksec->sclass ==SECCLASS_TCP_SOCKET ) ?TCP_SOCKET__NAME_CONNECT :DCCP_SOCKET__NAME_CONNECT ;COMMON_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.dport =htons (snum); ad.u.net.family = sk->sk_family; - err =avc_has_perm (isec->sid, sid, isec->sclass, perm, &ad); + err =avc_has_perm (sksec->sid, sid, sksec->sclass, perm, &ad);if (err) goto out; }
@@ -3916,7 +3906,7 @@ out:static int selinux_socket_listen (struct socket *sock,int backlog) { -return socket_has_perm (current, sock,SOCKET__LISTEN ); +return sock_has_perm (current, sock->sk,SOCKET__LISTEN ); }static int selinux_socket_accept (struct socket *sock,struct socket *newsock)
@@ -3925,7 +3915,7 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)struct inode_security_struct *isec;struct inode_security_struct *newisec; - err =socket_has_perm (current, sock,SOCKET__ACCEPT ); + err =sock_has_perm (current, sock->sk,SOCKET__ACCEPT );if (err)return err;
@@ -3942,30 +3932,30 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)static int selinux_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return socket_has_perm (current, sock,SOCKET__WRITE ); +return sock_has_perm (current, sock->sk,SOCKET__WRITE ); }static int selinux_socket_recvmsg (struct socket *sock,struct msghdr *msg,int size,int flags) { -return socket_has_perm (current, sock,SOCKET__READ ); +return sock_has_perm (current, sock->sk,SOCKET__READ ); }static int selinux_socket_getsockname (struct socket *sock) { -return socket_has_perm (current, sock,SOCKET__GETATTR ); +return sock_has_perm (current, sock->sk,SOCKET__GETATTR ); }static int selinux_socket_getpeername (struct socket *sock) { -return socket_has_perm (current, sock,SOCKET__GETATTR ); +return sock_has_perm (current, sock->sk,SOCKET__GETATTR ); }static int selinux_socket_setsockopt (struct socket *sock,int level,int optname) {int err; - err =socket_has_perm (current, sock,SOCKET__SETOPT ); + err =sock_has_perm (current, sock->sk,SOCKET__SETOPT );if (err)return err;
@@ -3975,12 +3965,12 @@ static int selinux_socket_setsockopt(struct socket *sock, int level, int optnamestatic int selinux_socket_getsockopt (struct socket *sock,int level,int optname) { -return socket_has_perm (current, sock,SOCKET__GETOPT ); +return sock_has_perm (current, sock->sk,SOCKET__GETOPT ); }static int selinux_socket_shutdown (struct socket *sock,int how) { -return socket_has_perm (current, sock,SOCKET__SHUTDOWN ); +return sock_has_perm (current, sock->sk,SOCKET__SHUTDOWN ); } static int selinux_socket_unix_stream_connect(struct socket *sock,
@@ -4018,23 +4008,15 @@ static int selinux_socket_unix_stream_connect(struct socket *sock,static int selinux_socket_unix_may_send (struct socket *sock,struct socket *other) { -struct inode_security_struct *isec; -struct inode_security_struct *other_isec; +struct sk_security_struct *ssec = sock->sk->sk_security; +struct sk_security_struct *osec = other->sk->sk_security;struct common_audit_data ad; -int err; - - isec =SOCK_INODE (sock)->i_security; - other_isec =SOCK_INODE (other)->i_security;COMMON_AUDIT_DATA_INIT (&ad,NET ); ad.u.net.sk = other->sk; - err =avc_has_perm (isec->sid, other_isec->sid, - isec->sclass,SOCKET__SENDTO , &ad); -if (err) -return err; - -return 0 ; +return avc_has_perm (ssec->sid, osec->sid, osec->sclass,SOCKET__SENDTO , + &ad); } static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
@@ -4173,26 +4155,18 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *opint err =0 ;char *scontext;u32 scontext_len; -struct sk_security_struct *sksec; -struct inode_security_struct *isec; +struct sk_security_struct *sksec = sock->sk->sk_security;u32 peer_sid =SECSID_NULL ; - isec =SOCK_INODE (sock)->i_security; - -if (isec->sclass ==SECCLASS_UNIX_STREAM_SOCKET || - isec->sclass ==SECCLASS_TCP_SOCKET ) { - sksec = sock->sk->sk_security; +if (sksec->sclass ==SECCLASS_UNIX_STREAM_SOCKET || + sksec->sclass ==SECCLASS_TCP_SOCKET ) peer_sid = sksec->peer_sid; - } -if (peer_sid ==SECSID_NULL ) { - err = -ENOPROTOOPT ; - goto out; - } +if (peer_sid ==SECSID_NULL ) +return -ENOPROTOOPT ; err =security_sid_to_context (peer_sid, &scontext, &scontext_len); -if (err) - goto out; +return err;if (scontext_len > len) { err = -ERANGE ;
@@ -4205,9 +4179,7 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op out_len:if (put_user (scontext_len, optlen)) err = -EFAULT ; -kfree (scontext); -out:return err; }
@@ -4419,8 +4391,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)int err =0 ;u32 perm;struct nlmsghdr *nlh; -struct socket *sock = sk->sk_socket; -struct inode_security_struct *isec =SOCK_INODE (sock)->i_security; +struct sk_security_struct *sksec = sk->sk_security;if (skb->len <NLMSG_SPACE (0 )) { err = -EINVAL ;
@@ -4428,13 +4399,13 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) } nlh =nlmsg_hdr (skb); - err =selinux_nlmsg_lookup (isec->sclass, nlh->nlmsg_type, &perm); + err =selinux_nlmsg_lookup (sksec->sclass, nlh->nlmsg_type, &perm);if (err) {if (err == -EINVAL ) {audit_log (current->audit_context,GFP_KERNEL ,AUDIT_SELINUX_ERR ,"SELinux: unrecognized netlink message" " type=%hu for sclass=%hu\n" , - nlh->nlmsg_type, isec->sclass); + nlh->nlmsg_type, sksec->sclass);if (!selinux_enforcing ||security_get_allow_unknown ()) err =0 ; }
@@ -4445,7 +4416,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) goto out; } - err =socket_has_perm (current, sock, perm); + err =sock_has_perm (current, sk, perm); out:return err; }
--
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.
PATCH 6/6 selinux: Use current_security() when possible
In reply to Paul MooreThere were a number of places using the following code pattern:
struct cred *cred = current_cred(); struct task_security_struct *tsec = cred->security;
... which were simplified to the following:
struct task_security_struct *tsec = current_security();
--- security/selinux/hooks.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-)
security/selinux/hooks.c +6 -11
@@ -188,7 +188,7 @@ static inline u32 task_sid(const struct task_struct *task)*/ static inline u32 current_sid (void ) { -const struct task_security_struct *tsec =current_cred ()->security; +const struct task_security_struct *tsec =current_security ();return tsec->sid; }
@@ -1558,8 +1558,7 @@ static int may_create(struct inode *dir, struct dentry *dentry, u16 tclass) { -const struct cred *cred =current_cred (); -const struct task_security_struct *tsec = cred->security; +const struct task_security_struct *tsec =current_security ();struct inode_security_struct *dsec;struct superblock_security_struct *sbsec;u32 sid, newsid;
@@ -2157,8 +2156,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)static int selinux_bprm_secureexec (struct linux_binprm *bprm) { -const struct cred *cred =current_cred (); -const struct task_security_struct *tsec = cred->security; +const struct task_security_struct *tsec =current_security ();u32 sid, osid;int atsecure =0 ;
@@ -2533,8 +2531,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir, char **name, void **value, size_t *len) { - const struct cred *cred = current_cred(); -const struct task_security_struct *tsec = cred->security; + const struct task_security_struct *tsec = current_security();struct inode_security_struct *dsec;struct superblock_security_struct *sbsec;u32 sid, newsid, clen;
@@ -3710,8 +3707,7 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)static int selinux_socket_create (int family,int type,int protocol,int kern) { -const struct cred *cred =current_cred (); -const struct task_security_struct *tsec = cred->security; +const struct task_security_struct *tsec =current_security ();u32 newsid;u16 secclass;
@@ -3726,8 +3722,7 @@ static int selinux_socket_create(int family, int type,static int selinux_socket_post_create (struct socket *sock,int family,int type,int protocol,int kern) { -const struct cred *cred =current_cred (); -const struct task_security_struct *tsec = cred->security; +const struct task_security_struct *tsec =current_security ();struct inode_security_struct *isec =SOCK_INODE (sock)->i_security;struct sk_security_struct *sksec;int err =0 ;
--
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 13 lines · Paul Moore
I finally got a chance to cobble together some tests to verify both
getpeercon()on the client end of a connected UNIX domain socket as well as the proper operation offsetxattr()on sockets. I'm happy to report that everything worked as I expected it to (UNIX sockets now behave like INET sockets) and nothing exploded. This latest version of the patchset should include all the feedback I've received so far as well as my sign-off on each patch so I think we should be in good shape at this point. As a result, I'm submitting these patches for whatever kernel release looks most appropriate - maybe to late for .35, but you might be able to make a weak argument that some of the patches are bugfixes - regardless, I'll let you guys make that call; as long as they go somewhere I'll be happy.
Quoted 6 lines
For those of you using git, you can also find a copy of the patches at the URL below.
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testingThanks.
Thoughts? Comments? ACKs? NACKs?
Signature · 7 lines
paul moore linux @ hp -- 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 10 lines · Paul Moore
Quoted 6 lines · Paul Moore
For those of you using git, you can also find a copy of the patches at the URL below.
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testingThanks.
Thoughts? Comments? ACKs? NACKs?
I looked over the whole series and was good with them except I didn't know/understand the netlbl changes at the bottom of the first patch. I kept telling myself I was going to dig out the code and verify it's correctness but I haven't yet. Any chance you could explain what that change is all about to make it easier for me to verify it is correct?
Patches 2-6 I'm ok adding my ACK to.....
-Eric
--
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 9 lines · Eric Paris
Quoted 8 lines · Paul Moore
Quoted 6 lines · Paul Moore
For those of you using git, you can also find a copy of the patches at the URL below.
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testingThanks.
Quoted 7 lines
Quoted 1 line
Thoughts? Comments? ACKs? NACKs?
I looked over the whole series and was good with them except I didn't know/understand the netlbl changes at the bottom of the first patch. I kept telling myself I was going to dig out the code and verify it's correctness but I haven't yet. Any chance you could explain what that change is all about to make it easier for me to verify it is correct?
Sure, let me give it a shot - I assume you're talking about the changes to selinux_netlbl_sk_security_reset()? Assuming the answer is "yes", the reason is that before it's inclusion in selinux_inode_setsecurity() it was always called from functions operating on newly allocated sk_security_structs and as a result it didn't need to worry about any old per-socket cached values (look at selinux_netlbl_sock_genattr() to see what I mean about cached values and sksec->nlbl_secattr). The change to selinux_netlbl_sk_security_reset() is to check if a cache value exists and if it does clear it out before we relabel the socket.
Anything else you're fuzzy on? I can't promise my explanations will help but I can try ;)
Quoted 1 line
Patches 2-6 I'm ok adding my ACK to.....
Thanks!
Signature · 7 lines
paul moore linux @ hp -- 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 28 lines · Paul Moore
Quoted 9 lines · Eric Paris
Quoted 8 lines · Paul Moore
Quoted 6 lines · Paul Moore
For those of you using git, you can also find a copy of the patches at the URL below.
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testingThanks.
Quoted 7 lines
Quoted 1 line
Thoughts? Comments? ACKs? NACKs?
I looked over the whole series and was good with them except I didn't know/understand the netlbl changes at the bottom of the first patch. I kept telling myself I was going to dig out the code and verify it's correctness but I haven't yet. Any chance you could explain what that change is all about to make it easier for me to verify it is correct?
Sure, let me give it a shot - I assume you're talking about the changes to
selinux_netlbl_sk_security_reset()? Assuming the answer is "yes", the reason is that before it's inclusion inselinux_inode_setsecurity()it was always called from functions operating on newly allocatedsk_security_structsand as a result it didn't need to worry about any old per-socket cached values (look atselinux_netlbl_sock_genattr()to see what I mean about cached values andsksec->nlbl_secattr). The change toselinux_netlbl_sk_security_reset()is to check if a cache value exists and if it does clear it out before we relabel the socket.
Quoted 6 lines
Anything else you're fuzzy on? I can't promise my explanations will help but I can try ;)
Quoted 1 line
Patches 2-6 I'm ok adding my ACK to.....
Thanks!
Did the above explanation make sense? I ask because I'd like to get these patches moving into James' security-next tree as soon as possible and if there are any remaining issues I'd like to get working on them ...
Thanks.
Signature · 7 lines
paul moore linux @ hp -- 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 13 lines · Paul Moore
I finally got a chance to cobble together some tests to verify both
getpeercon()on the client end of a connected UNIX domain socket as well as the proper operation offsetxattr()on sockets. I'm happy to report that everything worked as I expected it to (UNIX sockets now behave like INET sockets) and nothing exploded. This latest version of the patchset should include all the feedback I've received so far as well as my sign-off on each patch so I think we should be in good shape at this point. As a result, I'm submitting these patches for whatever kernel release looks most appropriate - maybe to late for .35, but you might be able to make a weak argument that some of the patches are bugfixes - regardless, I'll let you guys make that call; as long as they go somewhere I'll be happy.
Quoted 4 lines
For those of you using git, you can also find a copy of the patches at the URL below.
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testing
Just a quick follow-up for the archives ... James has merged patches 2 through 6 with patch 1 being intentionally excluded due to concerns from Stephan Smalley over the potential race conditions described in the comments.
Signature · 7 lines
paul moore linux @ hp -- 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 17 lines · Paul Moore
Quoted 16 lines · Paul Moore
I finally got a chance to cobble together some tests to verify both
getpeercon()on the client end of a connected UNIX domain socket as well as the proper operation offsetxattr()on sockets. I'm happy to report that everything worked as I expected it to (UNIX sockets now behave like INET sockets) and nothing exploded. This latest version of the patchset should include all the feedback I've received so far as well as my sign-off on each patch so I think we should be in good shape at this point. As a result, I'm submitting these patches for whatever kernel release looks most appropriate - maybe to late for .35, but you might be able to make a weak argument that some of the patches are bugfixes - regardless, I'll let you guys make that call; as long as they go somewhere I'll be happy.For those of you using git, you can also find a copy of the patches at the URL below.
Quoted 6 lines
Quoted 1 line
*
git://git.infradead.org/users/pcmoore/lblnet-2.6_testingJust a quick follow-up for the archives ... James has merged patches 2 through 6 with patch 1 being intentionally excluded due to concerns from Stephan Smalley over the potential race conditions described in the comments.
My apologies, that would be _Stephen_ Smalley and not his evil twin Stephan ;)
Signature · 7 lines
paul moore linux @ hp -- 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.