diff mbox series

libsepol: check for overflow in put_entry()

Message ID 20230706135718.44908-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit df666f70534e
Headers show
Series libsepol: check for overflow in put_entry() | expand

Commit Message

Christian Göttsche July 6, 2023, 1:57 p.m. UTC
put_entry() is used during writing binary policies.  Avoid short writes
due to an overflow.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/services.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

James Carter July 11, 2023, 7:16 p.m. UTC | #1
On Thu, Jul 6, 2023 at 10:03 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> put_entry() is used during writing binary policies.  Avoid short writes
> due to an overflow.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

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

> ---
>  libsepol/src/services.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libsepol/src/services.c b/libsepol/src/services.c
> index 062510ab..07ae051b 100644
> --- a/libsepol/src/services.c
> +++ b/libsepol/src/services.c
> @@ -1708,7 +1708,10 @@ int next_entry(void *buf, struct policy_file *fp, size_t bytes)
>  size_t put_entry(const void *ptr, size_t size, size_t n,
>                         struct policy_file *fp)
>  {
> -       size_t bytes = size * n;
> +       size_t bytes;
> +
> +       if (__builtin_mul_overflow(size, n, &bytes))
> +               return 0;
>
>         switch (fp->type) {
>         case PF_USE_STDIO:
> --
> 2.40.1
>
James Carter July 12, 2023, 5:35 p.m. UTC | #2
On Tue, Jul 11, 2023 at 3:16 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Thu, Jul 6, 2023 at 10:03 AM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > put_entry() is used during writing binary policies.  Avoid short writes
> > due to an overflow.
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>

Merged.
Thanks,
Jim

> > ---
> >  libsepol/src/services.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/libsepol/src/services.c b/libsepol/src/services.c
> > index 062510ab..07ae051b 100644
> > --- a/libsepol/src/services.c
> > +++ b/libsepol/src/services.c
> > @@ -1708,7 +1708,10 @@ int next_entry(void *buf, struct policy_file *fp, size_t bytes)
> >  size_t put_entry(const void *ptr, size_t size, size_t n,
> >                         struct policy_file *fp)
> >  {
> > -       size_t bytes = size * n;
> > +       size_t bytes;
> > +
> > +       if (__builtin_mul_overflow(size, n, &bytes))
> > +               return 0;
> >
> >         switch (fp->type) {
> >         case PF_USE_STDIO:
> > --
> > 2.40.1
> >
diff mbox series

Patch

diff --git a/libsepol/src/services.c b/libsepol/src/services.c
index 062510ab..07ae051b 100644
--- a/libsepol/src/services.c
+++ b/libsepol/src/services.c
@@ -1708,7 +1708,10 @@  int next_entry(void *buf, struct policy_file *fp, size_t bytes)
 size_t put_entry(const void *ptr, size_t size, size_t n,
 			struct policy_file *fp)
 {
-	size_t bytes = size * n;
+	size_t bytes;
+
+	if (__builtin_mul_overflow(size, n, &bytes))
+		return 0;
 
 	switch (fp->type) {
 	case PF_USE_STDIO: