From patchwork Thu May 9 21:08:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Tull X-Patchwork-Id: 10937737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6C2376 for ; Thu, 9 May 2019 21:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9774E28AFB for ; Thu, 9 May 2019 21:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AA0E28B15; Thu, 9 May 2019 21:08:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CE0328AFB for ; Thu, 9 May 2019 21:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727108AbfEIVIj (ORCPT ); Thu, 9 May 2019 17:08:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbfEIVIg (ORCPT ); Thu, 9 May 2019 17:08:36 -0400 Received: from localhost.localdomain (user-0ccsrjt.cable.mindspring.com [24.206.110.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34513217F5; Thu, 9 May 2019 21:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557436115; bh=A2KlR4tg2BhBXTfCzsQuGbwT0RVrYjIIugnnkl+JVAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9wfyHob1Brg0UK3vjRJ8iO/B6s1DMf1UfQ9PMSKL7dp69cF0Rkd9QhEIjt1XlKOJ b5qjMdTmzbze1iqYRdK5QOcwBkTq89zZQaSnHYxbsDANuVgLtKtmYaZQlch1b1sSUV M6YFWAR7sSb4veSEZJnZ08+XEe28xkLpbVXRfGH4= From: Alan Tull To: Greg Kroah-Hartman Cc: Moritz Fischer , Alan Tull , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Wen Yang , Nicolas Saenz Julienne Subject: [PATCH 1/4] fpga: stratix10-soc: fix use-after-free on s10_init() Date: Thu, 9 May 2019 16:08:26 -0500 Message-Id: <20190509210829.31815-2-atull@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509210829.31815-1-atull@kernel.org> References: <20190509210829.31815-1-atull@kernel.org> MIME-Version: 1.0 Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wen Yang 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 Cc: Alan Tull Cc: Moritz Fischer Cc: Nicolas Saenz Julienne Cc: linux-fpga@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Moritz Fischer Reviewed-by: Nicolas Saenz Julienne Acked-by: Alan Tull --- 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 13851b3d1c56..215d33789c74 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;