Skip to contentSkip to conversation

selinux: return -ENOMEM when memory allocation fails

PATCH In review Davidlohr Bueso 2 participants 4 messages Jan 20, 2011 – Jan 24, 2011 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 selinux: return -ENOMEM when memory allocation fails

From: Davidlohr Bueso <[email protected]>

---
 security/selinux/ss/conditional.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/selinux/ss/conditional.c +1 -1
index c3f845c..a533732 100644
@@ -178,7 +178,7 @@ int cond_init_bool_indexes(struct policydb *p)
 	p->bool_val_to_struct = (struct cond_bool_datum **)
 		kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
 	if (!p->bool_val_to_struct)
-		return -1;
+		return -ENOMEM;
 	return 0;
 }
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 12 lines · Davidlohr Bueso

From: Davidlohr Bueso <[email protected]>

---
 security/selinux/ss/conditional.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/selinux/ss/conditional.c +0 -0
index c3f845c..a533732 100644

security/selinux/ss/conditional.c int cond_init_bool_indexes(struct policydb *p) · line 182

Quoted 6 lines
security/selinux/ss/conditional.c +1 -1
@@ -178,7 +178,7 @@ int cond_init_bool_indexes(struct policydb *p)
 	p->bool_val_to_struct = (struct cond_bool_datum **)
 		kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
 	if (!p->bool_val_to_struct)
-		return -1;
+		return -ENOMEM;
 	return 0;

The caller has already set -ENOMEM, so the code should probably be updated there, too, e.g.

	rc = cond_init_bool_indexes();
	if (rc)
		goto out;
Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 24 lines · James Morris
Quoted 12 lines · Davidlohr Bueso

From: Davidlohr Bueso <[email protected]>

---
 security/selinux/ss/conditional.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/selinux/ss/conditional.c +0 -0
index c3f845c..a533732 100644

security/selinux/ss/conditional.c int cond_init_bool_indexes(struct policydb *p) · line 182

Quoted 6 lines
security/selinux/ss/conditional.c +1 -1
@@ -178,7 +178,7 @@ int cond_init_bool_indexes(struct policydb *p)
 	p->bool_val_to_struct = (struct cond_bool_datum **)
 		kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
 	if (!p->bool_val_to_struct)
-		return -1;
+		return -ENOMEM;
 	return 0;

The caller has already set -ENOMEM, so the code should probably be updated there, too, e.g.

Quoted 3 lines
	rc = cond_init_bool_indexes();
	if (rc)
		goto out;

Ah yes, thanks for pointing this out.

From: Davidlohr Bueso <[email protected]>
Date: Fri, 21 Jan 2011 12:26:51 -0300
Subject: [PATCH] selinux: return -ENOMEM when memory allocation fails

---
 security/selinux/ss/conditional.c |    2 +-
 security/selinux/ss/policydb.c    |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
security/selinux/ss/conditional.c +1 -1
index c3f845c..a533732 100644
@@ -178,7 +178,7 @@ int cond_init_bool_indexes(struct policydb *p)
 	p->bool_val_to_struct = (struct cond_bool_datum **)
 		kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
 	if (!p->bool_val_to_struct)
-		return -1;
+		return -ENOMEM;
 	return 0;
 }
 
security/selinux/ss/policydb.c +3 -3
index be9de38..0ebf5b5 100644
@@ -500,9 +500,9 @@ static int policydb_index(struct policydb *p)
 				 p->p_types.nprim - 1, GFP_KERNEL | __GFP_ZERO);
 	if (rc)
 		goto out;
-
-	rc = -ENOMEM;
-	if (cond_init_bool_indexes(p))
+	
+	rc = cond_init_bool_indexes(p);
+	if (rc)
 		goto out;
 
 	for (i = 0; i < SYM_NUM; i++) {
Signature · 1 line
1.7.1
#3 lore raw
Quoted 10 lines · Davidlohr Bueso

From: Davidlohr Bueso <[email protected]>
Date: Fri, 21 Jan 2011 12:26:51 -0300
Subject: [PATCH] selinux: return -ENOMEM when memory allocation fails

---
 security/selinux/ss/conditional.c |    2 +-
 security/selinux/ss/policydb.c    |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#for-linus

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.