lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAOQ4uxjbB9mtt6Fq=CLrH5AQm0fPHscrW2+91+3zgn89cxL=aQ@mail.gmail.com>
Date:   Tue, 12 Jun 2018 08:37:50 +0300
From:   Amir Goldstein <amir73il@...il.com>
To:     Zhouyang Jia <jiazhouyang09@...il.com>
Cc:     Jan Kara <jack@...e.cz>,
        linux-fsdevel <linux-fsdevel@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] fanotify: add error handling for kmem_cache_create

On Tue, Jun 12, 2018 at 7:19 AM, Zhouyang Jia <jiazhouyang09@...il.com> wrote:
> When kmem_cache_create fails, the lack of error-handling code may
> cause unexpected results.
>
> This patch adds error-handling code after calling kmem_cache_create.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@...il.com>
> ---
>  fs/notify/fanotify/fanotify_user.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index ec4d8c5..e3fa861 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -959,9 +959,14 @@ static int __init fanotify_user_setup(void)
>  {
>         fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC);
>         fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC);
> +       if (!fanotify_mark_cache || !fanotify_event_cachep)
> +               return -ENOMEM;

If only one failed need to free the other.

> +
>         if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
>                 fanotify_perm_event_cachep =
>                         KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC);
> +               if (!fanotify_perm_event_cachep)
> +                       return -ENOMEM;

here as well.
best implement as goto fail

>         }
>
>         return 0;

fail:
           if (fanotify_mark_cache)
                            kmem_cache_destroy(fanotify_mark_cache);
           ...
           return -ENOMEM;

Thanks,
Amir.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ