Commit | Line | Data |
---|---|---|
7420ed23 VY |
1 | /* |
2 | * SELinux interface to the NetLabel subsystem | |
3 | * | |
4 | * Author : Paul Moore <paul.moore@hp.com> | |
5 | * | |
6 | */ | |
7 | ||
8 | /* | |
9 | * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
19 | * the GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | * | |
25 | */ | |
26 | ||
27 | #ifndef _SELINUX_NETLABEL_H_ | |
28 | #define _SELINUX_NETLABEL_H_ | |
29 | ||
30 | #ifdef CONFIG_NETLABEL | |
31 | void selinux_netlbl_cache_invalidate(void); | |
32 | int selinux_netlbl_socket_post_create(struct socket *sock, | |
33 | int sock_family, | |
34 | u32 sid); | |
35 | void selinux_netlbl_sock_graft(struct sock *sk, struct socket *sock); | |
36 | u32 selinux_netlbl_inet_conn_request(struct sk_buff *skb, u32 sock_sid); | |
37 | int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, | |
38 | struct sk_buff *skb, | |
39 | struct avc_audit_data *ad); | |
40 | u32 selinux_netlbl_socket_getpeersec_stream(struct socket *sock); | |
41 | u32 selinux_netlbl_socket_getpeersec_dgram(struct sk_buff *skb); | |
99f59ed0 PM |
42 | void selinux_netlbl_sk_security_init(struct sk_security_struct *ssec, |
43 | int family); | |
44 | void selinux_netlbl_sk_clone_security(struct sk_security_struct *ssec, | |
45 | struct sk_security_struct *newssec); | |
7420ed23 VY |
46 | |
47 | int __selinux_netlbl_inode_permission(struct inode *inode, int mask); | |
48 | /** | |
49 | * selinux_netlbl_inode_permission - Verify the socket is NetLabel labeled | |
50 | * @inode: the file descriptor's inode | |
51 | * @mask: the permission mask | |
52 | * | |
53 | * Description: | |
54 | * Looks at a file's inode and if it is marked as a socket protected by | |
55 | * NetLabel then verify that the socket has been labeled, if not try to label | |
56 | * the socket now with the inode's SID. Returns zero on success, negative | |
57 | * values on failure. | |
58 | * | |
59 | */ | |
60 | static inline int selinux_netlbl_inode_permission(struct inode *inode, | |
61 | int mask) | |
62 | { | |
63 | int rc = 0; | |
64 | struct inode_security_struct *isec; | |
65 | struct sk_security_struct *sksec; | |
66 | ||
67 | if (!S_ISSOCK(inode->i_mode)) | |
68 | return 0; | |
69 | ||
70 | isec = inode->i_security; | |
71 | sksec = SOCKET_I(inode)->sk->sk_security; | |
72 | down(&isec->sem); | |
73 | if (unlikely(sksec->nlbl_state == NLBL_REQUIRE && | |
74 | (mask & (MAY_WRITE | MAY_APPEND)))) | |
75 | rc = __selinux_netlbl_inode_permission(inode, mask); | |
76 | up(&isec->sem); | |
77 | ||
78 | return rc; | |
79 | } | |
80 | #else | |
81 | static inline void selinux_netlbl_cache_invalidate(void) | |
82 | { | |
83 | return; | |
84 | } | |
85 | ||
86 | static inline int selinux_netlbl_socket_post_create(struct socket *sock, | |
87 | int sock_family, | |
88 | u32 sid) | |
89 | { | |
90 | return 0; | |
91 | } | |
92 | ||
93 | static inline void selinux_netlbl_sock_graft(struct sock *sk, | |
94 | struct socket *sock) | |
95 | { | |
96 | return; | |
97 | } | |
98 | ||
99 | static inline u32 selinux_netlbl_inet_conn_request(struct sk_buff *skb, | |
100 | u32 sock_sid) | |
101 | { | |
102 | return SECSID_NULL; | |
103 | } | |
104 | ||
105 | static inline int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, | |
106 | struct sk_buff *skb, | |
107 | struct avc_audit_data *ad) | |
108 | { | |
109 | return 0; | |
110 | } | |
111 | ||
112 | static inline u32 selinux_netlbl_socket_getpeersec_stream(struct socket *sock) | |
113 | { | |
114 | return SECSID_NULL; | |
115 | } | |
116 | ||
117 | static inline u32 selinux_netlbl_socket_getpeersec_dgram(struct sk_buff *skb) | |
118 | { | |
119 | return SECSID_NULL; | |
120 | } | |
121 | ||
99f59ed0 PM |
122 | static inline void selinux_netlbl_sk_security_init( |
123 | struct sk_security_struct *ssec, | |
124 | int family) | |
125 | { | |
126 | return; | |
127 | } | |
128 | ||
129 | static inline void selinux_netlbl_sk_clone_security( | |
130 | struct sk_security_struct *ssec, | |
131 | struct sk_security_struct *newssec) | |
132 | { | |
133 | return; | |
134 | } | |
135 | ||
7420ed23 VY |
136 | static inline int selinux_netlbl_inode_permission(struct inode *inode, |
137 | int mask) | |
138 | { | |
139 | return 0; | |
140 | } | |
141 | #endif /* CONFIG_NETLABEL */ | |
142 | ||
143 | #endif |