blob: 6713f04e30ba8810415f88f7ed6e78cb5685f6f4 [file] [log] [blame]
Trent Jaegerd28d1e02005-12-13 23:12:40 -08001/*
2 * SELinux support for the XFRM LSM hooks
3 *
4 * Author : Trent Jaeger, <jaegert@us.ibm.com>
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07005 * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com>
Trent Jaegerd28d1e02005-12-13 23:12:40 -08006 */
7#ifndef _SELINUX_XFRM_H_
8#define _SELINUX_XFRM_H_
9
David Howells778aae82012-03-26 16:38:47 +010010#include <net/flow.h>
11
Paul Moore03e1ad72008-04-12 19:07:52 -070012int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
13 struct xfrm_user_sec_ctx *sec_ctx);
14int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
15 struct xfrm_sec_ctx **new_ctxp);
16void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
17int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070018int selinux_xfrm_state_alloc(struct xfrm_state *x,
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -060019 struct xfrm_user_sec_ctx *sec_ctx, u32 secid);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080020void selinux_xfrm_state_free(struct xfrm_state *x);
Catherine Zhangc8c05a82006-06-08 23:39:49 -070021int selinux_xfrm_state_delete(struct xfrm_state *x);
Paul Moore03e1ad72008-04-12 19:07:52 -070022int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070023int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
David S. Millere33f7702011-02-22 18:13:15 -080024 struct xfrm_policy *xp, const struct flowi *fl);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080025
26/*
27 * Extract the security blob from the sock (it's actually on the socket)
28 */
29static inline struct inode_security_struct *get_sock_isec(struct sock *sk)
30{
31 if (!sk->sk_socket)
32 return NULL;
33
34 return SOCK_INODE(sk->sk_socket)->i_security;
35}
36
Trent Jaegerd28d1e02005-12-13 23:12:40 -080037#ifdef CONFIG_SECURITY_NETWORK_XFRM
Paul Moored621d352008-01-29 08:43:36 -050038extern atomic_t selinux_xfrm_refcount;
39
40static inline int selinux_xfrm_enabled(void)
41{
42 return (atomic_read(&selinux_xfrm_refcount) > 0);
43}
44
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070045int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040046 struct common_audit_data *ad);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070047int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040048 struct common_audit_data *ad, u8 proto);
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070049int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080050
51static inline void selinux_xfrm_notify_policyload(void)
52{
fan.duca4c3fc2013-07-30 08:33:53 +080053 struct net *net;
54
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080055 atomic_inc(&flow_cache_genid);
fan.duca4c3fc2013-07-30 08:33:53 +080056 rtnl_lock();
57 for_each_net(net)
58 rt_genid_bump_all(net);
59 rtnl_unlock();
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080060}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080061#else
Paul Moored621d352008-01-29 08:43:36 -050062static inline int selinux_xfrm_enabled(void)
63{
64 return 0;
65}
66
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070067static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040068 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080069{
70 return 0;
71}
72
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070073static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040074 struct common_audit_data *ad, u8 proto)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080075{
James Morris4e5ab4c2006-06-09 00:33:33 -070076 return 0;
Trent Jaegerd28d1e02005-12-13 23:12:40 -080077}
Catherine Zhange6f50712006-03-20 22:49:00 -080078
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070079static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
80{
81 *sid = SECSID_NULL;
82 return 0;
83}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080084
85static inline void selinux_xfrm_notify_policyload(void)
86{
87}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080088#endif
89
Venkat Yekkirala6b877692006-11-08 17:04:09 -060090static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
91{
92 int err = selinux_xfrm_decode_session(skb, sid, 0);
93 BUG_ON(err);
94}
95
Trent Jaegerd28d1e02005-12-13 23:12:40 -080096#endif /* _SELINUX_XFRM_H_ */