mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pstore/ram: Avoid possible failure of dummy device unregister
@ 2019-02-14 11:31 Yue Hu
  2019-02-14 16:22 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Yue Hu @ 2019-02-14 11:31 UTC (permalink / raw)
  To: anton, ccross, tony.luck, keescook; +Cc: linux-kernel

From 08ac260f36b4c11eb33fa58466462a5e1027bdb3 Mon Sep 17 00:00:00 2001
From: Yue Hu <zbestahu@gmail.com>
Date: Thu, 14 Feb 2019 19:34:16 +0800
Subject: [PATCH] pstore/ram: Avoid possible failure of dummy device unregister

If create dummy platform device failed, dummy variable should not
been set as NULL. Because the following platform_device_unregister()
will judge if the dummy is NULL or not, if dummy is NULL nothing
happen for unregister flow.

Signed-off-by: Yue Hu <zbestahu@gmail.com>
---
 fs/pstore/ram.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 4a06675..61bc573 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -994,7 +994,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();
 	}
 }
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pstore/ram: Avoid possible failure of dummy device unregister
  2019-02-14 11:31 [PATCH] pstore/ram: Avoid possible failure of dummy device unregister Yue Hu
@ 2019-02-14 16:22 ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2019-02-14 16:22 UTC (permalink / raw)
  To: Yue Hu; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML

On Thu, Feb 14, 2019 at 3:31 AM Yue Hu <zbestahu@gmail.com> wrote:
>
> From 08ac260f36b4c11eb33fa58466462a5e1027bdb3 Mon Sep 17 00:00:00 2001
> From: Yue Hu <zbestahu@gmail.com>
> Date: Thu, 14 Feb 2019 19:34:16 +0800
> Subject: [PATCH] pstore/ram: Avoid possible failure of dummy device unregister
>
> If create dummy platform device failed, dummy variable should not
> been set as NULL. Because the following platform_device_unregister()
> will judge if the dummy is NULL or not, if dummy is NULL nothing
> happen for unregister flow.
>
> Signed-off-by: Yue Hu <zbestahu@gmail.com>

I've gotten this email a few times today. :)

I already replied that this isn't what we want to do: we have to mark
it NULL since prior to that it was an ERR_PTR, and will break the
unregister.

-Kees

> ---
>  fs/pstore/ram.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 4a06675..61bc573 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -994,7 +994,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();
>         }
>  }
> --
> 1.9.1
>


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pstore/ram: Avoid possible failure of dummy device unregister
       [not found] <5c46c41c.1c69fb81.13fc6.834eSMTPIN_ADDED_BROKEN@mx.google.com>
@ 2019-02-12 20:16 ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2019-02-12 20:16 UTC (permalink / raw)
  To: Yue Hu; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML

On Mon, Jan 21, 2019 at 11:19 PM Yue Hu <huyue2@yulong.com> wrote:
>
> From 7c1f672a2d7b7c2cfef313060bd429afc4af995b Mon Sep 17 00:00:00 2001
> From: Yue Hu <huyue2@yulong.com>
> 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 <huyue2@yulong.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-14 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 11:31 [PATCH] pstore/ram: Avoid possible failure of dummy device unregister Yue Hu
2019-02-14 16:22 ` Kees Cook
     [not found] <5c46c41c.1c69fb81.13fc6.834eSMTPIN_ADDED_BROKEN@mx.google.com>
2019-02-12 20:16 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome