Skip to contentSkip to conversation

selinux: check for failed kmalloc in security_sid_to_context

PATCH In review Serge E. Hallyn 4 participants 4 messages Apr 27, 2006 – May 8, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: check for failed kmalloc in security_sid_to_context

Check for NULL kmalloc return value before writing to it.

---

 security/selinux/ss/services.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

3d9cf05c7fa2578f87648dd0862e70cf7959ad7a

security/selinux/ss/services.c +4 -0
index 6149248..20b1065 100644
@@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
 
 			*scontext_len = strlen(initial_sid_to_string[sid]) + 1;
 			scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
+			if (!scontextp) {
+				rc = -ENOMEM;
+				goto out;
+			}
 			strcpy(scontextp, initial_sid_to_string[sid]);
 			*scontext = scontextp;
 			goto out;
Signature · 1 line
1.3.0
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Serge E. Hallyn

Check for NULL kmalloc return value before writing to it.

Quoted 22 lines

---

 security/selinux/ss/services.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

3d9cf05c7fa2578f87648dd0862e70cf7959ad7a

security/selinux/ss/services.c +4 -0
index 6149248..20b1065 100644
@@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
 
 			*scontext_len = strlen(initial_sid_to_string[sid]) + 1;
 			scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
+			if (!scontextp) {
+				rc = -ENOMEM;
+				goto out;
+			}
 			strcpy(scontextp, initial_sid_to_string[sid]);
 			*scontext = scontextp;
 			goto out;
Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
Quoted 22 lines · James Morris
Quoted 3 lines · Serge E. Hallyn

Check for NULL kmalloc return value before writing to it.

Quoted 12 lines

---

 security/selinux/ss/services.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

3d9cf05c7fa2578f87648dd0862e70cf7959ad7a

security/selinux/ss/services.c +0 -0
index 6149248..20b1065 100644
@@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
 
Quoted 11 lines

security/selinux/ss/services.c int security_sid_to_context(u32 sid, cha · line 602

Quoted 10 lines
security/selinux/ss/services.c +4 -0
 			*scontext_len = strlen(initial_sid_to_string[sid]) + 1;
 			scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
+			if (!scontextp) {
+				rc = -ENOMEM;
+				goto out;
+			}
 			strcpy(scontextp, initial_sid_to_string[sid]);
 			*scontext = scontextp;
 			goto out;

Given that GFP_ATOMIC can fail and it'll cause an oops I'll queue this for 2.6.17 and shall send it in the direction of the -stable guys too, thanks.

What will happen when one of the GFP_ATOMIC allocations in there fails? Will the computer become insecure?

#3 lore raw
Quoted 35 lines · Andrew Morton
Quoted 22 lines · James Morris
Quoted 3 lines · Serge E. Hallyn

Check for NULL kmalloc return value before writing to it.

Quoted 12 lines

---

 security/selinux/ss/services.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

3d9cf05c7fa2578f87648dd0862e70cf7959ad7a

security/selinux/ss/services.c +0 -0
index 6149248..20b1065 100644
@@ -593,6 +593,10 @@ int security_sid_to_context(u32 sid, cha
 
Quoted 11 lines

security/selinux/ss/services.c int security_sid_to_context(u32 sid, cha · line 602

Quoted 10 lines
security/selinux/ss/services.c +4 -0
 			*scontext_len = strlen(initial_sid_to_string[sid]) + 1;
 			scontextp = kmalloc(*scontext_len,GFP_ATOMIC);
+			if (!scontextp) {
+				rc = -ENOMEM;
+				goto out;
+			}
 			strcpy(scontextp, initial_sid_to_string[sid]);
 			*scontext = scontextp;
 			goto out;
Quoted 2 lines

Given that GFP_ATOMIC can fail and it'll cause an oops I'll queue this for 2.6.17 and shall send it in the direction of the -stable guys too, thanks.

Note however that this can only occur prior to initial policy load by /sbin/init; after that, we don't follow that branch.

Quoted 2 lines

What will happen when one of the GFP_ATOMIC allocations in there fails? Will the computer become insecure?

No, it doesn't affect the access control enforcement. The caller just can't get the context string in that case, so in the case of the AVC or audit, it falls back to only logging the SID for later analysis. The audit people are interested in having a way to dump the kernel's SID table in that case, so we may end up exporting that via selinuxfs. In some other cases where we are returning the context to userspace, the program would get the ENOMEM error ultimately and have to retry when memory was available.

Signature · 2 lines
Stephen Smalley
National Security Agency