Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 34652
b: refs/heads/master
c: 99f59ed
h: refs/heads/master
v: v3
  • Loading branch information
Paul Moore authored and David S. Miller committed Sep 22, 2006
1 parent fc86711 commit 0c5f844
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fc747e82b40ea50a62eb2aef55bedd4465607cb0
refs/heads/master: 99f59ed073d3c1b890690064ab285a201dea2e35
6 changes: 6 additions & 0 deletions trunk/security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
ssec->sid = SECINITSID_UNLABELED;
sk->sk_security = ssec;

selinux_netlbl_sk_security_init(ssec, family);

return 0;
}

Expand Down Expand Up @@ -3585,6 +3587,8 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)

newssec->sid = ssec->sid;
newssec->peer_sid = ssec->peer_sid;

selinux_netlbl_sk_clone_security(ssec, newssec);
}

static void selinux_sk_getsecid(struct sock *sk, u32 *secid)
Expand Down Expand Up @@ -3648,6 +3652,8 @@ static void selinux_inet_csk_clone(struct sock *newsk,
new socket in sync, but we don't have the isec available yet.
So we will wait until sock_graft to do it, by which
time it will have been created and available. */

selinux_netlbl_sk_security_init(newsksec, req->rsk_ops->family);
}

static void selinux_req_classify_flow(const struct request_sock *req,
Expand Down
18 changes: 18 additions & 0 deletions trunk/security/selinux/include/selinux_netlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec,
struct avc_audit_data *ad);
u32 selinux_netlbl_socket_getpeersec_stream(struct socket *sock);
u32 selinux_netlbl_socket_getpeersec_dgram(struct sk_buff *skb);
void selinux_netlbl_sk_security_init(struct sk_security_struct *ssec,
int family);
void selinux_netlbl_sk_clone_security(struct sk_security_struct *ssec,
struct sk_security_struct *newssec);

int __selinux_netlbl_inode_permission(struct inode *inode, int mask);
/**
Expand Down Expand Up @@ -115,6 +119,20 @@ static inline u32 selinux_netlbl_socket_getpeersec_dgram(struct sk_buff *skb)
return SECSID_NULL;
}

static inline void selinux_netlbl_sk_security_init(
struct sk_security_struct *ssec,
int family)
{
return;
}

static inline void selinux_netlbl_sk_clone_security(
struct sk_security_struct *ssec,
struct sk_security_struct *newssec)
{
return;
}

static inline int selinux_netlbl_inode_permission(struct inode *inode,
int mask)
{
Expand Down
45 changes: 43 additions & 2 deletions trunk/security/selinux/ss/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,45 @@ static int selinux_netlbl_socket_setsid(struct socket *sock, u32 sid)
return rc;
}

/**
* selinux_netlbl_sk_security_init - Setup the NetLabel fields
* @ssec: the sk_security_struct
* @family: the socket family
*
* Description:
* Called when a new sk_security_struct is allocated to initialize the NetLabel
* fields.
*
*/
void selinux_netlbl_sk_security_init(struct sk_security_struct *ssec,
int family)
{
if (family == PF_INET)
ssec->nlbl_state = NLBL_REQUIRE;
else
ssec->nlbl_state = NLBL_UNSET;
}

/**
* selinux_netlbl_sk_clone_security - Copy the NetLabel fields
* @ssec: the original sk_security_struct
* @newssec: the cloned sk_security_struct
*
* Description:
* Clone the NetLabel specific sk_security_struct fields from @ssec to
* @newssec.
*
*/
void selinux_netlbl_sk_clone_security(struct sk_security_struct *ssec,
struct sk_security_struct *newssec)
{
newssec->sclass = ssec->sclass;
if (ssec->nlbl_state != NLBL_UNSET)
newssec->nlbl_state = NLBL_REQUIRE;
else
newssec->nlbl_state = NLBL_UNSET;
}

/**
* selinux_netlbl_socket_post_create - Label a socket using NetLabel
* @sock: the socket to label
Expand All @@ -2440,10 +2479,11 @@ int selinux_netlbl_socket_post_create(struct socket *sock,
struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
struct sk_security_struct *sksec = sock->sk->sk_security;

sksec->sclass = isec->sclass;

if (sock_family != PF_INET)
return 0;

sksec->sclass = isec->sclass;
sksec->nlbl_state = NLBL_REQUIRE;
return selinux_netlbl_socket_setsid(sock, sid);
}
Expand All @@ -2463,12 +2503,13 @@ void selinux_netlbl_sock_graft(struct sock *sk, struct socket *sock)
struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
struct sk_security_struct *sksec = sk->sk_security;

sksec->sclass = isec->sclass;

if (sk->sk_family != PF_INET)
return;

sksec->nlbl_state = NLBL_REQUIRE;
sksec->peer_sid = sksec->sid;
sksec->sclass = isec->sclass;

/* Try to set the NetLabel on the socket to save time later, if we fail
* here we will pick up the pieces in later calls to
Expand Down

0 comments on commit 0c5f844

Please sign in to comment.