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, |
Nikolay Aleksandrov | 52a4c64 | 2014-03-07 12:44:19 +0100 | [diff] [blame] | 13 | struct xfrm_user_sec_ctx *uctx, |
| 14 | gfp_t gfp); |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 15 | int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
| 16 | struct xfrm_sec_ctx **new_ctxp); |
| 17 | void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); |
| 18 | int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 19 | int selinux_xfrm_state_alloc(struct xfrm_state *x, |
Paul Moore | 2e5aa86 | 2013-07-23 17:38:38 -0400 | [diff] [blame] | 20 | struct xfrm_user_sec_ctx *uctx); |
| 21 | int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x, |
| 22 | struct xfrm_sec_ctx *polsec, u32 secid); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 23 | void selinux_xfrm_state_free(struct xfrm_state *x); |
Catherine Zhang | c8c05a8 | 2006-06-08 23:39:49 -0700 | [diff] [blame] | 24 | int selinux_xfrm_state_delete(struct xfrm_state *x); |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 25 | 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] | 26 | int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x, |
Paul Moore | d1b17b0 | 2013-07-23 17:38:40 -0400 | [diff] [blame] | 27 | struct xfrm_policy *xp, |
| 28 | const struct flowi *fl); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 29 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 30 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 31 | extern atomic_t selinux_xfrm_refcount; |
| 32 | |
| 33 | static inline int selinux_xfrm_enabled(void) |
| 34 | { |
| 35 | return (atomic_read(&selinux_xfrm_refcount) > 0); |
| 36 | } |
| 37 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 38 | int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 39 | struct common_audit_data *ad); |
| 40 | int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 41 | struct common_audit_data *ad, u8 proto); |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 42 | int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall); |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 43 | int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 44 | |
| 45 | static inline void selinux_xfrm_notify_policyload(void) |
| 46 | { |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 47 | struct net *net; |
| 48 | |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 49 | rtnl_lock(); |
Fan Du | ca925cf | 2014-01-18 09:55:27 +0800 | [diff] [blame] | 50 | for_each_net(net) { |
| 51 | atomic_inc(&net->xfrm.flow_cache_genid); |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 52 | rt_genid_bump_all(net); |
Fan Du | ca925cf | 2014-01-18 09:55:27 +0800 | [diff] [blame] | 53 | } |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 54 | rtnl_unlock(); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 55 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 56 | #else |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 57 | static inline int selinux_xfrm_enabled(void) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 62 | static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 63 | struct common_audit_data *ad) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 64 | { |
| 65 | return 0; |
| 66 | } |
| 67 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 68 | static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 69 | struct common_audit_data *ad, |
| 70 | u8 proto) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 71 | { |
James Morris | 4e5ab4c | 2006-06-09 00:33:33 -0700 | [diff] [blame] | 72 | return 0; |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 73 | } |
Catherine Zhang | e6f5071 | 2006-03-20 22:49:00 -0800 | [diff] [blame] | 74 | |
Paul Moore | d1b17b0 | 2013-07-23 17:38:40 -0400 | [diff] [blame] | 75 | static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, |
| 76 | int ckall) |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 77 | { |
| 78 | *sid = SECSID_NULL; |
| 79 | return 0; |
| 80 | } |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 81 | |
| 82 | static inline void selinux_xfrm_notify_policyload(void) |
| 83 | { |
| 84 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 85 | |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 86 | static inline int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid) |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 87 | { |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 88 | *sid = SECSID_NULL; |
| 89 | return 0; |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 90 | } |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 91 | #endif |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 92 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 93 | #endif /* _SELINUX_XFRM_H_ */ |