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 |
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 >
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 --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:
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(-)