blob: c220f314709cc1345792e4a4ddab28cd63a23177 [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);
54}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080055#else
Paul Moored621d352008-01-29 08:43:36 -050056static inline int selinux_xfrm_enabled(void)
57{
58 return 0;
59}
60
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070061static inline int selinux_xfrm_sock_rcv_skb(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040062 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080063{
64 return 0;
65}
66
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070067static inline int selinux_xfrm_postroute_last(u32 isec_sid, struct sk_buff *skb,
Thomas Liu2bf49692009-07-14 12:14:09 -040068 struct common_audit_data *ad, u8 proto)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080069{
James Morris4e5ab4c2006-06-09 00:33:33 -070070 return 0;
Trent Jaegerd28d1e02005-12-13 23:12:40 -080071}
Catherine Zhange6f50712006-03-20 22:49:00 -080072
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070073static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall)
74{
75 *sid = SECSID_NULL;
76 return 0;
77}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080078
79static inline void selinux_xfrm_notify_policyload(void)
80{
81}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080082#endif
83
Venkat Yekkirala6b877692006-11-08 17:04:09 -060084static inline void selinux_skb_xfrm_sid(struct sk_buff *skb, u32 *sid)
85{
86 int err = selinux_xfrm_decode_session(skb, sid, 0);
87 BUG_ON(err);
88}
89
Trent Jaegerd28d1e02005-12-13 23:12:40 -080090#endif /* _SELINUX_XFRM_H_ */