All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: Nicolas Iooss <nicolas.iooss@m4x.org>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH 1/6] libsepol/cil: fix out-of-bound read of a file context pattern ending with "\"
Date: Mon, 15 Mar 2021 17:02:39 -0400	[thread overview]
Message-ID: <CAP+JOzThBfc5-JtYYuPfhBHX6phxWMCJksy8WPggDiDFJyTpaw@mail.gmail.com> (raw)
In-Reply-To: <20210314201651.474432-1-nicolas.iooss@m4x.org>

On Sun, Mar 14, 2021 at 4:23 PM Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
>
> OSS-Fuzz found a Heap-buffer-overflow in the CIL compiler when trying to
> compile the following policy:
>
>     (sid SID)
>     (sidorder(SID))
>     (filecon "\" any ())
>     (filecon "" any ())
>
> When cil_post_fc_fill_data() processes "\", it goes beyond the NUL
> terminator of the string. Fix this by returning when '\0' is read after
> a backslash.
>
> Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28484
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>  libsepol/cil/src/cil_post.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c
> index a55df1ea5bb0..5f9cf4efd242 100644
> --- a/libsepol/cil/src/cil_post.c
> +++ b/libsepol/cil/src/cil_post.c
> @@ -179,6 +179,12 @@ void cil_post_fc_fill_data(struct fc_data *fc, char *path)
>                         break;
>                 case '\\':
>                         c++;

The patch below is fine, but I can't figure out the reason for the
line above. I guess it means that fc->str_len++ will be skipped, but
if that is the purpose, it is not very clear. Does anyone know if this
is correct?

Jim


> +                       if (path[c] == '\0') {
> +                               if (!fc->meta) {
> +                                       fc->stem_len++;
> +                               }
> +                               return;
> +                       }
>                         /* FALLTHRU */
>                 default:
>                         if (!fc->meta) {
> --
> 2.30.2
>

  parent reply	other threads:[~2021-03-15 21:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-14 20:16 [PATCH 1/6] libsepol/cil: fix out-of-bound read of a file context pattern ending with "\" Nicolas Iooss
2021-03-14 20:16 ` [PATCH 2/6] libsepol/cil: make cil_post_fc_fill_data static Nicolas Iooss
2021-03-15 21:03   ` James Carter
2021-03-17  8:39     ` Nicolas Iooss
2021-03-14 20:16 ` [PATCH 3/6] libsepol/cil: remove stray printf Nicolas Iooss
2021-03-15 21:03   ` James Carter
2021-03-14 20:16 ` [PATCH 4/6] libsepol/cil: replace printf with proper cil_tree_log Nicolas Iooss
2021-03-15 21:04   ` James Carter
2021-03-14 20:16 ` [PATCH 5/6] libsepol/cil: fix NULL pointer dereference in __cil_insert_name Nicolas Iooss
2021-03-15 21:05   ` James Carter
2021-03-14 20:16 ` [PATCH 6/6] libsepol/cil: do not leak avrulex_ioctl_table memory when an error occurs Nicolas Iooss
2021-03-15 21:05   ` James Carter
2021-03-15 21:02 ` James Carter [this message]
2021-03-15 21:34   ` [PATCH 1/6] libsepol/cil: fix out-of-bound read of a file context pattern ending with "\" Nicolas Iooss
2021-03-16 13:34     ` James Carter
2021-03-17  7:45       ` Nicolas Iooss
2021-03-17 14:35         ` 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=CAP+JOzThBfc5-JtYYuPfhBHX6phxWMCJksy8WPggDiDFJyTpaw@mail.gmail.com \
    --to=jwcart2@gmail.com \
    --cc=nicolas.iooss@m4x.org \
    --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.