Re: [PATCH v2 3/5] selinux: convert cond_av_list to array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 17, 2020 at 3:58 AM Ondrej Mosnacek <omosnace@xxxxxxxxxx> wrote:
> Since it is fixed-size after allocation and we know the size beforehand,
> using a plain old array is simpler and more efficient.
>
> Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx>
> Reviewed-by: Stephen Smalley <sds@xxxxxxxxxxxxx>
> ---
>  security/selinux/ss/conditional.c | 125 ++++++++++++------------------
>  security/selinux/ss/conditional.h |   8 +-
>  2 files changed, 53 insertions(+), 80 deletions(-)

...

> diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c
> index c8a02c9b23ee..b847fd2a6a51 100644
> --- a/security/selinux/ss/conditional.c
> +++ b/security/selinux/ss/conditional.c
> @@ -255,19 +249,17 @@ err:
>
>  struct cond_insertf_data {
>         struct policydb *p;
> +       struct avtab_node **dst;
>         struct cond_av_list *other;
> -       struct cond_av_list *head;
> -       struct cond_av_list *tail;
>  };
>
>  static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum *d, void *ptr)
>  {
>         struct cond_insertf_data *data = ptr;
>         struct policydb *p = data->p;
> -       struct cond_av_list *other = data->other, *list, *cur;
>         struct avtab_node *node_ptr;
> -       u8 found;
> -       int rc = -EINVAL;
> +       u32 i;
> +       bool found;
>
>         /*
>          * For type rules we have to make certain there aren't any
> @@ -277,7 +269,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
>         if (k->specified & AVTAB_TYPE) {
>                 if (avtab_search(&p->te_avtab, k)) {
>                         pr_err("SELinux: type rule already exists outside of a conditional.\n");
> -                       goto err;
> +                       return -EINVAL;
>                 }
>                 /*
>                  * If we are reading the false list other will be a pointer to
> @@ -287,29 +279,29 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
>                  * If we are reading the true list (other == NULL) there shouldn't
>                  * be any other entries.
>                  */
> -               if (other) {
> +               if (data->other) {
>                         node_ptr = avtab_search_node(&p->te_cond_avtab, k);
>                         if (node_ptr) {
>                                 if (avtab_search_node_next(node_ptr, k->specified)) {
>                                         pr_err("SELinux: too many conflicting type rules.\n");
> -                                       goto err;
> +                                       return -EINVAL;
>                                 }
> -                               found = 0;
> -                               for (cur = other; cur; cur = cur->next) {
> -                                       if (cur->node == node_ptr) {
> -                                               found = 1;
> +                               found = false;
> +                               for (i = 0; i < data->other->len; i++) {
> +                                       if (data->other->nodes[i] == node_ptr) {
> +                                               found = true;
>                                                 break;
>                                         }
>                                 }

Can you explain why you got rid of the "other" variable in this
function?  It seems like it would be nice in the loop above.

-- 
paul moore
www.paul-moore.com



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux