Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 15517
b: refs/heads/master
c: d28d1e0
h: refs/heads/master
i:
  15515: f4b2efb
v: v3
  • Loading branch information
Trent Jaeger authored and David S. Miller committed Jan 3, 2006
1 parent a5a3420 commit 4214f07
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: df71837d5024e2524cd51c93621e558aa7dd9f3f
refs/heads/master: d28d1e080132f28ab773291f10ad6acca4c8bba2
2 changes: 2 additions & 0 deletions trunk/security/selinux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o

selinux-$(CONFIG_SECURITY_NETWORK) += netif.o

selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o

EXTRA_CFLAGS += -Isecurity/selinux/include

39 changes: 39 additions & 0 deletions trunk/security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "avc.h"
#include "objsec.h"
#include "netif.h"
#include "xfrm.h"

#define XATTR_SELINUX_SUFFIX "selinux"
#define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
Expand Down Expand Up @@ -3349,6 +3350,10 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
err = avc_has_perm(sock_sid, port_sid,
sock_class, recv_perm, &ad);
}

if (!err)
err = selinux_xfrm_sock_rcv_skb(sock_sid, skb);

out:
return err;
}
Expand Down Expand Up @@ -3401,6 +3406,24 @@ static void selinux_sk_free_security(struct sock *sk)
sk_free_security(sk);
}

static unsigned int selinux_sk_getsid_security(struct sock *sk, struct flowi *fl, u8 dir)
{
struct inode_security_struct *isec;
u32 sock_sid = SECINITSID_ANY_SOCKET;

if (!sk)
return selinux_no_sk_sid(fl);

read_lock_bh(&sk->sk_callback_lock);
isec = get_sock_isec(sk);

if (isec)
sock_sid = isec->sid;

read_unlock_bh(&sk->sk_callback_lock);
return sock_sid;
}

static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
{
int err = 0;
Expand Down Expand Up @@ -3536,6 +3559,11 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum,
send_perm, &ad) ? NF_DROP : NF_ACCEPT;
}

if (err != NF_ACCEPT)
goto out;

err = selinux_xfrm_postroute_last(isec->sid, skb);

out:
return err;
}
Expand Down Expand Up @@ -4380,6 +4408,16 @@ static struct security_operations selinux_ops = {
.socket_getpeersec = selinux_socket_getpeersec,
.sk_alloc_security = selinux_sk_alloc_security,
.sk_free_security = selinux_sk_free_security,
.sk_getsid = selinux_sk_getsid_security,
#endif

#ifdef CONFIG_SECURITY_NETWORK_XFRM
.xfrm_policy_alloc_security = selinux_xfrm_policy_alloc,
.xfrm_policy_clone_security = selinux_xfrm_policy_clone,
.xfrm_policy_free_security = selinux_xfrm_policy_free,
.xfrm_state_alloc_security = selinux_xfrm_state_alloc,
.xfrm_state_free_security = selinux_xfrm_state_free,
.xfrm_policy_lookup = selinux_xfrm_policy_lookup,
#endif
};

Expand Down Expand Up @@ -4491,6 +4529,7 @@ static int __init selinux_nf_ip_init(void)
panic("SELinux: nf_register_hook for IPv6: error %d\n", err);

#endif /* IPV6 */

out:
return err;
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/security/selinux/include/av_perm_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,5 @@
S_(SECCLASS_NSCD, NSCD__SHMEMHOST, "shmemhost")
S_(SECCLASS_ASSOCIATION, ASSOCIATION__SENDTO, "sendto")
S_(SECCLASS_ASSOCIATION, ASSOCIATION__RECVFROM, "recvfrom")
S_(SECCLASS_ASSOCIATION, ASSOCIATION__RELABELFROM, "relabelfrom")
S_(SECCLASS_ASSOCIATION, ASSOCIATION__RELABELTO, "relabelto")
2 changes: 2 additions & 0 deletions trunk/security/selinux/include/av_permissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@

#define ASSOCIATION__SENDTO 0x00000001UL
#define ASSOCIATION__RECVFROM 0x00000002UL
#define ASSOCIATION__RELABELFROM 0x00000004UL
#define ASSOCIATION__RELABELTO 0x00000008UL

#define NETLINK_KOBJECT_UEVENT_SOCKET__IOCTL 0x00000001UL
#define NETLINK_KOBJECT_UEVENT_SOCKET__READ 0x00000002UL
Expand Down
54 changes: 54 additions & 0 deletions trunk/security/selinux/include/xfrm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* SELinux support for the XFRM LSM hooks
*
* Author : Trent Jaeger, <jaegert@us.ibm.com>
*/
#ifndef _SELINUX_XFRM_H_
#define _SELINUX_XFRM_H_

int selinux_xfrm_policy_alloc(struct xfrm_policy *xp, struct xfrm_user_sec_ctx *sec_ctx);
int selinux_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new);
void selinux_xfrm_policy_free(struct xfrm_policy *xp);
int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx);
void selinux_xfrm_state_free(struct xfrm_state *x);
int selinux_xfrm_policy_lookup(struct xfrm_policy *xp, u32 sk_sid, u8 dir);

/*
* Extract the security blob from the sock (it's actually on the socket)
*/
static inline struct inode_security_struct *get_sock_isec(struct sock *sk)
{
if (!sk->sk_socket)
return NULL;

return SOCK_INODE(sk->sk_socket)->i_security;
}


static inline u32 selinux_no_sk_sid(struct flowi *fl)
{
/* NOTE: no sock occurs on ICMP reply, forwards, ... */
/* icmp_reply: authorize as kernel packet */
if (fl && fl->proto == IPPROTO_ICMP) {
return SECINITSID_KERNEL;
}

return SECINITSID_ANY_SOCKET;
}

#ifdef CONFIG_SECURITY_NETWORK_XFRM
int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb);
int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb);
#else
static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb)
{
return 0;
}

static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb)
{
return NF_ACCEPT;
}
#endif

#endif /* _SELINUX_XFRM_H_ */
Loading

0 comments on commit 4214f07

Please sign in to comment.