Re: [PATCH] libsepol: Check for embedded NUL when reading from policy file

Stephen Smalley <[email protected]> Fri, 24 Jul 2026 10:28:12 -0400
Newsgroups org.kernel.vger.selinux
Message-ID <CAEjxPJ5fG5tVCaMmw5DUNNSUXEnt8w7wEevuhHziGZCVqeAnEQ@mail.gmail.com>
On Thu, Jul 23, 2026 at 2:39 PM Stephen Smalley
<[email protected]> wrote:
>
> On Wed, Jul 22, 2026 at 2:13 PM James Carter <[email protected]> wrote:
> >
> > Check that data read from a policy file does not have an
> > embedded NUL to protect against maliciously crafted polcies.
>
> policies
>
> >
> > Signed-off-by: James Carter <[email protected]>
>
> Otherwise,
> Acked-by: Stephen Smalley <[email protected]>

Merged.

>
> > ---
> >  libsepol/src/services.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/libsepol/src/services.c b/libsepol/src/services.c
> > index e8f0e622..3e8bd38b 100644
> > --- a/libsepol/src/services.c
> > +++ b/libsepol/src/services.c
> > @@ -1799,6 +1799,12 @@ int str_read(char **strp, struct policy_file *fp, size_t len)
> >         if (rc)
> >                 return rc;
> >
> > +       /* Check for an embedded NUL character */
> > +       if (memchr(str, '\0', len)) {
> > +               errno = EINVAL;
> > +               return -1;
> > +       }
> > +
> >         str[len] = '\0';
> >         return 0;
> >  }
> > --
> > 2.55.0
> >