diff options
author | Trent Jaeger <tjaeger@cse.psu.edu> | 2005-12-14 02:12:40 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-01-03 16:10:25 -0500 |
commit | d28d1e080132f28ab773291f10ad6acca4c8bba2 (patch) | |
tree | 4cc6abef076393bc4c9f0d4e4c9952b78c04d3ee /security/selinux/hooks.c | |
parent | df71837d5024e2524cd51c93621e558aa7dd9f3f (diff) |
[LSM-IPSec]: Per-packet access control.
This patch series implements per packet access control via the
extension of the Linux Security Modules (LSM) interface by hooks in
the XFRM and pfkey subsystems that leverage IPSec security
associations to label packets. Extensions to the SELinux LSM are
included that leverage the patch for this purpose.
This patch implements the changes necessary to the SELinux LSM to
create, deallocate, and use security contexts for policies
(xfrm_policy) and security associations (xfrm_state) that enable
control of a socket's ability to send and receive packets.
Patch purpose:
The patch is designed to enable the SELinux LSM to implement access
control on individual packets based on the strongly authenticated
IPSec security association. Such access controls augment the existing
ones in SELinux based on network interface and IP address. The former
are very coarse-grained, and the latter can be spoofed. By using
IPSec, the SELinux can control access to remote hosts based on
cryptographic keys generated using the IPSec mechanism. This enables
access control on a per-machine basis or per-application if the remote
machine is running the same mechanism and trusted to enforce the
access control policy.
Patch design approach:
The patch's main function is to authorize a socket's access to a IPSec
policy based on their security contexts. Since the communication is
implemented by a security association, the patch ensures that the
security association's negotiated and used have the same security
context. The patch enables allocation and deallocation of such
security contexts for policies and security associations. It also
enables copying of the security context when policies are cloned.
Lastly, the patch ensures that packets that are sent without using a
IPSec security assocation with a security context are allowed to be
sent in that manner.
A presentation available at
www.selinux-symposium.org/2005/presentations/session2/2-3-jaeger.pdf
from the SELinux symposium describes the overall approach.
Patch implementation details:
The function which authorizes a socket to perform a requested
operation (send/receive) on a IPSec policy (xfrm_policy) is
selinux_xfrm_policy_lookup. The Netfilter and rcv_skb hooks ensure
that if a IPSec SA with a securit y association has not been used,
then the socket is allowed to send or receive the packet,
respectively.
The patch implements SELinux function for allocating security contexts
when policies (xfrm_policy) are created via the pfkey or xfrm_user
interfaces via selinux_xfrm_policy_alloc. When a security association
is built, SELinux allocates the security context designated by the
XFRM subsystem which is based on that of the authorized policy via
selinux_xfrm_state_alloc.
When a xfrm_policy is cloned, the security context of that policy, if
any, is copied to the clone via selinux_xfrm_policy_clone.
When a xfrm_policy or xfrm_state is freed, its security context, if
any is also freed at selinux_xfrm_policy_free or
selinux_xfrm_state_free.
Testing:
The SELinux authorization function is tested using ipsec-tools. We
created policies and security associations with particular security
contexts and added SELinux access control policy entries to verify the
authorization decision. We also made sure that packets for which no
security context was supplied (which either did or did not use
security associations) were authorized using an unlabelled context.
Signed-off-by: Trent Jaeger <tjaeger@cse.psu.edu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fc774436a264..3d496eae1b47 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -73,6 +73,7 @@ | |||
73 | #include "avc.h" | 73 | #include "avc.h" |
74 | #include "objsec.h" | 74 | #include "objsec.h" |
75 | #include "netif.h" | 75 | #include "netif.h" |
76 | #include "xfrm.h" | ||
76 | 77 | ||
77 | #define XATTR_SELINUX_SUFFIX "selinux" | 78 | #define XATTR_SELINUX_SUFFIX "selinux" |
78 | #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX | 79 | #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX |
@@ -3349,6 +3350,10 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |||
3349 | err = avc_has_perm(sock_sid, port_sid, | 3350 | err = avc_has_perm(sock_sid, port_sid, |
3350 | sock_class, recv_perm, &ad); | 3351 | sock_class, recv_perm, &ad); |
3351 | } | 3352 | } |
3353 | |||
3354 | if (!err) | ||
3355 | err = selinux_xfrm_sock_rcv_skb(sock_sid, skb); | ||
3356 | |||
3352 | out: | 3357 | out: |
3353 | return err; | 3358 | return err; |
3354 | } | 3359 | } |
@@ -3401,6 +3406,24 @@ static void selinux_sk_free_security(struct sock *sk) | |||
3401 | sk_free_security(sk); | 3406 | sk_free_security(sk); |
3402 | } | 3407 | } |
3403 | 3408 | ||
3409 | static unsigned int selinux_sk_getsid_security(struct sock *sk, struct flowi *fl, u8 dir) | ||
3410 | { | ||
3411 | struct inode_security_struct *isec; | ||
3412 | u32 sock_sid = SECINITSID_ANY_SOCKET; | ||
3413 | |||
3414 | if (!sk) | ||
3415 | return selinux_no_sk_sid(fl); | ||
3416 | |||
3417 | read_lock_bh(&sk->sk_callback_lock); | ||
3418 | isec = get_sock_isec(sk); | ||
3419 | |||
3420 | if (isec) | ||
3421 | sock_sid = isec->sid; | ||
3422 | |||
3423 | read_unlock_bh(&sk->sk_callback_lock); | ||
3424 | return sock_sid; | ||
3425 | } | ||
3426 | |||
3404 | static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) | 3427 | static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb) |
3405 | { | 3428 | { |
3406 | int err = 0; | 3429 | int err = 0; |
@@ -3536,6 +3559,11 @@ static unsigned int selinux_ip_postroute_last(unsigned int hooknum, | |||
3536 | send_perm, &ad) ? NF_DROP : NF_ACCEPT; | 3559 | send_perm, &ad) ? NF_DROP : NF_ACCEPT; |
3537 | } | 3560 | } |
3538 | 3561 | ||
3562 | if (err != NF_ACCEPT) | ||
3563 | goto out; | ||
3564 | |||
3565 | err = selinux_xfrm_postroute_last(isec->sid, skb); | ||
3566 | |||
3539 | out: | 3567 | out: |
3540 | return err; | 3568 | return err; |
3541 | } | 3569 | } |
@@ -4380,6 +4408,16 @@ static struct security_operations selinux_ops = { | |||
4380 | .socket_getpeersec = selinux_socket_getpeersec, | 4408 | .socket_getpeersec = selinux_socket_getpeersec, |
4381 | .sk_alloc_security = selinux_sk_alloc_security, | 4409 | .sk_alloc_security = selinux_sk_alloc_security, |
4382 | .sk_free_security = selinux_sk_free_security, | 4410 | .sk_free_security = selinux_sk_free_security, |
4411 | .sk_getsid = selinux_sk_getsid_security, | ||
4412 | #endif | ||
4413 | |||
4414 | #ifdef CONFIG_SECURITY_NETWORK_XFRM | ||
4415 | .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc, | ||
4416 | .xfrm_policy_clone_security = selinux_xfrm_policy_clone, | ||
4417 | .xfrm_policy_free_security = selinux_xfrm_policy_free, | ||
4418 | .xfrm_state_alloc_security = selinux_xfrm_state_alloc, | ||
4419 | .xfrm_state_free_security = selinux_xfrm_state_free, | ||
4420 | .xfrm_policy_lookup = selinux_xfrm_policy_lookup, | ||
4383 | #endif | 4421 | #endif |
4384 | }; | 4422 | }; |
4385 | 4423 | ||
@@ -4491,6 +4529,7 @@ static int __init selinux_nf_ip_init(void) | |||
4491 | panic("SELinux: nf_register_hook for IPv6: error %d\n", err); | 4529 | panic("SELinux: nf_register_hook for IPv6: error %d\n", err); |
4492 | 4530 | ||
4493 | #endif /* IPV6 */ | 4531 | #endif /* IPV6 */ |
4532 | |||
4494 | out: | 4533 | out: |
4495 | return err; | 4534 | return err; |
4496 | } | 4535 | } |