diff mbox series

libselinux/fuzz: update for lookup_all() change

Message ID 20241205193005.20532-1-cgoettsche@seltendoof.de (mailing list archive)
State Accepted
Commit 6c8f6390bc62
Delegated to: Petr Lautrbach
Headers show
Series libselinux/fuzz: update for lookup_all() change | expand

Commit Message

Christian Göttsche Dec. 5, 2024, 7:30 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Commit 89dd0b23 ("libselinux: avoid memory allocation in common file
label lookup") added an additional parameter to lookup_all() for an
optional buffer the return value might be placed into.  Update the
fuzzing related code accordingly.

Fixes: 89dd0b23 ("libselinux: avoid memory allocation in common file label lookup")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/fuzz/selabel_file_compiled-fuzzer.c | 2 +-
 libselinux/fuzz/selabel_file_text-fuzzer.c     | 2 +-
 libselinux/src/label_file.h                    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

James Carter Dec. 6, 2024, 8:40 p.m. UTC | #1
On Thu, Dec 5, 2024 at 2:40 PM Christian Göttsche
<cgoettsche@seltendoof.de> wrote:
>
> From: Christian Göttsche <cgzones@googlemail.com>
>
> Commit 89dd0b23 ("libselinux: avoid memory allocation in common file
> label lookup") added an additional parameter to lookup_all() for an
> optional buffer the return value might be placed into.  Update the
> fuzzing related code accordingly.
>
> Fixes: 89dd0b23 ("libselinux: avoid memory allocation in common file label lookup")
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

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

> ---
>  libselinux/fuzz/selabel_file_compiled-fuzzer.c | 2 +-
>  libselinux/fuzz/selabel_file_text-fuzzer.c     | 2 +-
>  libselinux/src/label_file.h                    | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libselinux/fuzz/selabel_file_compiled-fuzzer.c b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> index cf0710ad..d1249a76 100644
> --- a/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> +++ b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> @@ -232,7 +232,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
>         assert(cmp(&rec, &rec) == SELABEL_EQUAL);
>
>         errno = 0;
> -       result = lookup_all(&rec, key, mode, partial, find_all);
> +       result = lookup_all(&rec, key, mode, partial, find_all, NULL);
>
>         if (!result)
>                 assert(errno != 0);
> diff --git a/libselinux/fuzz/selabel_file_text-fuzzer.c b/libselinux/fuzz/selabel_file_text-fuzzer.c
> index 5d851de1..ed67ea25 100644
> --- a/libselinux/fuzz/selabel_file_text-fuzzer.c
> +++ b/libselinux/fuzz/selabel_file_text-fuzzer.c
> @@ -178,7 +178,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
>         assert(cmp(&rec, &rec) == SELABEL_EQUAL);
>
>         errno = 0;
> -       result = lookup_all(&rec, key, mode, partial, find_all);
> +       result = lookup_all(&rec, key, mode, partial, find_all, NULL);
>
>         if (!result)
>                 assert(errno != 0);
> diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h
> index c7fe3a48..562c3da6 100644
> --- a/libselinux/src/label_file.h
> +++ b/libselinux/src/label_file.h
> @@ -63,7 +63,7 @@ struct lookup_result {
>  extern int load_mmap(FILE *fp, const size_t len, struct selabel_handle *rec, const char *path);
>  extern int process_text_file(FILE *fp, const char *prefix, struct selabel_handle *rec, const char *path);
>  extern void free_lookup_result(struct lookup_result *result);
> -extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all);
> +extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all, struct lookup_result *buf);
>  extern enum selabel_cmp_result cmp(const struct selabel_handle *h1, const struct selabel_handle *h2);
>  #endif  /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
>
> --
> 2.45.2
>
>
James Carter Dec. 17, 2024, 8:26 p.m. UTC | #2
On Fri, Dec 6, 2024 at 3:40 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Thu, Dec 5, 2024 at 2:40 PM Christian Göttsche
> <cgoettsche@seltendoof.de> wrote:
> >
> > From: Christian Göttsche <cgzones@googlemail.com>
> >
> > Commit 89dd0b23 ("libselinux: avoid memory allocation in common file
> > label lookup") added an additional parameter to lookup_all() for an
> > optional buffer the return value might be placed into.  Update the
> > fuzzing related code accordingly.
> >
> > Fixes: 89dd0b23 ("libselinux: avoid memory allocation in common file label lookup")
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>
Merged.
Thanks,
Jim

> > ---
> >  libselinux/fuzz/selabel_file_compiled-fuzzer.c | 2 +-
> >  libselinux/fuzz/selabel_file_text-fuzzer.c     | 2 +-
> >  libselinux/src/label_file.h                    | 2 +-
> >  3 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libselinux/fuzz/selabel_file_compiled-fuzzer.c b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> > index cf0710ad..d1249a76 100644
> > --- a/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> > +++ b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
> > @@ -232,7 +232,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
> >         assert(cmp(&rec, &rec) == SELABEL_EQUAL);
> >
> >         errno = 0;
> > -       result = lookup_all(&rec, key, mode, partial, find_all);
> > +       result = lookup_all(&rec, key, mode, partial, find_all, NULL);
> >
> >         if (!result)
> >                 assert(errno != 0);
> > diff --git a/libselinux/fuzz/selabel_file_text-fuzzer.c b/libselinux/fuzz/selabel_file_text-fuzzer.c
> > index 5d851de1..ed67ea25 100644
> > --- a/libselinux/fuzz/selabel_file_text-fuzzer.c
> > +++ b/libselinux/fuzz/selabel_file_text-fuzzer.c
> > @@ -178,7 +178,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
> >         assert(cmp(&rec, &rec) == SELABEL_EQUAL);
> >
> >         errno = 0;
> > -       result = lookup_all(&rec, key, mode, partial, find_all);
> > +       result = lookup_all(&rec, key, mode, partial, find_all, NULL);
> >
> >         if (!result)
> >                 assert(errno != 0);
> > diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h
> > index c7fe3a48..562c3da6 100644
> > --- a/libselinux/src/label_file.h
> > +++ b/libselinux/src/label_file.h
> > @@ -63,7 +63,7 @@ struct lookup_result {
> >  extern int load_mmap(FILE *fp, const size_t len, struct selabel_handle *rec, const char *path);
> >  extern int process_text_file(FILE *fp, const char *prefix, struct selabel_handle *rec, const char *path);
> >  extern void free_lookup_result(struct lookup_result *result);
> > -extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all);
> > +extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all, struct lookup_result *buf);
> >  extern enum selabel_cmp_result cmp(const struct selabel_handle *h1, const struct selabel_handle *h2);
> >  #endif  /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
> >
> > --
> > 2.45.2
> >
> >
diff mbox series

Patch

diff --git a/libselinux/fuzz/selabel_file_compiled-fuzzer.c b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
index cf0710ad..d1249a76 100644
--- a/libselinux/fuzz/selabel_file_compiled-fuzzer.c
+++ b/libselinux/fuzz/selabel_file_compiled-fuzzer.c
@@ -232,7 +232,7 @@  int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 	assert(cmp(&rec, &rec) == SELABEL_EQUAL);
 
 	errno = 0;
-	result = lookup_all(&rec, key, mode, partial, find_all);
+	result = lookup_all(&rec, key, mode, partial, find_all, NULL);
 
 	if (!result)
 		assert(errno != 0);
diff --git a/libselinux/fuzz/selabel_file_text-fuzzer.c b/libselinux/fuzz/selabel_file_text-fuzzer.c
index 5d851de1..ed67ea25 100644
--- a/libselinux/fuzz/selabel_file_text-fuzzer.c
+++ b/libselinux/fuzz/selabel_file_text-fuzzer.c
@@ -178,7 +178,7 @@  int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 	assert(cmp(&rec, &rec) == SELABEL_EQUAL);
 
 	errno = 0;
-	result = lookup_all(&rec, key, mode, partial, find_all);
+	result = lookup_all(&rec, key, mode, partial, find_all, NULL);
 
 	if (!result)
 		assert(errno != 0);
diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h
index c7fe3a48..562c3da6 100644
--- a/libselinux/src/label_file.h
+++ b/libselinux/src/label_file.h
@@ -63,7 +63,7 @@  struct lookup_result {
 extern int load_mmap(FILE *fp, const size_t len, struct selabel_handle *rec, const char *path);
 extern int process_text_file(FILE *fp, const char *prefix, struct selabel_handle *rec, const char *path);
 extern void free_lookup_result(struct lookup_result *result);
-extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all);
+extern struct lookup_result *lookup_all(struct selabel_handle *rec, const char *key, int type, bool partial, bool find_all, struct lookup_result *buf);
 extern enum selabel_cmp_result cmp(const struct selabel_handle *h1, const struct selabel_handle *h2);
 #endif  /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */