Skip to content

Commit cde3b1b

Browse files
cgzonespcmoore
authored andcommitted
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 c350f8b ("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: c350f8b ("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>
1 parent e6fb56b commit cde3b1b

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

security/selinux/ibpkey.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int sel_ib_pkey_sid_slow(u64 subnet_prefix, u16 pkey_num, u32 *sid)
130130
{
131131
int ret;
132132
struct sel_ib_pkey *pkey;
133-
struct sel_ib_pkey *new = NULL;
133+
struct sel_ib_pkey *new;
134134
unsigned long flags;
135135

136136
spin_lock_irqsave(&sel_ib_pkey_lock, flags);
@@ -146,12 +146,11 @@ static int sel_ib_pkey_sid_slow(u64 subnet_prefix, u16 pkey_num, u32 *sid)
146146
if (ret)
147147
goto out;
148148

149-
/* If this memory allocation fails still return 0. The SID
150-
* is valid, it just won't be added to the cache.
151-
*/
152-
new = kzalloc(sizeof(*new), GFP_ATOMIC);
149+
new = kmalloc(sizeof(*new), GFP_ATOMIC);
153150
if (!new) {
154-
ret = -ENOMEM;
151+
/* If this memory allocation fails still return 0. The SID
152+
* is valid, it just won't be added to the cache.
153+
*/
155154
goto out;
156155
}
157156

security/selinux/netif.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ static int sel_netif_sid_slow(struct net *ns, int ifindex, u32 *sid)
156156
ret = security_netif_sid(dev->name, sid);
157157
if (ret != 0)
158158
goto out;
159-
new = kzalloc(sizeof(*new), GFP_ATOMIC);
159+
160+
/* If this memory allocation fails still return 0. The SID
161+
* is valid, it just won't be added to the cache.
162+
*/
163+
new = kmalloc(sizeof(*new), GFP_ATOMIC);
160164
if (new) {
161165
new->nsec.ns = ns;
162166
new->nsec.ifindex = ifindex;

security/selinux/netnode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ static int sel_netnode_sid_slow(const void *addr, u16 family, u32 *sid)
201201
return 0;
202202
}
203203

204-
new = kzalloc(sizeof(*new), GFP_ATOMIC);
204+
/* If this memory allocation fails still return 0. The SID
205+
* is valid, it just won't be added to the cache.
206+
*/
207+
new = kmalloc(sizeof(*new), GFP_ATOMIC);
205208
switch (family) {
206209
case PF_INET:
207210
ret = security_node_sid(PF_INET,

security/selinux/netport.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ static int sel_netport_sid_slow(u8 protocol, u16 pnum, u32 *sid)
151151
ret = security_port_sid(protocol, pnum, sid);
152152
if (ret != 0)
153153
goto out;
154-
new = kzalloc(sizeof(*new), GFP_ATOMIC);
154+
155+
/* If this memory allocation fails still return 0. The SID
156+
* is valid, it just won't be added to the cache.
157+
*/
158+
new = kmalloc(sizeof(*new), GFP_ATOMIC);
155159
if (new) {
156160
new->psec.port = pnum;
157161
new->psec.protocol = protocol;

0 commit comments

Comments
 (0)