Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3484202imu; Sun, 11 Nov 2018 16:08:54 -0800 (PST) X-Google-Smtp-Source: AJdET5dM288ThfQWi4YYYEJTUQ5Argkpjv3p6r9rvMpwVCz2XzMeUHrydVur1DOnlWjjgJ7fuuhL X-Received: by 2002:a63:1904:: with SMTP id z4mr15056539pgl.135.1541981334673; Sun, 11 Nov 2018 16:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981334; cv=none; d=google.com; s=arc-20160816; b=CCkyn0FUX/dJO7LKjHYPsddItnkU+3J98zop8ym1ZPMz5q6f8NAfqeBggIbtjkR7OB avJmEaovHXA8983B8g89ltlOboDZUz9bmudTX+Hb8NqHAYPyHKxzE4UZkl+bwntlKpM6 yEYyKhpy0/Ga+X+lk1YjT1Y2NylB2mX8G4Bt3KM+Uko2th36fNEzJ2Z8bSaoU1Sh1pc5 fVWehG80FTjVgcyDYcLTKJMMcbQH5EaFTO3JWDbJE9oCBTYONUVZdT/K08/hKVtk8zKz McVhUkuBg/rMm4mYQbLBpLDc0nqRTYgHZDsT82s6xH6OPlbhVU+wpYPVkvbebZCCk5FR +JvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DluQ2XBET1FiW/+GrNgWsGq6cFJO8evvX4CMP+yr5HU=; b=MU5HmKweH9Ascgth+TtKYkB95FYrRGOtzHneTvhuioiueX0AsNoeQ8MEyhsTbYG9Q9 WvitVJKIxp+8hvn03gZM3nSKRkvhVtNiBqykqb1P1Zmbxa8ZSFZjhL3U72iWY383/vmF 917KJ8E5Mh0r3XOogA51Y9tetT2DNjA8SeWoXoVWiBF6akxllobM5Su05kvBDuaCQq+o E/xFKaP3tYzNkPD79qeIEg5Bj2021s8s+mmEJiZn5A/fxvikrZxp4HlauAN9qBlcOumM M4gXSv5g0jk7UFlAo3buBwrrUMEQqxVE6QHXPKJZ6yy4c8ZKpZp7C+igHsGLReV2aNCA vBHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="eSyUyc/x"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24-v6si13136996pgb.50.2018.11.11.16.08.39; Sun, 11 Nov 2018 16:08:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="eSyUyc/x"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731923AbeKLJ6k (ORCPT + 99 others); Mon, 12 Nov 2018 04:58:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:60706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731421AbeKLIRc (ORCPT ); Mon, 12 Nov 2018 03:17:32 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C2AE208A3; Sun, 11 Nov 2018 22:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975257; bh=HxWcwC7Jke6wp4n4UvkIdjYH0UQKd6FpG14CgNgTdQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eSyUyc/xnN9vUqpQwuR/kPNrI4SyuWTp/as1rJGFyJyGoluK7V7/PKWAKkcpKL6yo Ez9KVTkpmd6QwGZdeQh/D/950hfLtJUN++eI2GqMrTCBZhu558P9ejJ+3S35f41e43 a41wrsB392iMCB4nz0rDvJgSZTJzFKnKPLmyTlus= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Corentin Labbe , Andrew Lunn , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Johan Hovold , Rob Herring , Sasha Levin Subject: [PATCH 4.19 132/361] net: stmmac: dwmac-sun8i: fix OF child-node lookup Date: Sun, 11 Nov 2018 14:17:59 -0800 Message-Id: <20181111221638.876405404@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold [ Upstream commit ac63043d8cb5503c7e0fe110f947eacf2663804e ] Use the new of_get_compatible_child() helper to lookup the mdio-internal child node instead of using of_find_compatible_node(), which searches the entire tree from a given start node and thus can return an unrelated (i.e. non-child) node. This also addresses a potential use-after-free (e.g. after probe deferral) as the tree-wide helper drops a reference to its first argument (i.e. the mdio-mux node). Fortunately, this was inadvertently balanced by a failure to drop the mdio-mux reference after lookup. While at it, also fix the related mdio-internal- and phy-node reference leaks. Fixes: 634db83b8265 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs") Tested-by: Corentin Labbe Cc: Andrew Lunn Cc: Giuseppe Cavallaro Cc: Alexandre Torgue Cc: Jose Abreu Cc: David S. Miller Signed-off-by: Johan Hovold Signed-off-by: Rob Herring Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -714,8 +714,9 @@ static int get_ephy_nodes(struct stmmac_ return -ENODEV; } - mdio_internal = of_find_compatible_node(mdio_mux, NULL, + mdio_internal = of_get_compatible_child(mdio_mux, "allwinner,sun8i-h3-mdio-internal"); + of_node_put(mdio_mux); if (!mdio_internal) { dev_err(priv->device, "Cannot get internal_mdio node\n"); return -ENODEV; @@ -729,13 +730,20 @@ static int get_ephy_nodes(struct stmmac_ gmac->rst_ephy = of_reset_control_get_exclusive(iphynode, NULL); if (IS_ERR(gmac->rst_ephy)) { ret = PTR_ERR(gmac->rst_ephy); - if (ret == -EPROBE_DEFER) + if (ret == -EPROBE_DEFER) { + of_node_put(iphynode); + of_node_put(mdio_internal); return ret; + } continue; } dev_info(priv->device, "Found internal PHY node\n"); + of_node_put(iphynode); + of_node_put(mdio_internal); return 0; } + + of_node_put(mdio_internal); return -ENODEV; }