Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * SELinux support for the XFRM LSM hooks |
| 3 | * |
| 4 | * Author : Trent Jaeger, <jaegert@us.ibm.com> |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 5 | * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com> |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 6 | */ |
| 7 | #ifndef _SELINUX_XFRM_H_ |
| 8 | #define _SELINUX_XFRM_H_ |
| 9 | |
David Howells | 778aae8 | 2012-03-26 16:38:47 +0100 | [diff] [blame] | 10 | #include <net/flow.h> |
| 11 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 12 | int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, |
| 13 | struct xfrm_user_sec_ctx *sec_ctx); |
| 14 | int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
| 15 | struct xfrm_sec_ctx **new_ctxp); |
| 16 | void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); |
| 17 | int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 18 | int selinux_xfrm_state_alloc(struct xfrm_state *x, |
Paul Moore | 2e5aa86 | 2013-07-23 17:38:38 -0400 | [diff] [blame] | 19 | struct xfrm_user_sec_ctx *uctx); |
| 20 | int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x, |
| 21 | struct xfrm_sec_ctx *polsec, u32 secid); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 22 | void selinux_xfrm_state_free(struct xfrm_state *x); |
Catherine Zhang | c8c05a8 | 2006-06-08 23:39:49 -0700 | [diff] [blame] | 23 | int selinux_xfrm_state_delete(struct xfrm_state *x); |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 24 | int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 25 | int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x, |
David S. Miller | e33f770 | 2011-02-22 18:13:15 -0800 | [diff] [blame] | 26 | struct xfrm_policy *xp, const struct flowi *fl); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Extract the security blob from the sock (it's actually on the socket) |
| 30 | */ |
| 31 | static inline struct inode_security_struct *get_sock_isec(struct sock *sk) |
| 32 | { |
| 33 | if (!sk->sk_socket) |
| 34 | return NULL; |
| 35 | |
| 36 | return SOCK_INODE(sk->sk_socket)->i_security; |
| 37 | } |
| 38 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 40 | extern atomic_t selinux_xfrm_refcount; |
| 41 | |
| 42 | static inline int selinux_xfrm_enabled(void) |
| 43 | { |
| 44 | return (atomic_read(&selinux_xfrm_refcount) > 0); |
| 45 | } |
| 46 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame^] | 47 | int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 48 | struct common_audit_data *ad); |
| 49 | int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 50 | struct common_audit_data *ad, u8 proto); |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 51 | int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 52 | |
| 53 | static inline void selinux_xfrm_notify_policyload(void) |
| 54 | { |
| 55 | atomic_inc(&flow_cache_genid); |
Nicolas Dichtel | ee8372d | 2012-09-10 22:09:45 +0000 | [diff] [blame] | 56 | rt_genid_bump(&init_net); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 57 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 58 | #else |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 59 | static inline int selinux_xfrm_enabled(void) |
| 60 | { |
| 61 | return 0; |
| 62 | } |
| 63 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame^] | 64 | static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 65 | struct common_audit_data *ad) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame^] | 70 | static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 71 | struct common_audit_data *ad, |
| 72 | u8 proto) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 73 | { |
James Morris | 4e5ab4c | 2006-06-09 00:33:33 -0700 | [diff] [blame] | 74 | return 0; |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 75 | } |
Catherine Zhang | e6f5071 | 2006-03-20 22:49:00 -0800 | [diff] [blame] | 76 | |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 77 | static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall) |
| 78 | { |
| 79 | *sid = SECSID_NULL; |
| 80 | return 0; |
| 81 | } |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 82 | |
| 83 | static inline void selinux_xfrm_notify_policyload(void) |
| 84 | { |
| 85 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 86 | #endif |
| 87 | |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 88 | static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid) |
| 89 | { |
| 90 | int err = selinux_xfrm_decode_session(skb, sid, 0); |
| 91 | BUG_ON(err); |
| 92 | } |
| 93 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 94 | #endif /* _SELINUX_XFRM_H_ */ |