blob: b43813c9e049c9491cd37283c5f45bf494a6efcd [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
Paul Moore03e1ad72008-04-12 19:07:52 -070010int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
11 struct xfrm_user_sec_ctx *sec_ctx);
12int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
13 struct xfrm_sec_ctx **new_ctxp);
14void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
15int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070016int selinux_xfrm_state_alloc(struct xfrm_state *x,
Venkat Yekkiralac1a856c2006-11-08 17:03:44 -060017 struct xfrm_user_sec_ctx *sec_ctx, u32 secid);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080018void selinux_xfrm_state_free(struct xfrm_state *x);
Catherine Zhangc8c05a82006-06-08 23:39:49 -070019int selinux_xfrm_state_delete(struct xfrm_state *x);
Paul Moore03e1ad72008-04-12 19:07:52 -070020int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070021int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
David S. Millere33f7702011-02-22 18:13:15 -080022 struct xfrm_policy *xp, const struct flowi *fl);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080023
24/*
25 * Extract the security blob from the sock (it's actually on the socket)
26 */
27static inline struct inode_security_struct *get_sock_isec(struct sock *sk)
28{
29 if (!sk->sk_socket)
30 return NULL;
31
32 return SOCK_INODE(sk->sk_socket)->i_security;
33}
34
Trent Jaegerd28d1e02005-12-13 23:12:40 -080035#ifdef CONFIG_SECURITY_NETWORK_XFRM
Paul Moored621d352008-01-29 08:43:36 -050036extern atomic_t selinux_xfrm_refcount;
37
38static inline int selinux_xfrm_enabled(void)
39{
40 return (atomic_read(&selinux_xfrm_refcount) > 0);
41}
42
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070043int selinux_xfrm_sock_rcv_skb(u32 sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040044 struct common_audit_data *ad);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070045int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040046 struct common_audit_data *ad, u8 proto);
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070047int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080048
49static inline void selinux_xfrm_notify_policyload(void)
50{
51 atomic_inc(&flow_cache_genid);
52}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080053#else
Paul Moored621d352008-01-29 08:43:36 -050054static inline int selinux_xfrm_enabled(void)
55{
56 return 0;
57}
58
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070059static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040060 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080061{
62 return 0;
63}
64
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070065static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040066 struct common_audit_data *ad, u8 proto)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080067{
James Morris4e5ab4c2006-06-09 00:33:33 -070068 return 0;
Trent Jaegerd28d1e02005-12-13 23:12:40 -080069}
Catherine Zhange6f50712006-03-20 22:49:00 -080070
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070071static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
72{
73 *sid = SECSID_NULL;
74 return 0;
75}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080076
77static inline void selinux_xfrm_notify_policyload(void)
78{
79}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080080#endif
81
Venkat Yekkirala6b877692006-11-08 17:04:09 -060082static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
83{
84 int err = selinux_xfrm_decode_session(skb, sid, 0);
85 BUG_ON(err);
86}
87
Trent Jaegerd28d1e02005-12-13 23:12:40 -080088#endif /* _SELINUX_XFRM_H_ */