selinux: clean up error path in policydb_init()
PATCH 1/1 selinux: clean up error path in policydb_init()
Commit e0ac568de1fa ("selinux: reduce the use of hard-coded hash sizes") moved symtab initialization out of policydb_init(), but left the cleanup of symtabs from the error path. This patch fixes the oversight.
--- security/selinux/ss/policydb.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
security/selinux/ss/policydb.c +5 -13
@@ -463,36 +463,28 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)*/ static int policydb_init (struct policydb *p) { -int i, rc; +int rc;memset (p,0 ,sizeof (*p)); rc =avtab_init (&p->te_avtab);if (rc) - goto out; +return rc; rc =cond_policydb_init (p);if (rc) - goto out; +return rc; p->filename_trans =hashtab_create (filenametr_hash, filenametr_cmp, (1 <<11 )); -if (!p->filename_trans) { - rc = -ENOMEM ; - goto out; - } +if (!p->filename_trans) +return -ENOMEM ;ebitmap_init (&p->filename_trans_ttypes);ebitmap_init (&p->policycaps);ebitmap_init (&p->permissive_map);return 0 ; -out: -for (i =0 ; i <SYM_NUM ; i++) { -hashtab_map (p->symtab[i].table, destroy_f[i],NULL ); -hashtab_destroy (p->symtab[i].table); - } -return rc; }/*
Signature · 1 line
2.24.1
Stephen Smalley
maintainerQuoted 23 lines · Ondrej Mosnacek
Commit
e0ac568de1fa("selinux: reduce the use of hard-coded hash sizes") moved symtab initialization out ofpolicydb_init(), but left the cleanup of symtabs from the error path. This patch fixes the oversight.Suggested-by Stephen Smalley <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>--- security/selinux/ss/policydb.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)security/selinux/ss/policydb.c +1
-1@@ -463,36 +463,28 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)*/ static int policydb_init (struct policydb *p) { -int i, rc; +int rc;memset (p,0 ,sizeof (*p));
security/selinux/ss/policydb.c static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2) · line 476
Quoted 10 lines
security/selinux/ss/policydb.c +2
-2rc =avtab_init (&p->te_avtab);if (rc) - goto out; +return rc; rc =cond_policydb_init (p);if (rc) - goto out; +return rc;
Looks like avtab_init() and cond_policydb_init() can no longer return errors, merely initialize fields to 0/NULL,
which is already done via the memset above, and are not used anywhere else so those can go away entirely?
security/selinux/ss/policydb.c static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2) · line 485
Quoted 13 lines
security/selinux/ss/policydb.c +2
-4p->filename_trans =hashtab_create (filenametr_hash, filenametr_cmp, (1 <<11 )); -if (!p->filename_trans) { - rc = -ENOMEM ; - goto out; - } +if (!p->filename_trans) +return -ENOMEM ;ebitmap_init (&p->filename_trans_ttypes);ebitmap_init (&p->policycaps);ebitmap_init (&p->permissive_map);
Technically these aren't needed either but I guess we can leave them in case ebitmap_init() does more than just memset
at some point.
Quoted 30 lines · Stephen Smalley
Quoted 29 lines · Ondrej Mosnacek
Commit
e0ac568de1fa("selinux: reduce the use of hard-coded hash sizes") moved symtab initialization out ofpolicydb_init(), but left the cleanup of symtabs from the error path. This patch fixes the oversight.Suggested-by Stephen Smalley <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>--- security/selinux/ss/policydb.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)security/selinux/ss/policydb.c +2
-2@@ -463,36 +463,28 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)*/ static int policydb_init (struct policydb *p) { -int i, rc; +int rc;memset (p,0 ,sizeof (*p)); rc =avtab_init (&p->te_avtab);if (rc) - goto out; +return rc;
Quoted 9 lines
security/selinux/ss/policydb.c static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2) · line 476
Quoted 4 lines
security/selinux/ss/policydb.c +1
-1rc =cond_policydb_init (p);if (rc) - goto out; +return rc;Looks like
avtab_init()andcond_policydb_init()can no longer return errors, merely initialize fields to 0/NULL,
which is already done via the memset above, and are not used anywhere else so those can go away entirely?
OK, but that can be done in a separate patch, right? Do you plan to send it? Anyway, I'd prefer to keep the *_init() functions for the sake of abstraction - I'd suggest just changing the return type to void where possible.
Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com> Software Engineer, Security Technologies Red Hat, Inc.
Quoted 17 lines · Ondrej Mosnacek
Quoted 6 lines · Stephen Smalley
Quoted 5 lines · Ondrej Mosnacek
Commit
e0ac568de1fa("selinux: reduce the use of hard-coded hash sizes") moved symtab initialization out ofpolicydb_init(), but left the cleanup of symtabs from the error path. This patch fixes the oversight.Quoted 7 lines
Quoted 3 lines
Suggested-by Stephen Smalley <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>---
Looks like
avtab_init()andcond_policydb_init()can no longer return errors, merely initialize fields to 0/NULL,
which is already done via the memset above, and are not used anywhere else so those can go away entirely?
Quoted 4 lines
OK, but that can be done in a separate patch, right? Do you plan to send it? Anyway, I'd prefer to keep the
*_init()functions for the sake of abstraction - I'd suggest just changing the return type to void where possible.
Fair enough.
Paul Moore
maintainerQuoted 42 lines · Ondrej Mosnacek
Quoted 30 lines · Stephen Smalley
Quoted 29 lines · Ondrej Mosnacek
Commit
e0ac568de1fa("selinux: reduce the use of hard-coded hash sizes") moved symtab initialization out ofpolicydb_init(), but left the cleanup of symtabs from the error path. This patch fixes the oversight.Suggested-by Stephen Smalley <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>--- security/selinux/ss/policydb.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)security/selinux/ss/policydb.c +2
-2@@ -463,36 +463,28 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)*/ static int policydb_init (struct policydb *p) { -int i, rc; +int rc;memset (p,0 ,sizeof (*p)); rc =avtab_init (&p->te_avtab);if (rc) - goto out; +return rc;Quoted 9 lines
security/selinux/ss/policydb.c static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2) · line 476
Quoted 4 lines
security/selinux/ss/policydb.c +1
-1rc =cond_policydb_init (p);if (rc) - goto out; +return rc;Looks like
avtab_init()andcond_policydb_init()can no longer return errors, merely initialize fields to 0/NULL,
which is already done via the memset above, and are not used anywhere else so those can go away entirely?
Quoted 4 lines
OK, but that can be done in a separate patch, right? Do you plan to send it? Anyway, I'd prefer to keep the
*_init()functions for the sake of abstraction - I'd suggest just changing the return type to void where possible.
I tend to agree. Merged into selinux/next.
I'm also not seeing a patch from anyone to change the return type so I'll put one together now.
Signature · 2 lines
paul moore www.paul-moore.com