summaryrefslogtreecommitdiffstats
path: root/security/selinux/netnode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-09-23 14:21:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-23 14:21:04 -0400
commit5825a95fe92566ada2292a65de030850b5cff1da (patch)
tree8e210a297844f6e07e0acb6ee793036a2c692976 /security/selinux/netnode.c
parent3c6a6910a81eae3566bb5fef6ea0f624382595e6 (diff)
parent15322a0d90b6fd62ae8f22e5b87f735c3fdfeff7 (diff)
Merge tag 'selinux-pr-20190917' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: - Add LSM hooks, and SELinux access control hooks, for dnotify, fanotify, and inotify watches. This has been discussed with both the LSM and fs/notify folks and everybody is good with these new hooks. - The LSM stacking changes missed a few calls to current_security() in the SELinux code; we fix those and remove current_security() for good. - Improve our network object labeling cache so that we always return the object's label, even when under memory pressure. Previously we would return an error if we couldn't allocate a new cache entry, now we always return the label even if we can't create a new cache entry for it. - Convert the sidtab atomic_t counter to a normal u32 with READ/WRITE_ONCE() and memory barrier protection. - A few patches to policydb.c to clean things up (remove forward declarations, long lines, bad variable names, etc) * tag 'selinux-pr-20190917' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: lsm: remove current_security() selinux: fix residual uses of current_security() for the SELinux blob selinux: avoid atomic_t usage in sidtab fanotify, inotify, dnotify, security: add security hook for fs notifications selinux: always return a secid from the network caches if we find one selinux: policydb - rename type_val_to_struct_array selinux: policydb - fix some checkpatch.pl warnings selinux: shuffle around policydb.c to get rid of forward declarations
Diffstat (limited to 'security/selinux/netnode.c')
-rw-r--r--security/selinux/netnode.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/security/selinux/netnode.c b/security/selinux/netnode.c
index cae1fcaffd1a..9ab84efa46c7 100644
--- a/security/selinux/netnode.c
+++ b/security/selinux/netnode.c
@@ -189,9 +189,9 @@ static void sel_netnode_insert(struct sel_netnode *node)
189 */ 189 */
190static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid) 190static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)
191{ 191{
192 int ret = -ENOMEM; 192 int ret;
193 struct sel_netnode *node; 193 struct sel_netnode *node;
194 struct sel_netnode *new = NULL; 194 struct sel_netnode *new;
195 195
196 spin_lock_bh(&sel_netnode_lock); 196 spin_lock_bh(&sel_netnode_lock);
197 node = sel_netnode_find(addr, family); 197 node = sel_netnode_find(addr, family);
@@ -200,38 +200,36 @@ static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)
200 spin_unlock_bh(&sel_netnode_lock); 200 spin_unlock_bh(&sel_netnode_lock);
201 return 0; 201 return 0;
202 } 202 }
203
203 new = kzalloc(sizeof(*new), GFP_ATOMIC); 204 new = kzalloc(sizeof(*new), GFP_ATOMIC);
204 if (new == NULL)
205 goto out;
206 switch (family) { 205 switch (family) {
207 case PF_INET: 206 case PF_INET:
208 ret = security_node_sid(&selinux_state, PF_INET, 207 ret = security_node_sid(&selinux_state, PF_INET,
209 addr, sizeof(struct in_addr), sid); 208 addr, sizeof(struct in_addr), sid);
210 new->nsec.addr.ipv4 = *(__be32 *)addr; 209 if (new)
210 new->nsec.addr.ipv4 = *(__be32 *)addr;
211 break; 211 break;
212 case PF_INET6: 212 case PF_INET6:
213 ret = security_node_sid(&selinux_state, PF_INET6, 213 ret = security_node_sid(&selinux_state, PF_INET6,
214 addr, sizeof(struct in6_addr), sid); 214 addr, sizeof(struct in6_addr), sid);
215 new->nsec.addr.ipv6 = *(struct in6_addr *)addr; 215 if (new)
216 new->nsec.addr.ipv6 = *(struct in6_addr *)addr;
216 break; 217 break;
217 default: 218 default:
218 BUG(); 219 BUG();
219 ret = -EINVAL; 220 ret = -EINVAL;
220 } 221 }
221 if (ret != 0) 222 if (ret == 0 && new) {
222 goto out; 223 new->nsec.family = family;
223 224 new->nsec.sid = *sid;
224 new->nsec.family = family; 225 sel_netnode_insert(new);
225 new->nsec.sid = *sid; 226 } else
226 sel_netnode_insert(new); 227 kfree(new);
227 228
228out:
229 spin_unlock_bh(&sel_netnode_lock); 229 spin_unlock_bh(&sel_netnode_lock);
230 if (unlikely(ret)) { 230 if (unlikely(ret))
231 pr_warn("SELinux: failure in %s(), unable to determine network node label\n", 231 pr_warn("SELinux: failure in %s(), unable to determine network node label\n",
232 __func__); 232 __func__);
233 kfree(new);
234 }
235 return ret; 233 return ret;
236} 234}
237 235