* [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init()
@ 2019-04-23 23:32 Wen Yang
2019-04-24 0:21 ` Moritz Fischer
2019-04-24 11:22 ` Nicolas Saenz Julienne
0 siblings, 2 replies; 3+ messages in thread
From: Wen Yang @ 2019-04-23 23:32 UTC (permalink / raw)
To: linux-kernel
Cc: wang.yi59, Wen Yang, Alan Tull, Moritz Fischer,
Nicolas Saenz Julienne, linux-fpga
The refcount of fw_np has already been decreased by of_find_matching_node()
so it shouldn't be used anymore.
This patch adds an of_node_get() before of_find_matching_node() to avoid
the use-after-free problem.
Fixes: e7eef1d7633a ("fpga: add intel stratix10 soc fpga manager driver")
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Alan Tull <atull@kernel.org>
Cc: Moritz Fischer <mdf@kernel.org>
Cc: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: linux-fpga@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/fpga/stratix10-soc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
index 13851b3..215d337 100644
--- a/drivers/fpga/stratix10-soc.c
+++ b/drivers/fpga/stratix10-soc.c
@@ -507,12 +507,16 @@ static int __init s10_init(void)
if (!fw_np)
return -ENODEV;
+ of_node_get(fw_np);
np = of_find_matching_node(fw_np, s10_of_match);
- if (!np)
+ if (!np) {
+ of_node_put(fw_np);
return -ENODEV;
+ }
of_node_put(np);
ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
+ of_node_put(fw_np);
if (ret)
return ret;
--
2.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init()
2019-04-23 23:32 [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init() Wen Yang
@ 2019-04-24 0:21 ` Moritz Fischer
2019-04-24 11:22 ` Nicolas Saenz Julienne
1 sibling, 0 replies; 3+ messages in thread
From: Moritz Fischer @ 2019-04-24 0:21 UTC (permalink / raw)
To: Wen Yang
Cc: linux-kernel, wang.yi59, Alan Tull, Moritz Fischer,
Nicolas Saenz Julienne, linux-fpga
Hi Wen,
On Wed, Apr 24, 2019 at 07:32:05AM +0800, Wen Yang wrote:
> The refcount of fw_np has already been decreased by of_find_matching_node()
> so it shouldn't be used anymore.
> This patch adds an of_node_get() before of_find_matching_node() to avoid
> the use-after-free problem.
>
> Fixes: e7eef1d7633a ("fpga: add intel stratix10 soc fpga manager driver")
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> Cc: linux-fpga@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
Reviewed-by: Moritz Fischer <mdf@kernel.org>
> ---
> drivers/fpga/stratix10-soc.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> index 13851b3..215d337 100644
> --- a/drivers/fpga/stratix10-soc.c
> +++ b/drivers/fpga/stratix10-soc.c
> @@ -507,12 +507,16 @@ static int __init s10_init(void)
> if (!fw_np)
> return -ENODEV;
>
> + of_node_get(fw_np);
> np = of_find_matching_node(fw_np, s10_of_match);
> - if (!np)
> + if (!np) {
> + of_node_put(fw_np);
> return -ENODEV;
> + }
>
> of_node_put(np);
> ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
> + of_node_put(fw_np);
> if (ret)
> return ret;
>
> --
> 2.9.5
>
Thanks,
Moritz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init()
2019-04-23 23:32 [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init() Wen Yang
2019-04-24 0:21 ` Moritz Fischer
@ 2019-04-24 11:22 ` Nicolas Saenz Julienne
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Saenz Julienne @ 2019-04-24 11:22 UTC (permalink / raw)
To: Wen Yang, linux-kernel; +Cc: wang.yi59, Alan Tull, Moritz Fischer, linux-fpga
[-- Attachment #1: Type: text/plain, Size: 1421 bytes --]
Hi Thanks,
On Wed, 2019-04-24 at 07:32 +0800, Wen Yang wrote:
> The refcount of fw_np has already been decreased by of_find_matching_node()
> so it shouldn't be used anymore.
> This patch adds an of_node_get() before of_find_matching_node() to avoid
> the use-after-free problem.
>
> Fixes: e7eef1d7633a ("fpga: add intel stratix10 soc fpga manager driver")
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Alan Tull <atull@kernel.org>
> Cc: Moritz Fischer <mdf@kernel.org>
> Cc: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> Cc: linux-fpga@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/fpga/stratix10-soc.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c
> index 13851b3..215d337 100644
> --- a/drivers/fpga/stratix10-soc.c
> +++ b/drivers/fpga/stratix10-soc.c
> @@ -507,12 +507,16 @@ static int __init s10_init(void)
> if (!fw_np)
> return -ENODEV;
>
> + of_node_get(fw_np);
> np = of_find_matching_node(fw_np, s10_of_match);
> - if (!np)
> + if (!np) {
> + of_node_put(fw_np);
> return -ENODEV;
> + }
>
> of_node_put(np);
> ret = of_platform_populate(fw_np, s10_of_match, NULL, NULL);
> + of_node_put(fw_np);
> if (ret)
> return ret;
>
Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Regards,
Nicolas
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-24 11:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 23:32 [PATCH] fpga: stratix10-soc: fix use-after-free on s10_init() Wen Yang
2019-04-24 0:21 ` Moritz Fischer
2019-04-24 11:22 ` Nicolas Saenz Julienne
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.