blob: 74159400eeee7a43ade2000440620f0392b0de85 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Trent Jaegerd28d1e02005-12-13 23:12:40 -08002/*
3 * SELinux support for the XFRM LSM hooks
4 *
5 * Author : Trent Jaeger, <jaegert@us.ibm.com>
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -07006 * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com>
Trent Jaegerd28d1e02005-12-13 23:12:40 -08007 */
8#ifndef _SELINUX_XFRM_H_
9#define _SELINUX_XFRM_H_
10
David Howells778aae82012-03-26 16:38:47 +010011#include <net/flow.h>
12
Paul Moore03e1ad72008-04-12 19:07:52 -070013int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
Nikolay Aleksandrov52a4c642014-03-07 12:44:19 +010014 struct xfrm_user_sec_ctx *uctx,
15 gfp_t gfp);
Paul Moore03e1ad72008-04-12 19:07:52 -070016int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
17 struct xfrm_sec_ctx **new_ctxp);
18void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
19int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070020int selinux_xfrm_state_alloc(struct xfrm_state *x,
Paul Moore2e5aa862013-07-23 17:38:38 -040021 struct xfrm_user_sec_ctx *uctx);
22int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,
23 struct xfrm_sec_ctx *polsec, u32 secid);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080024void selinux_xfrm_state_free(struct xfrm_state *x);
Catherine Zhangc8c05a82006-06-08 23:39:49 -070025int selinux_xfrm_state_delete(struct xfrm_state *x);
Zhongjun Tan8a922802021-04-09 13:48:41 +080026int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid);
Venkat Yekkiralae0d1caa2006-07-24 23:29:07 -070027int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x,
Paul Moored1b17b02013-07-23 17:38:40 -040028 struct xfrm_policy *xp,
Paul Moore3df98d72020-09-27 22:38:26 -040029 const struct flowi_common *flic);
Trent Jaegerd28d1e02005-12-13 23:12:40 -080030
Trent Jaegerd28d1e02005-12-13 23:12:40 -080031#ifdef CONFIG_SECURITY_NETWORK_XFRM
Paul Moored621d352008-01-29 08:43:36 -050032extern atomic_t selinux_xfrm_refcount;
33
34static inline int selinux_xfrm_enabled(void)
35{
36 return (atomic_read(&selinux_xfrm_refcount) > 0);
37}
38
Paul Mooreeef9b412013-07-23 17:38:39 -040039int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,
40 struct common_audit_data *ad);
41int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
42 struct common_audit_data *ad, u8 proto);
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070043int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
Paul Moore817eff72013-12-10 14:57:54 -050044int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080045
46static inline void selinux_xfrm_notify_policyload(void)
47{
fan.duca4c3fc2013-07-30 08:33:53 +080048 struct net *net;
49
Kirill Tkhaif0b07bb12018-03-29 19:20:32 +030050 down_read(&net_rwsem);
Florian Westphal09c75702017-07-17 13:57:26 +020051 for_each_net(net)
fan.duca4c3fc2013-07-30 08:33:53 +080052 rt_genid_bump_all(net);
Kirill Tkhaif0b07bb12018-03-29 19:20:32 +030053 up_read(&net_rwsem);
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080054}
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
Paul Mooreeef9b412013-07-23 17:38:39 -040061static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb,
62 struct common_audit_data *ad)
Trent Jaegerd28d1e02005-12-13 23:12:40 -080063{
64 return 0;
65}
66
Paul Mooreeef9b412013-07-23 17:38:39 -040067static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb,
68 struct common_audit_data *ad,
69 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
Paul Moored1b17b02013-07-23 17:38:40 -040074static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid,
75 int ckall)
Venkat Yekkiralaa51c64f2006-07-27 22:01:34 -070076{
77 *sid = SECSID_NULL;
78 return 0;
79}
Venkat Yekkirala342a0cf2007-01-26 19:03:48 -080080
81static inline void selinux_xfrm_notify_policyload(void)
82{
83}
Trent Jaegerd28d1e02005-12-13 23:12:40 -080084
Paul Moore817eff72013-12-10 14:57:54 -050085static inline int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid)
Venkat Yekkirala6b877692006-11-08 17:04:09 -060086{
Paul Moore817eff72013-12-10 14:57:54 -050087 *sid = SECSID_NULL;
88 return 0;
Venkat Yekkirala6b877692006-11-08 17:04:09 -060089}
Paul Moore817eff72013-12-10 14:57:54 -050090#endif
Venkat Yekkirala6b877692006-11-08 17:04:09 -060091
Trent Jaegerd28d1e02005-12-13 23:12:40 -080092#endif /* _SELINUX_XFRM_H_ */