Re: [PATCH 09/13] checkpolicy: resolve dismod memory leaks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 14, 2021 at 8:51 AM Christian Göttsche
<cgzones@xxxxxxxxxxxxxx> wrote:
>
> Example leak:
>
>     Indirect leak of 4 byte(s) in 1 object(s) allocated from:
>         #0 0x49bacd in __interceptor_malloc (./checkpolicy/test/dismod+0x49bacd)
>         #1 0x58ae54 in add_i_to_a ./libsepol/src/util.c:55:21
>         #2 0x53ea8e in symtab_insert ./libsepol/src/policydb.c:1729:6
>         #3 0x536252 in roles_init ./libsepol/src/policydb.c:772:7
>         #4 0x536252 in policydb_init ./libsepol/src/policydb.c:892:7
>         #5 0x562ff1 in sepol_policydb_create ./libsepol/src/policydb_public.c:69:6
>         #6 0x521a7c in module_package_init ./libsepol/src/module.c:96:6
>         #7 0x521a7c in sepol_module_package_create ./libsepol/src/module.c:126:7
>         #8 0x4cfb80 in read_policy ./checkpolicy/test/dismod.c:750:7
>         #9 0x4cda10 in main ./checkpolicy/test/dismod.c:878:6
>         #10 0x7f8538d01e49 in __libc_start_main csu/../csu/libc-start.c:314:16
>
> Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>
> ---
>  checkpolicy/test/dismod.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
> index 90c29318..9550b999 100644
> --- a/checkpolicy/test/dismod.c
> +++ b/checkpolicy/test/dismod.c
> @@ -751,12 +751,15 @@ static int read_policy(char *filename, policydb_t * policy)
>                         fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
>                         exit(1);
>                 }
> +               policydb_destroy((policydb_t *) package->policy);
> +               free(package->policy);

Should use "sepol_policydb_free(package->policy)" here. It does both
of these lines.
Jim


>                 package->policy = (sepol_policydb_t *) policy;
>                 package->file_contexts = NULL;
>                 retval =
>                     sepol_module_package_read(package,
>                                               (sepol_policy_file_t *) & f, 1);
> -               free(package->file_contexts);
> +               package->policy = NULL;
> +               sepol_module_package_free(package);
>         } else {
>                 if (policydb_init(policy)) {
>                         fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
> --
> 2.33.0
>




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux