On Mon, Jan 21, 2019 at 11:19 PM Yue Hu <[email protected]> wrote:
>
> From 7c1f672a2d7b7c2cfef313060bd429afc4af995b Mon Sep 17 00:00:00 2001
> From: Yue Hu <[email protected]>
> Date: Tue, 22 Jan 2019 14:47:00 +0800
> Subject: [PATCH] pstore/ram: Avoid possible failure of dummy device unregister
>
> In ramoops_register_dummy() if create platform device of dummy
> failed, the problem is following code called:
>
>     dummy = NULL;
>     ramoops_unregister_dummy();
>
> However platform_device_unregister() will check the pointer:
>
>     void platform_device_del(struct platform_device *pdev)
>     {
>             int i;
>
>             if (pdev) {
>                     ...
>             }
>     }
>     void platform_device_put(struct platform_device *pdev)
>     {
>             if (pdev)
>                     put_device(&pdev->dev);
>     }
>     void platform_device_unregister(struct platform_device *pdev)
>     {
>             platform_device_del(pdev);
>             platform_device_put(pdev);
>     }
>
> So the dummy device maybe always exists in the system, this is bad
> case, we need to avoid it.
>
> Signed-off-by: Yue Hu <[email protected]>
> ---
>  fs/pstore/ram.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 8db1f7f..1d56a20 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -932,7 +932,6 @@ static void __init ramoops_register_dummy(void)
>         if (IS_ERR(dummy)) {
>                 pr_info("could not create platform device: %ld\n",
>                         PTR_ERR(dummy));
> -               dummy = NULL;
>                 ramoops_unregister_dummy();

No, this needs to be cleared to NULL to avoid leaving a ERR_PTR (which
are non-NULL, see IS_ERR() above it), so that it can be safe to
unconditionally call platform_device_unregister().

-- 
Kees Cook

Reply via email to