summaryrefslogtreecommitdiff
path: root/security/selinux/netif.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2025-03-18 09:33:32 +0100
committerPaul Moore <paul@paul-moore.com>2025-04-11 16:29:51 -0400
commitcde3b1b66f2de9eba3ce1beadb91739d803a1018 (patch)
tree240f1e23fe5076588436059e4b17b5ba23f5a9ae /security/selinux/netif.c
parente6fb56b2253d49d192d4fe790698462d5422c041 (diff)
selinux: unify OOM handling in network hashtables
For network objects, like interfaces, nodes, port and InfiniBands, the object to SID lookup is cached in hashtables. OOM during such hashtable additions of new objects is considered non-fatal and the computed SID is simply returned without adding the compute result into the hash table. Actually ignore OOM in the InfiniBand code, despite the comment already suggesting to do so. This reverts commit c350f8bea271 ("selinux: Fix error return code in sel_ib_pkey_sid_slow()"). Add comments in the other places. Use kmalloc() instead of kzalloc(), since all members are initialized on success and the data is only used in internbal hash tables, so no risk of information leakage to userspace. Fixes: c350f8bea271 ("selinux: Fix error return code in sel_ib_pkey_sid_slow()") Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security/selinux/netif.c')
-rw-r--r--security/selinux/netif.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/security/selinux/netif.c b/security/selinux/netif.c
index 43a0d3594b72..78afbecdbe57 100644
--- a/security/selinux/netif.c
+++ b/security/selinux/netif.c
@@ -156,7 +156,11 @@ static int sel_netif_sid_slow(struct net *ns, int ifindex, u32 *sid)
ret = security_netif_sid(dev->name, sid);
if (ret != 0)
goto out;
- new = kzalloc(sizeof(*new), GFP_ATOMIC);
+
+ /* If this memory allocation fails still return 0. The SID
+ * is valid, it just won't be added to the cache.
+ */
+ new = kmalloc(sizeof(*new), GFP_ATOMIC);
if (new) {
new->nsec.ns = ns;
new->nsec.ifindex = ifindex;