blob: 65f67cb0aefb22f323d8048c140417555c273c9d [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{
53 atomic_inc(&flow_cache_genid);
Nicolas Dichtelee8372d2012-09-10 22:09:45 +000054 rt_genid_bump(&init_net);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080055}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080056#else
Paul Moored621d352008-01-29 08:43:36 -050057static inline int selinux_xfrm_enabled(void)
58{
59 return 0;
60}
61
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070062static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040063 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080064{
65 return 0;
66}
67
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070068static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040069 struct common_audit_data *ad, u8 proto)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080070{
James Morris4e5ab4c2006-06-09 00:33:33 -070071 return 0;
Trent Jaegerd28d1e02005-12-13 23:12:40 -080072}
Catherine Zhange6f50712006-03-20 22:49:00 -080073
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070074static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
75{
76 *sid = SECSID_NULL;
77 return 0;
78}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080079
80static inline void selinux_xfrm_notify_policyload(void)
81{
82}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080083#endif
84
Venkat Yekkirala6b877692006-11-08 17:04:09 -060085static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
86{
87 int err = selinux_xfrm_decode_session(skb, sid, 0);
88 BUG_ON(err);
89}
90
Trent Jaegerd28d1e02005-12-13 23:12:40 -080091#endif /* _SELINUX_XFRM_H_ */