Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1559248 > unrolled thread
| Started by | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| First post | 2017-01-15 16:00 +0100 |
| Last post | 2017-01-16 19:40 +0100 |
| Articles | 20 on this page of 50 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH 00/46] SELinux: Fine-tuning for several function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:00 +0100
[PATCH 02/46] selinux: Delete an unnecessary return statement in cond_compute_av() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:00 +0100
[PATCH 01/46] selinux: Use kmalloc_array() in cond_init_bool_indexes() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:00 +0100
[PATCH 04/46] selinux: Use kmalloc_array() in hashtab_create() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 05/46] selinux: Adjust four checks for null pointers SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 09/46] selinux: Delete an error message for a failed memory allocation in policydb_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 08/46] selinux: Delete an unnecessary return statement in policydb_destroy() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 03/46] selinux: Improve size determinations in four functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 06/46] selinux: Use kcalloc() in policydb_index() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:10 +0100
[PATCH 18/46] selinux: One function call less in filename_trans_read() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 17/46] selinux: Delete an unnecessary variable assignment in filename_trans_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 11/46] selinux: Return directly after a failed next_entry() in genfs_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 15/46] selinux: One check and function call less in genfs_read() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 16/46] selinux: Move two assignments for the variable "rc" in filename_trans_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 13/46] selinux: Move four assignments for the variable "rc" in genfs_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 14/46] selinux: One function call less in genfs_read() after null pointer detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 19/46] selinux: Return directly after a failed next_entry() in range_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 10/46] selinux: Move some assignments for the variable "rc" in policydb_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 12/46] selinux: Move assignments for two pointers in genfs_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:20 +0100
[PATCH 28/46] selinux: Return directly after a failed kzalloc() in user_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 20/46] selinux: Move four assignments for the variable "rc" in range_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 24/46] selinux: Return directly after a failed kzalloc() in cat_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 21/46] selinux: Two function calls less in range_read() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 23/46] selinux: Move an assignment for a pointer in range_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 29/46] selinux: Return directly after a failed kzalloc() in type_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 25/46] selinux: Return directly after a failed kzalloc() in sens_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 26/46] selinux: Improve another size determination in sens_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 27/46] selinux: Move an assignment for the variable "rc" in sens_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 22/46] selinux: Delete an unnecessary variable initialisation in range_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:30 +0100
[PATCH 35/46] selinux: Return directly after a failed kzalloc() in perm_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 32/46] selinux: Return directly after a failed kzalloc() in class_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 39/46] selinux: Move two assignments for the variable "rc" in ocontext_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 33/46] selinux: Move an assignment for the variable "rc" in class_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 37/46] selinux: Move an assignment for the variable "rc" in policydb_load_isids() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 38/46] selinux: One function call less in five functions after null pointer detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 30/46] selinux: Return directly after a failed kzalloc() in role_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 31/46] selinux: Move an assignment for the variable "rc" in role_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 36/46] selinux: Move an assignment for the variable "rc" in mls_read_range_helper() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 34/46] selinux: Return directly after a failed kzalloc() in common_read() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:40 +0100
[PATCH 45/46] selinux: Use common error handling code in sidtab_insert() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 44/46] selinux: Adjust two checks for null pointers SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 40/46] selinux: Return directly after a failed kzalloc() in roles_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 46/46] selinuxfs: Use seq_puts() in sel_avc_stats_seq_show() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 43/46] selinux: Use kmalloc_array() in sidtab_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 42/46] selinux: One function call less in roles_init() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
[PATCH 41/46] selinux: Move two assignments for the variable "rc" in roles_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-15 16:50 +0100
Re: [PATCH 00/46] SELinux: Fine-tuning for several function implementations Eric Paris <eparis@redhat.com> - 2017-01-16 16:30 +0100
Re: [PATCH 00/46] SELinux: Fine-tuning for several function implementations Paul Moore <paul@paul-moore.com> - 2017-01-16 17:50 +0100
Re: SELinux: Checking source code positions for the setting of error codes SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-16 19:40 +0100
Page 1 of 3 [1] 2 3 Next page →
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:00 +0100 |
| Subject | [PATCH 00/46] SELinux: Fine-tuning for several function implementations |
| Message-ID | <sZUrL-3Jh-9@gated-at.bofh.it> |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sun, 15 Jan 2017 15:15:14 +0100 Several update suggestions were taken into account from static source code analysis. Markus Elfring (46): Use kmalloc_array() in cond_init_bool_indexes() Delete an unnecessary return statement in cond_compute_av() Improve size determinations in four functions Use kmalloc_array() in hashtab_create() Adjust four checks for null pointers Use kcalloc() in policydb_index() Delete unnecessary variable assignments in policydb_index() Delete an unnecessary return statement in policydb_destroy() Delete an error message for a failed memory allocation in policydb_read() Move some assignments for the variable "rc" in policydb_read() Return directly after a failed next_entry() in genfs_read() Move assignments for two pointers in genfs_read() Move four assignments for the variable "rc" in genfs_read() One function call less in genfs_read() after null pointer detection One check and function call less in genfs_read() after error detection Move two assignments for the variable "rc" in filename_trans_read() Delete an unnecessary variable assignment in filename_trans_read() One function call less in filename_trans_read() after error detection Return directly after a failed next_entry() in range_read() Move four assignments for the variable "rc" in range_read() Two function calls less in range_read() after error detection Delete an unnecessary variable initialisation in range_read() Move an assignment for a pointer in range_read() Return directly after a failed kzalloc() in cat_read() Return directly after a failed kzalloc() in sens_read() Improve another size determination in sens_read() Move an assignment for the variable "rc" in sens_read() Return directly after a failed kzalloc() in user_read() Return directly after a failed kzalloc() in type_read() Return directly after a failed kzalloc() in role_read() Move an assignment for the variable "rc" in role_read() Return directly after a failed kzalloc() in class_read() Move an assignment for the variable "rc" in class_read() Return directly after a failed kzalloc() in common_read() Return directly after a failed kzalloc() in perm_read() Move an assignment for the variable "rc" in mls_read_range_helper() Move an assignment for the variable "rc" in policydb_load_isids() One function call less in five functions after null pointer detection Move two assignments for the variable "rc" in ocontext_read() Return directly after a failed kzalloc() in roles_init() Move two assignments for the variable "rc" in roles_init() One function call less in roles_init() after error detection Use kmalloc_array() in sidtab_init() Adjust two checks for null pointers Use common error handling code in sidtab_insert() Use seq_puts() in sel_avc_stats_seq_show() security/selinux/selinuxfs.c | 8 +- security/selinux/ss/conditional.c | 14 +-- security/selinux/ss/hashtab.c | 10 +- security/selinux/ss/policydb.c | 255 ++++++++++++++++++++------------------ security/selinux/ss/sidtab.c | 22 ++-- 5 files changed, 157 insertions(+), 152 deletions(-) -- 2.11.0
[toc] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:00 +0100 |
| Subject | [PATCH 02/46] selinux: Delete an unnecessary return statement in cond_compute_av() |
| Message-ID | <sZUrL-3Jh-7@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 14 Jan 2017 11:00:23 +0100 The script "checkpatch.pl" pointed information out like the following. WARNING: void function return statements are not generally useful Thus remove such a statement in the affected function. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- security/selinux/ss/conditional.c | 1 - 1 file changed, 1 deletion(-) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index fcfab2635c11..4a3bf29f7565 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -664,5 +664,4 @@ void cond_compute_av(struct avtab *ctab, struct avtab_key *key, (node->key.specified & AVTAB_XPERMS)) services_compute_xperms_drivers(xperms, node); } - return; } -- 2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:00 +0100 |
| Subject | [PATCH 01/46] selinux: Use kmalloc_array() in cond_init_bool_indexes() |
| Message-ID | <sZUrM-3Jh-17@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 10:48:28 +0100
* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/conditional.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
index 34afeadd9e73..fcfab2635c11 100644
--- a/security/selinux/ss/conditional.c
+++ b/security/selinux/ss/conditional.c
@@ -176,8 +176,9 @@ void cond_policydb_destroy(struct policydb *p)
int cond_init_bool_indexes(struct policydb *p)
{
kfree(p->bool_val_to_struct);
- p->bool_val_to_struct =
- kmalloc(p->p_bools.nprim * sizeof(struct cond_bool_datum *), GFP_KERNEL);
+ p->bool_val_to_struct = kmalloc_array(p->p_bools.nprim,
+ sizeof(*p->bool_val_to_struct),
+ GFP_KERNEL);
if (!p->bool_val_to_struct)
return -ENOMEM;
return 0;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 04/46] selinux: Use kmalloc_array() in hashtab_create() |
| Message-ID | <sZUBr-41H-7@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 12:06:13 +0100
A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/hashtab.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index 2cc496149842..dc99fff64ecb 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -24,7 +24,7 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void *
p->nel = 0;
p->hash_value = hash_value;
p->keycmp = keycmp;
- p->htable = kmalloc(sizeof(*(p->htable)) * size, GFP_KERNEL);
+ p->htable = kmalloc_array(size, sizeof(*p->htable), GFP_KERNEL);
if (p->htable == NULL) {
kfree(p);
return NULL;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 05/46] selinux: Adjust four checks for null pointers |
| Message-ID | <sZUBs-41H-15@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 12:36:59 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written !…
Thus fix affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/hashtab.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/security/selinux/ss/hashtab.c b/security/selinux/ss/hashtab.c
index dc99fff64ecb..3858706a29fb 100644
--- a/security/selinux/ss/hashtab.c
+++ b/security/selinux/ss/hashtab.c
@@ -17,7 +17,7 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void *
u32 i;
p = kzalloc(sizeof(*p), GFP_KERNEL);
- if (p == NULL)
+ if (!p)
return p;
p->size = size;
@@ -25,7 +25,7 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct hashtab *h, const void *
p->hash_value = hash_value;
p->keycmp = keycmp;
p->htable = kmalloc_array(size, sizeof(*p->htable), GFP_KERNEL);
- if (p->htable == NULL) {
+ if (!p->htable) {
kfree(p);
return NULL;
}
@@ -58,7 +58,7 @@ int hashtab_insert(struct hashtab *h, void *key, void *datum)
return -EEXIST;
newnode = kzalloc(sizeof(*newnode), GFP_KERNEL);
- if (newnode == NULL)
+ if (!newnode)
return -ENOMEM;
newnode->key = key;
newnode->datum = datum;
@@ -87,7 +87,7 @@ void *hashtab_search(struct hashtab *h, const void *key)
while (cur && h->keycmp(h, key, cur->key) > 0)
cur = cur->next;
- if (cur == NULL || (h->keycmp(h, key, cur->key) != 0))
+ if (!cur || (h->keycmp(h, key, cur->key) != 0))
return NULL;
return cur->datum;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 07/46] selinux: Delete unnecessary variable assignments in policydb_index() |
| Message-ID | <sZUBs-41H-27@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 13:40:25 +0100
The local variable "rc" was reset with an error code up to five times
before a memory allocation failure was detected.
Add a jump target so that this assignment will only be performed after
a concrete software failure.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 21869b622c0c..4d4ba1ad910d 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -539,34 +539,30 @@ static int policydb_index(struct policydb *p)
symtab_hash_eval(p->symtab);
#endif
- rc = -ENOMEM;
p->class_val_to_struct = kcalloc(p->p_classes.nprim,
sizeof(*p->class_val_to_struct),
GFP_KERNEL);
if (!p->class_val_to_struct)
- goto out;
+ goto failure_indication;
- rc = -ENOMEM;
p->role_val_to_struct = kcalloc(p->p_roles.nprim,
sizeof(*p->role_val_to_struct),
GFP_KERNEL);
if (!p->role_val_to_struct)
- goto out;
+ goto failure_indication;
- rc = -ENOMEM;
p->user_val_to_struct = kcalloc(p->p_users.nprim,
sizeof(*p->user_val_to_struct),
GFP_KERNEL);
if (!p->user_val_to_struct)
- goto out;
+ goto failure_indication;
/* Yes, I want the sizeof the pointer, not the structure */
- rc = -ENOMEM;
p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *),
p->p_types.nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->type_val_to_struct_array)
- goto out;
+ goto failure_indication;
rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
p->p_types.nprim, GFP_KERNEL | __GFP_ZERO);
@@ -578,12 +574,11 @@ static int policydb_index(struct policydb *p)
goto out;
for (i = 0; i < SYM_NUM; i++) {
- rc = -ENOMEM;
p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
p->symtab[i].nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->sym_val_to_name[i])
- goto out;
+ goto failure_indication;
rc = flex_array_prealloc(p->sym_val_to_name[i],
0, p->symtab[i].nprim,
@@ -598,6 +593,9 @@ static int policydb_index(struct policydb *p)
rc = 0;
out:
return rc;
+failure_indication:
+ rc = -ENOMEM;
+ goto out;
}
/*
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 09/46] selinux: Delete an error message for a failed memory allocation in policydb_read() |
| Message-ID | <sZUBs-41H-17@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 14:20:41 +0100
Omit an extra message for a memory allocation failure in this function.
Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index fe8992382a71..53e6d06e772a 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2269,11 +2269,8 @@ int policydb_read(struct policydb *p, void *fp)
rc = -ENOMEM;
policydb_str = kmalloc(len + 1, GFP_KERNEL);
- if (!policydb_str) {
- printk(KERN_ERR "SELinux: unable to allocate memory for policydb "
- "string of length %d\n", len);
+ if (!policydb_str)
goto bad;
- }
rc = next_entry(policydb_str, fp, len);
if (rc) {
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 08/46] selinux: Delete an unnecessary return statement in policydb_destroy() |
| Message-ID | <sZUBs-41H-31@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 14 Jan 2017 14:00:02 +0100 The script "checkpatch.pl" pointed information out like the following. WARNING: void function return statements are not generally useful Thus remove such a statement in the affected function. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- security/selinux/ss/policydb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 4d4ba1ad910d..fe8992382a71 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -878,8 +878,6 @@ void policydb_destroy(struct policydb *p) ebitmap_destroy(&p->filename_trans_ttypes); ebitmap_destroy(&p->policycaps); ebitmap_destroy(&p->permissive_map); - - return; } /* -- 2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 03/46] selinux: Improve size determinations in four functions |
| Message-ID | <sZUBt-41H-41@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 11:22:12 +0100
Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/conditional.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
index 4a3bf29f7565..771c96afe1d5 100644
--- a/security/selinux/ss/conditional.c
+++ b/security/selinux/ss/conditional.c
@@ -227,7 +227,7 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
u32 len;
int rc;
- booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL);
+ booldatum = kzalloc(sizeof(*booldatum), GFP_KERNEL);
if (!booldatum)
return -ENOMEM;
@@ -332,7 +332,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
goto err;
}
- list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL);
+ list = kzalloc(sizeof(*list), GFP_KERNEL);
if (!list) {
rc = -ENOMEM;
goto err;
@@ -421,7 +421,7 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
goto err;
rc = -ENOMEM;
- expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL);
+ expr = kzalloc(sizeof(*expr), GFP_KERNEL);
if (!expr)
goto err;
@@ -472,7 +472,7 @@ int cond_read_list(struct policydb *p, void *fp)
for (i = 0; i < len; i++) {
rc = -ENOMEM;
- node = kzalloc(sizeof(struct cond_node), GFP_KERNEL);
+ node = kzalloc(sizeof(*node), GFP_KERNEL);
if (!node)
goto err;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:10 +0100 |
| Subject | [PATCH 06/46] selinux: Use kcalloc() in policydb_index() |
| Message-ID | <sZUBt-41H-49@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 14 Jan 2017 13:08:59 +0100 Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- security/selinux/ss/policydb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index d719db4219cd..21869b622c0c 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -540,23 +540,23 @@ static int policydb_index(struct policydb *p) #endif rc = -ENOMEM; - p->class_val_to_struct = - kzalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), - GFP_KERNEL); + p->class_val_to_struct = kcalloc(p->p_classes.nprim, + sizeof(*p->class_val_to_struct), + GFP_KERNEL); if (!p->class_val_to_struct) goto out; rc = -ENOMEM; - p->role_val_to_struct = - kzalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), - GFP_KERNEL); + p->role_val_to_struct = kcalloc(p->p_roles.nprim, + sizeof(*p->role_val_to_struct), + GFP_KERNEL); if (!p->role_val_to_struct) goto out; rc = -ENOMEM; - p->user_val_to_struct = - kzalloc(p->p_users.nprim * sizeof(*(p->user_val_to_struct)), - GFP_KERNEL); + p->user_val_to_struct = kcalloc(p->p_users.nprim, + sizeof(*p->user_val_to_struct), + GFP_KERNEL); if (!p->user_val_to_struct) goto out; -- 2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 18/46] selinux: One function call less in filename_trans_read() after error detection |
| Message-ID | <sZUL7-44S-3@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 19:19:42 +0100
Adjust a jump target to avoid a function call at the end after a memory
allocation failed for the local variable "ft".
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 2be5b18eb149..5f122e846332 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1932,7 +1932,7 @@ static int filename_trans_read(struct policydb *p, void *fp)
ft = kzalloc(sizeof(*ft), GFP_KERNEL);
if (!ft) {
rc = -ENOMEM;
- goto out;
+ goto free_name;
}
otype = kmalloc(sizeof(*otype), GFP_KERNEL);
@@ -1986,6 +1986,7 @@ static int filename_trans_read(struct policydb *p, void *fp)
return 0;
out:
kfree(ft);
+free_name:
kfree(name);
kfree(otype);
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 17/46] selinux: Delete an unnecessary variable assignment in filename_trans_read() |
| Message-ID | <sZUL7-44S-1@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 19:02:42 +0100
The local variable "ft" was set to a null pointer despite of an
immediate reassignment.
Thus remove this statement from the beginning of a loop.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 106a1da1d68a..2be5b18eb149 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1927,7 +1927,6 @@ static int filename_trans_read(struct policydb *p, void *fp)
nel = le32_to_cpu(buf[0]);
for (i = 0; i < nel; i++) {
- ft = NULL;
otype = NULL;
name = NULL;
ft = kzalloc(sizeof(*ft), GFP_KERNEL);
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 11/46] selinux: Return directly after a failed next_entry() in genfs_read() |
| Message-ID | <sZUL8-44S-29@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 16:34:25 +0100
Return directly after a call of the function "next_entry" failed
at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 506b0228d1f1..754f829d2027 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2004,7 +2004,7 @@ static int genfs_read(struct policydb *p, void *fp)
rc = next_entry(buf, fp, sizeof(u32));
if (rc)
- goto out;
+ return rc;
nel = le32_to_cpu(buf[0]);
for (i = 0; i < nel; i++) {
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 15/46] selinux: One check and function call less in genfs_read() after error detection |
| Message-ID | <sZUL8-44S-33@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 18:29:20 +0100
Adjust a jump target to avoid a check repetition at the end after a memory
allocation failed for the local variable "newgenfs".
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 5dc31faa601f..e7b882251da8 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2015,7 +2015,7 @@ static int genfs_read(struct policydb *p, void *fp)
newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
if (!newgenfs) {
rc = -ENOMEM;
- goto out;
+ goto exit;
}
rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len);
@@ -2101,7 +2101,7 @@ static int genfs_read(struct policydb *p, void *fp)
kfree(newgenfs);
}
ocontext_destroy(newc, OCON_FSUSE);
-
+exit:
return rc;
}
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 16/46] selinux: Move two assignments for the variable "rc" in filename_trans_read() |
| Message-ID | <sZUL9-44S-35@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 18:50:52 +0100
One local variable was set to an error code in two cases before
a concrete error situation was detected. Thus move the corresponding
assignments into if branches to indicate a software failure there.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index e7b882251da8..106a1da1d68a 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1930,16 +1930,17 @@ static int filename_trans_read(struct policydb *p, void *fp)
ft = NULL;
otype = NULL;
name = NULL;
-
- rc = -ENOMEM;
ft = kzalloc(sizeof(*ft), GFP_KERNEL);
- if (!ft)
+ if (!ft) {
+ rc = -ENOMEM;
goto out;
+ }
- rc = -ENOMEM;
otype = kmalloc(sizeof(*otype), GFP_KERNEL);
- if (!otype)
+ if (!otype) {
+ rc = -ENOMEM;
goto out;
+ }
/* length of the path component string */
rc = next_entry(buf, fp, sizeof(u32));
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 13/46] selinux: Move four assignments for the variable "rc" in genfs_read() |
| Message-ID | <sZUL9-44S-37@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 17:21:59 +0100
One local variable was set to an error code in four cases before
a concrete error situation was detected. Thus move the corresponding
assignments into if branches to indicate a software failure there.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 7544e374dec9..a12d9166f0e4 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2012,11 +2012,11 @@ static int genfs_read(struct policydb *p, void *fp)
if (rc)
goto out;
len = le32_to_cpu(buf[0]);
-
- rc = -ENOMEM;
newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
- if (!newgenfs)
+ if (!newgenfs) {
+ rc = -ENOMEM;
goto out;
+ }
rc = str_read(&newgenfs->fstype, GFP_KERNEL, fp, len);
if (rc)
@@ -2024,10 +2024,10 @@ static int genfs_read(struct policydb *p, void *fp)
for (genfs_p = NULL, genfs = p->genfs; genfs;
genfs_p = genfs, genfs = genfs->next) {
- rc = -EINVAL;
if (strcmp(newgenfs->fstype, genfs->fstype) == 0) {
printk(KERN_ERR "SELinux: dup genfs fstype %s\n",
newgenfs->fstype);
+ rc = -EINVAL;
goto out;
}
if (strcmp(newgenfs->fstype, genfs->fstype) < 0)
@@ -2051,11 +2051,11 @@ static int genfs_read(struct policydb *p, void *fp)
if (rc)
goto out;
len = le32_to_cpu(buf[0]);
-
- rc = -ENOMEM;
newc = kzalloc(sizeof(*newc), GFP_KERNEL);
- if (!newc)
+ if (!newc) {
+ rc = -ENOMEM;
goto out;
+ }
rc = str_read(&newc->u.name, GFP_KERNEL, fp, len);
if (rc)
@@ -2072,12 +2072,12 @@ static int genfs_read(struct policydb *p, void *fp)
for (l = NULL, c = genfs->head; c;
l = c, c = c->next) {
- rc = -EINVAL;
if (!strcmp(newc->u.name, c->u.name) &&
(!c->v.sclass || !newc->v.sclass ||
newc->v.sclass == c->v.sclass)) {
printk(KERN_ERR "SELinux: dup genfs entry (%s,%s)\n",
genfs->fstype, c->u.name);
+ rc = -EINVAL;
goto out;
}
len = strlen(newc->u.name);
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 14/46] selinux: One function call less in genfs_read() after null pointer detection |
| Message-ID | <sZUL8-44S-27@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 17:43:47 +0100
Call the function "kfree" at the end only after it was determined
that the local variable "newgenfs" contained a non-null pointer.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index a12d9166f0e4..5dc31faa601f 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2096,9 +2096,10 @@ static int genfs_read(struct policydb *p, void *fp)
}
rc = 0;
out:
- if (newgenfs)
+ if (newgenfs) {
kfree(newgenfs->fstype);
- kfree(newgenfs);
+ kfree(newgenfs);
+ }
ocontext_destroy(newc, OCON_FSUSE);
return rc;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 19/46] selinux: Return directly after a failed next_entry() in range_read() |
| Message-ID | <sZUL9-44S-47@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 19:35:59 +0100
Return directly after a call of the function "next_entry" failed
at the beginning.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 5f122e846332..a696876fc327 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1850,7 +1850,7 @@ static int range_read(struct policydb *p, void *fp)
rc = next_entry(buf, fp, sizeof(u32));
if (rc)
- goto out;
+ return rc;
nel = le32_to_cpu(buf[0]);
for (i = 0; i < nel; i++) {
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 10/46] selinux: Move some assignments for the variable "rc" in policydb_read() |
| Message-ID | <sZUL9-44S-49@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 15:22:29 +0100
One local variable was set to an error code in some cases before
a concrete error situation was detected. Thus move the corresponding
assignments into if branches to indicate a software failure there.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 59 +++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 53e6d06e772a..506b0228d1f1 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2250,15 +2250,14 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -EINVAL;
if (le32_to_cpu(buf[0]) != POLICYDB_MAGIC) {
printk(KERN_ERR "SELinux: policydb magic number 0x%x does "
"not match expected magic number 0x%x\n",
le32_to_cpu(buf[0]), POLICYDB_MAGIC);
+ rc = -EINVAL;
goto bad;
}
- rc = -EINVAL;
len = le32_to_cpu(buf[1]);
if (len != strlen(POLICYDB_STRING)) {
printk(KERN_ERR "SELinux: policydb string length %d does not "
@@ -2265,11 +2265,13 @@ int policydb_read(struct policydb *p, void *fp)
len, strlen(POLICYDB_STRING));
+ rc = -EINVAL;
goto bad;
}
- rc = -ENOMEM;
policydb_str = kmalloc(len + 1, GFP_KERNEL);
- if (!policydb_str)
+ if (!policydb_str) {
+ rc = -ENOMEM;
goto bad;
+ }
rc = next_entry(policydb_str, fp, len);
if (rc) {
@@ -2279,12 +2280,12 @@ int policydb_read(struct policydb *p, void *fp)
goto bad;
}
- rc = -EINVAL;
policydb_str[len] = '\0';
if (strcmp(policydb_str, POLICYDB_STRING)) {
printk(KERN_ERR "SELinux: policydb string %s does not match "
"my string %s\n", policydb_str, POLICYDB_STRING);
kfree(policydb_str);
+ rc = -EINVAL;
goto bad;
}
/* Done with policydb_str. */
@@ -2296,24 +2297,24 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -EINVAL;
p->policyvers = le32_to_cpu(buf[0]);
if (p->policyvers < POLICYDB_VERSION_MIN ||
p->policyvers > POLICYDB_VERSION_MAX) {
printk(KERN_ERR "SELinux: policydb version %d does not match "
"my version range %d-%d\n",
le32_to_cpu(buf[0]), POLICYDB_VERSION_MIN, POLICYDB_VERSION_MAX);
+ rc = -EINVAL;
goto bad;
}
if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
p->mls_enabled = 1;
- rc = -EINVAL;
if (p->policyvers < POLICYDB_VERSION_MLS) {
printk(KERN_ERR "SELinux: security policydb version %d "
"(MLS) not backwards compatible\n",
p->policyvers);
+ rc = -EINVAL;
goto bad;
}
}
@@ -2332,21 +2333,21 @@ int policydb_read(struct policydb *p, void *fp)
goto bad;
}
- rc = -EINVAL;
info = policydb_lookup_compat(p->policyvers);
if (!info) {
printk(KERN_ERR "SELinux: unable to find policy compat info "
"for version %d\n", p->policyvers);
+ rc = -EINVAL;
goto bad;
}
- rc = -EINVAL;
if (le32_to_cpu(buf[2]) != info->sym_num ||
le32_to_cpu(buf[3]) != info->ocon_num) {
printk(KERN_ERR "SELinux: policydb table sizes (%d,%d) do "
"not match mine (%d,%d)\n", le32_to_cpu(buf[2]),
le32_to_cpu(buf[3]),
info->sym_num, info->ocon_num);
+ rc = -EINVAL;
goto bad;
}
@@ -2365,10 +2366,11 @@ int policydb_read(struct policydb *p, void *fp)
p->symtab[i].nprim = nprim;
}
- rc = -EINVAL;
p->process_class = string_to_security_class(p, "process");
- if (!p->process_class)
+ if (!p->process_class) {
+ rc = -EINVAL;
goto bad;
+ }
rc = avtab_read(&p->te_avtab, fp, p);
if (rc)
@@ -2386,10 +2388,12 @@ int policydb_read(struct policydb *p, void *fp)
nel = le32_to_cpu(buf[0]);
ltr = NULL;
for (i = 0; i < nel; i++) {
- rc = -ENOMEM;
tr = kzalloc(sizeof(*tr), GFP_KERNEL);
- if (!tr)
+ if (!tr) {
+ rc = -ENOMEM;
goto bad;
+ }
+
if (ltr)
ltr->next = tr;
else
@@ -2398,7 +2402,6 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -EINVAL;
tr->role = le32_to_cpu(buf[0]);
tr->type = le32_to_cpu(buf[1]);
tr->new_role = le32_to_cpu(buf[2]);
@@ -2410,12 +2413,14 @@ int policydb_read(struct policydb *p, void *fp)
} else
tr->tclass = p->process_class;
- rc = -EINVAL;
if (!policydb_role_isvalid(p, tr->role) ||
!policydb_type_isvalid(p, tr->type) ||
!policydb_class_isvalid(p, tr->tclass) ||
- !policydb_role_isvalid(p, tr->new_role))
+ !policydb_role_isvalid(p, tr->new_role)) {
+ rc = -EINVAL;
goto bad;
+ }
+
ltr = tr;
}
@@ -2425,10 +2430,12 @@ int policydb_read(struct policydb *p, void *fp)
nel = le32_to_cpu(buf[0]);
lra = NULL;
for (i = 0; i < nel; i++) {
- rc = -ENOMEM;
ra = kzalloc(sizeof(*ra), GFP_KERNEL);
- if (!ra)
+ if (!ra) {
+ rc = -ENOMEM;
goto bad;
+ }
+
if (lra)
lra->next = ra;
else
@@ -2437,12 +2444,14 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -EINVAL;
ra->role = le32_to_cpu(buf[0]);
ra->new_role = le32_to_cpu(buf[1]);
if (!policydb_role_isvalid(p, ra->role) ||
- !policydb_role_isvalid(p, ra->new_role))
+ !policydb_role_isvalid(p, ra->new_role)) {
+ rc = -EINVAL;
goto bad;
+ }
+
lra = ra;
}
@@ -2454,11 +2463,12 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -EINVAL;
p->process_trans_perms = string_to_av_perm(p, p->process_class, "transition");
p->process_trans_perms |= string_to_av_perm(p, p->process_class, "dyntransition");
- if (!p->process_trans_perms)
+ if (!p->process_trans_perms) {
+ rc = -EINVAL;
goto bad;
+ }
rc = ocontext_read(p, info, fp);
if (rc)
@@ -2472,12 +2482,13 @@ int policydb_read(struct policydb *p, void *fp)
if (rc)
goto bad;
- rc = -ENOMEM;
p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
p->p_types.nprim,
GFP_KERNEL | __GFP_ZERO);
- if (!p->type_attr_map_array)
+ if (!p->type_attr_map_array) {
+ rc = -ENOMEM;
goto bad;
+ }
/* preallocate so we don't have to worry about the put ever failing */
rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim,
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2017-01-15 16:20 +0100 |
| Subject | [PATCH 12/46] selinux: Move assignments for two pointers in genfs_read() |
| Message-ID | <sZUL9-44S-41@gated-at.bofh.it> |
| In reply to | #1559248 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Jan 2017 16:56:51 +0100
Move the assignment for the local variables "newc" and "newgenfs" behind
a call of the function "next_entry" at the beginning so that they will
only be set after a successful call.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/selinux/ss/policydb.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 754f829d2027..7544e374dec9 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1997,14 +1997,14 @@ static int genfs_read(struct policydb *p, void *fp)
int i, j, rc;
u32 nel, nel2, len, len2;
__le32 buf[1];
- struct ocontext *l, *c;
- struct ocontext *newc = NULL;
- struct genfs *genfs_p, *genfs;
- struct genfs *newgenfs = NULL;
+ struct ocontext *l, *c, *newc;
+ struct genfs *genfs_p, *genfs, *newgenfs;
rc = next_entry(buf, fp, sizeof(u32));
if (rc)
return rc;
+ newc = NULL;
+ newgenfs = NULL;
nel = le32_to_cpu(buf[0]);
for (i = 0; i < nel; i++) {
--
2.11.0
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | linux.kernel
csiph-web