Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 2 | /* |
| 3 | * SELinux support for the XFRM LSM hooks |
| 4 | * |
| 5 | * Author : Trent Jaeger, <jaegert@us.ibm.com> |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 6 | * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com> |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 7 | */ |
| 8 | #ifndef _SELINUX_XFRM_H_ |
| 9 | #define _SELINUX_XFRM_H_ |
| 10 | |
David Howells | 778aae8 | 2012-03-26 16:38:47 +0100 | [diff] [blame] | 11 | #include <net/flow.h> |
| 12 | |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 13 | int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, |
Nikolay Aleksandrov | 52a4c64 | 2014-03-07 12:44:19 +0100 | [diff] [blame] | 14 | struct xfrm_user_sec_ctx *uctx, |
| 15 | gfp_t gfp); |
Paul Moore | 03e1ad7 | 2008-04-12 19:07:52 -0700 | [diff] [blame] | 16 | int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, |
| 17 | struct xfrm_sec_ctx **new_ctxp); |
| 18 | void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); |
| 19 | int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 20 | int selinux_xfrm_state_alloc(struct xfrm_state *x, |
Paul Moore | 2e5aa86 | 2013-07-23 17:38:38 -0400 | [diff] [blame] | 21 | struct xfrm_user_sec_ctx *uctx); |
| 22 | int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x, |
| 23 | struct xfrm_sec_ctx *polsec, u32 secid); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 24 | void selinux_xfrm_state_free(struct xfrm_state *x); |
Catherine Zhang | c8c05a8 | 2006-06-08 23:39:49 -0700 | [diff] [blame] | 25 | int selinux_xfrm_state_delete(struct xfrm_state *x); |
Zhongjun Tan | 8a92280 | 2021-04-09 13:48:41 +0800 | [diff] [blame] | 26 | int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid); |
Venkat Yekkirala | e0d1caa | 2006-07-24 23:29:07 -0700 | [diff] [blame] | 27 | int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x, |
Paul Moore | d1b17b0 | 2013-07-23 17:38:40 -0400 | [diff] [blame] | 28 | struct xfrm_policy *xp, |
Paul Moore | 3df98d7 | 2020-09-27 22:38:26 -0400 | [diff] [blame] | 29 | const struct flowi_common *flic); |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 30 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 31 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 32 | extern atomic_t selinux_xfrm_refcount; |
| 33 | |
| 34 | static inline int selinux_xfrm_enabled(void) |
| 35 | { |
| 36 | return (atomic_read(&selinux_xfrm_refcount) > 0); |
| 37 | } |
| 38 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 39 | int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 40 | struct common_audit_data *ad); |
| 41 | int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 42 | struct common_audit_data *ad, u8 proto); |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 43 | 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] | 44 | int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 45 | |
| 46 | static inline void selinux_xfrm_notify_policyload(void) |
| 47 | { |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 48 | struct net *net; |
| 49 | |
Kirill Tkhai | f0b07bb1 | 2018-03-29 19:20:32 +0300 | [diff] [blame] | 50 | down_read(&net_rwsem); |
Florian Westphal | 09c7570 | 2017-07-17 13:57:26 +0200 | [diff] [blame] | 51 | for_each_net(net) |
fan.du | ca4c3fc | 2013-07-30 08:33:53 +0800 | [diff] [blame] | 52 | rt_genid_bump_all(net); |
Kirill Tkhai | f0b07bb1 | 2018-03-29 19:20:32 +0300 | [diff] [blame] | 53 | up_read(&net_rwsem); |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 54 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 55 | #else |
Paul Moore | d621d35 | 2008-01-29 08:43:36 -0500 | [diff] [blame] | 56 | static inline int selinux_xfrm_enabled(void) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 61 | static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, |
| 62 | struct common_audit_data *ad) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | |
Paul Moore | eef9b41 | 2013-07-23 17:38:39 -0400 | [diff] [blame] | 67 | static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, |
| 68 | struct common_audit_data *ad, |
| 69 | u8 proto) |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 70 | { |
James Morris | 4e5ab4c | 2006-06-09 00:33:33 -0700 | [diff] [blame] | 71 | return 0; |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 72 | } |
Catherine Zhang | e6f5071 | 2006-03-20 22:49:00 -0800 | [diff] [blame] | 73 | |
Paul Moore | d1b17b0 | 2013-07-23 17:38:40 -0400 | [diff] [blame] | 74 | static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, |
| 75 | int ckall) |
Venkat Yekkirala | a51c64f | 2006-07-27 22:01:34 -0700 | [diff] [blame] | 76 | { |
| 77 | *sid = SECSID_NULL; |
| 78 | return 0; |
| 79 | } |
Venkat Yekkirala | 342a0cf | 2007-01-26 19:03:48 -0800 | [diff] [blame] | 80 | |
| 81 | static inline void selinux_xfrm_notify_policyload(void) |
| 82 | { |
| 83 | } |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 84 | |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 85 | 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] | 86 | { |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 87 | *sid = SECSID_NULL; |
| 88 | return 0; |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 89 | } |
Paul Moore | 817eff7 | 2013-12-10 14:57:54 -0500 | [diff] [blame] | 90 | #endif |
Venkat Yekkirala | 6b87769 | 2006-11-08 17:04:09 -0600 | [diff] [blame] | 91 | |
Trent Jaeger | d28d1e0 | 2005-12-13 23:12:40 -0800 | [diff] [blame] | 92 | #endif /* _SELINUX_XFRM_H_ */ |