linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Wen Yang <wen.yang99@zte.com.cn>
To: linux-kernel@vger.kernel.org
Cc: wang.yi59@zte.com.cn, Rob Herring <robh@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	xue.zhihong@zte.com.cn, cheng.shengyu@zte.com.cn,
	linuxppc-dev@lists.ozlabs.org, Wen Yang <wen.yang99@zte.com.cn>
Subject: [PATCH] powerpc: fix use-after-free on fixup_port_irq()
Date: Fri, 5 Jul 2019 16:59:36 +0800	[thread overview]
Message-ID: <1562317176-13317-1-git-send-email-wen.yang99@zte.com.cn> (raw)

There is a possible use-after-free issue in the fixup_port_irq():

460 static void __init fixup_port_irq(int index,
461                                   struct device_node *np,
462                                   struct plat_serial8250_port *port)
463 {
...
469         if (!virq && legacy_serial_infos[index].irq_check_parent) {
470                 np = of_get_parent(np);  --> modified here.
...
474                 of_node_put(np); ---> released here
475         }
...
481 #ifdef CONFIG_SERIAL_8250_FSL
482   if (of_device_is_compatible(np, "fsl,ns16550")) --> dereferenced here
...
484 #endif
485 }

We solve this problem by introducing a new parent_np variable.

Fixes: 9deaa53ac7fa ("serial: add irq handler for Freescale 16550 errata.")
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Rob Herring <robh@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
---
 arch/powerpc/kernel/legacy_serial.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index 7cea597..0105f3e 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -461,17 +461,18 @@ static void __init fixup_port_irq(int index,
 				  struct device_node *np,
 				  struct plat_serial8250_port *port)
 {
+	struct device_node *parent_np;
 	unsigned int virq;
 
 	DBG("fixup_port_irq(%d)\n", index);
 
 	virq = irq_of_parse_and_map(np, 0);
 	if (!virq && legacy_serial_infos[index].irq_check_parent) {
-		np = of_get_parent(np);
-		if (np == NULL)
+		parent_np = of_get_parent(np);
+		if (parent_np == NULL)
 			return;
-		virq = irq_of_parse_and_map(np, 0);
-		of_node_put(np);
+		virq = irq_of_parse_and_map(parent_np, 0);
+		of_node_put(parent_np);
 	}
 	if (!virq)
 		return;
-- 
2.9.5


                 reply	other threads:[~2019-07-05  9:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1562317176-13317-1-git-send-email-wen.yang99@zte.com.cn \
    --to=wen.yang99@zte.com.cn \
    --cc=cheng.shengyu@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    --cc=robh@kernel.org \
    --cc=wang.yi59@zte.com.cn \
    --cc=xue.zhihong@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).