All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: "Christian Göttsche" <cgzones@googlemail.com>
Cc: selinux@vger.kernel.org
Subject: Re: [RFC PATCH] libsepol: validate permission identifier length
Date: Fri, 8 Dec 2023 11:05:51 -0500	[thread overview]
Message-ID: <CAEjxPJ4htnqzDyHFNR_aNJH-hrz_wbM=Z=NN7BjUQDrKBa8e9A@mail.gmail.com> (raw)
In-Reply-To: <20231207165319.63889-1-cgzones@googlemail.com>

On Thu, Dec 7, 2023 at 11:53 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> Limit the maximum length of permission identifiers.  Otherwise
> formatting an access vector might fail in the common used helper
> sepol_av_to_string().
>
> The current longest permission within the Reference Policy is
> x_application_data { paste_after_confirm } with a length of 19.

Android has longer permission names. I'd rather just fix
sepol_av_to_string() than impose some arbitrary limit here.

>
> Reported-by: oss-fuzz (issue 64832)
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> The oss-fuzz issue got closed by the latest fuzzer updates (due to
> unrelated changes that invalid the current reproducer), but the issue is
> still valid.
> ---
>  libsepol/src/policydb_validate.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
> index bd8e9f8f..72681120 100644
> --- a/libsepol/src/policydb_validate.c
> +++ b/libsepol/src/policydb_validate.c
> @@ -366,12 +366,30 @@ bad:
>         return -1;
>  }
>
> +static int validate_permission_wrapper(hashtab_key_t k, __attribute__((unused)) hashtab_datum_t d, void *args)
> +{
> +       sepol_handle_t *handle = args;
> +       const char *name = k;
> +       size_t len = strlen(name);
> +
> +       if (len == 0 || len >= 32)
> +               goto bad;
> +
> +       return 0;
> +
> +bad:
> +       ERR(handle, "Invalid permission");
> +       return -1;
> +}
> +
>  static int validate_common_datum(sepol_handle_t *handle, const common_datum_t *common, validate_t flavors[])
>  {
>         if (validate_value(common->s.value, &flavors[SYM_COMMONS]))
>                 goto bad;
>         if (common->permissions.table->nel == 0 || common->permissions.nprim > PERM_SYMTAB_SIZE)
>                 goto bad;
> +       if (hashtab_map(common->permissions.table, validate_permission_wrapper, handle))
> +               goto bad;
>
>         return 0;
>
> @@ -395,6 +413,8 @@ static int validate_class_datum(sepol_handle_t *handle, const class_datum_t *cla
>                 goto bad;
>         if (class->permissions.nprim > PERM_SYMTAB_SIZE)
>                 goto bad;
> +       if (hashtab_map(class->permissions.table, validate_permission_wrapper, handle))
> +               goto bad;
>         if (validate_constraint_nodes(handle, class->permissions.nprim, class->constraints, flavors))
>                 goto bad;
>         if (validate_constraint_nodes(handle, 0, class->validatetrans, flavors))
> --
> 2.43.0
>
>

  reply	other threads:[~2023-12-08 16:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 16:53 [RFC PATCH] libsepol: validate permission identifier length Christian Göttsche
2023-12-08 16:05 ` Stephen Smalley [this message]
2023-12-08 16:23   ` Stephen Smalley
2023-12-08 17:39   ` James Carter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEjxPJ4htnqzDyHFNR_aNJH-hrz_wbM=Z=NN7BjUQDrKBa8e9A@mail.gmail.com' \
    --to=stephen.smalley.work@gmail.com \
    --cc=cgzones@googlemail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.