diff mbox series

libsepol: validate attribute-type maps

Message ID 20240608171838.136163-1-cgoettsche@seltendoof.de (mailing list archive)
State Accepted
Commit 8c1110d13438
Delegated to: Petr Lautrbach
Headers show
Series libsepol: validate attribute-type maps | expand

Commit Message

Christian Göttsche June 8, 2024, 5:18 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Ensure the attribute-to-type maps contain no invalid entries, required
for generating typeattributeset statements when converting to CIL.

Reported-by: oss-fuzz (issue 69283)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/policydb_validate.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

James Carter June 12, 2024, 3:33 p.m. UTC | #1
On Sat, Jun 8, 2024 at 1:18 PM Christian Göttsche
<cgoettsche@seltendoof.de> wrote:
>
> From: Christian Göttsche <cgzones@googlemail.com>
>
> Ensure the attribute-to-type maps contain no invalid entries, required
> for generating typeattributeset statements when converting to CIL.
>
> Reported-by: oss-fuzz (issue 69283)
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libsepol/src/policydb_validate.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
> index 84c1071c..9746f562 100644
> --- a/libsepol/src/policydb_validate.c
> +++ b/libsepol/src/policydb_validate.c
> @@ -1654,6 +1654,26 @@ bad:
>         return -1;
>  }
>
> +static int validate_attrtype_map(sepol_handle_t *handle, const policydb_t *p, validate_t flavors[])
> +{
> +       const ebitmap_t *maps = p->attr_type_map;
> +       uint32_t i;
> +
> +       if (p->policy_type == POLICY_KERN) {
> +               for (i = 0; i < p->p_types.nprim; i++) {
> +                       if (validate_ebitmap(&maps[i], &flavors[SYM_TYPES]))
> +                               goto bad;
> +               }
> +       } else if (maps)
> +               goto bad;
> +
> +       return 0;
> +
> +bad:
> +       ERR(handle, "Invalid attr type map");
> +       return -1;
> +}
> +
>  static int validate_properties(sepol_handle_t *handle, const policydb_t *p)
>  {
>         switch (p->policy_type) {
> @@ -1790,6 +1810,9 @@ int policydb_validate(sepol_handle_t *handle, const policydb_t *p)
>         if (validate_typeattr_map(handle, p, flavors))
>                 goto bad;
>
> +       if (validate_attrtype_map(handle, p, flavors))
> +               goto bad;
> +
>         validate_array_destroy(flavors);
>
>         return 0;
> --
> 2.45.1
>
>
James Carter June 14, 2024, 2:13 p.m. UTC | #2
On Wed, Jun 12, 2024 at 11:33 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Sat, Jun 8, 2024 at 1:18 PM Christian Göttsche
> <cgoettsche@seltendoof.de> wrote:
> >
> > From: Christian Göttsche <cgzones@googlemail.com>
> >
> > Ensure the attribute-to-type maps contain no invalid entries, required
> > for generating typeattributeset statements when converting to CIL.
> >
> > Reported-by: oss-fuzz (issue 69283)
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>

Merged.
Thanks,
Jim

> > ---
> >  libsepol/src/policydb_validate.c | 23 +++++++++++++++++++++++
> >  1 file changed, 23 insertions(+)
> >
> > diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
> > index 84c1071c..9746f562 100644
> > --- a/libsepol/src/policydb_validate.c
> > +++ b/libsepol/src/policydb_validate.c
> > @@ -1654,6 +1654,26 @@ bad:
> >         return -1;
> >  }
> >
> > +static int validate_attrtype_map(sepol_handle_t *handle, const policydb_t *p, validate_t flavors[])
> > +{
> > +       const ebitmap_t *maps = p->attr_type_map;
> > +       uint32_t i;
> > +
> > +       if (p->policy_type == POLICY_KERN) {
> > +               for (i = 0; i < p->p_types.nprim; i++) {
> > +                       if (validate_ebitmap(&maps[i], &flavors[SYM_TYPES]))
> > +                               goto bad;
> > +               }
> > +       } else if (maps)
> > +               goto bad;
> > +
> > +       return 0;
> > +
> > +bad:
> > +       ERR(handle, "Invalid attr type map");
> > +       return -1;
> > +}
> > +
> >  static int validate_properties(sepol_handle_t *handle, const policydb_t *p)
> >  {
> >         switch (p->policy_type) {
> > @@ -1790,6 +1810,9 @@ int policydb_validate(sepol_handle_t *handle, const policydb_t *p)
> >         if (validate_typeattr_map(handle, p, flavors))
> >                 goto bad;
> >
> > +       if (validate_attrtype_map(handle, p, flavors))
> > +               goto bad;
> > +
> >         validate_array_destroy(flavors);
> >
> >         return 0;
> > --
> > 2.45.1
> >
> >
diff mbox series

Patch

diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
index 84c1071c..9746f562 100644
--- a/libsepol/src/policydb_validate.c
+++ b/libsepol/src/policydb_validate.c
@@ -1654,6 +1654,26 @@  bad:
 	return -1;
 }
 
+static int validate_attrtype_map(sepol_handle_t *handle, const policydb_t *p, validate_t flavors[])
+{
+	const ebitmap_t *maps = p->attr_type_map;
+	uint32_t i;
+
+	if (p->policy_type == POLICY_KERN) {
+		for (i = 0; i < p->p_types.nprim; i++) {
+			if (validate_ebitmap(&maps[i], &flavors[SYM_TYPES]))
+				goto bad;
+		}
+	} else if (maps)
+		goto bad;
+
+	return 0;
+
+bad:
+	ERR(handle, "Invalid attr type map");
+	return -1;
+}
+
 static int validate_properties(sepol_handle_t *handle, const policydb_t *p)
 {
 	switch (p->policy_type) {
@@ -1790,6 +1810,9 @@  int policydb_validate(sepol_handle_t *handle, const policydb_t *p)
 	if (validate_typeattr_map(handle, p, flavors))
 		goto bad;
 
+	if (validate_attrtype_map(handle, p, flavors))
+		goto bad;
+
 	validate_array_destroy(flavors);
 
 	return 0;