From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39411C43387 for ; Tue, 8 Jan 2019 19:56:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0735A206BB for ; Tue, 8 Jan 2019 19:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546977407; bh=kPDdQhke/NyrXix/SvPk5fo8ogY32Dp5RHuk8EycDfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=o3OQbDsu90TTXgjZmpXJvDMTwysRV4A7DtnkwoIeMVd8Fzl3gBvTpEZTZwB3Uljs0 UUD7YonPq4KU7WjNx3zqCJooanXg34aXXS78wbmUlB12uL4bMlpUcbxFOZvbNFmmWZ iz/UWl88dbhR9NABqplgSYOdY6YThcy6Kfo9KPo0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731753AbfAHT4q (ORCPT ); Tue, 8 Jan 2019 14:56:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:37684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730576AbfAHTaE (ORCPT ); Tue, 8 Jan 2019 14:30:04 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB87620883; Tue, 8 Jan 2019 19:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975803; bh=kPDdQhke/NyrXix/SvPk5fo8ogY32Dp5RHuk8EycDfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oDrnH/+S0Wgpx7LRm8tq9uxEHpTaY/6sCELTGw7SuQ5yv4TxoBdxMQ9NC0tYsATG0 1QpgUXFXky8VbC/1ljgSJQNDpzklK8rxwpLCAnNPxIt/fA+n1xvtbiC/IU8XSzaEWH p+I62+HVdYUPkEENbyQKYRHpQm2LNppmwU/LirE8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Frank Rowand , Sasha Levin , devicetree@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 10/97] of: overlay: add missing of_node_put() after add new node to changeset Date: Tue, 8 Jan 2019 14:28:19 -0500 Message-Id: <20190108192949.122407-10-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192949.122407-1-sashal@kernel.org> References: <20190108192949.122407-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Rowand [ Upstream commit 7c528e457d53c75107d5aa56892316d265c778de ] The refcount of a newly added overlay node decrements to one (instead of zero) when the overlay changeset is destroyed. This change will cause the final decrement be to zero. After applying this patch, new validation warnings will be reported from the devicetree unittest during boot due to a pre-existing devicetree bug. The warnings will be similar to: OF: ERROR: memory leak before free overlay changeset, /testcase-data/overlay-node/test-bus/test-unittest4 This pre-existing devicetree bug will also trigger a WARN_ONCE() from refcount_sub_and_test_checked() when an overlay changeset is destroyed without having first been applied. This scenario occurs when an error in the overlay is detected during the overlay changeset creation: WARNING: CPU: 0 PID: 1 at lib/refcount.c:187 refcount_sub_and_test_checked+0xa8/0xbc refcount_t: underflow; use-after-free. (unwind_backtrace) from (show_stack+0x10/0x14) (show_stack) from (dump_stack+0x6c/0x8c) (dump_stack) from (__warn+0xdc/0x104) (__warn) from (warn_slowpath_fmt+0x44/0x6c) (warn_slowpath_fmt) from (refcount_sub_and_test_checked+0xa8/0xbc) (refcount_sub_and_test_checked) from (kobject_put+0x24/0x208) (kobject_put) from (of_changeset_destroy+0x2c/0xb4) (of_changeset_destroy) from (free_overlay_changeset+0x1c/0x9c) (free_overlay_changeset) from (of_overlay_remove+0x284/0x2cc) (of_overlay_remove) from (of_unittest_apply_revert_overlay_check.constprop.4+0xf8/0x1e8) (of_unittest_apply_revert_overlay_check.constprop.4) from (of_unittest_overlay+0x960/0xed8) (of_unittest_overlay) from (of_unittest+0x1cc4/0x2138) (of_unittest) from (do_one_initcall+0x4c/0x28c) (do_one_initcall) from (kernel_init_freeable+0x29c/0x378) (kernel_init_freeable) from (kernel_init+0x8/0x110) (kernel_init) from (ret_from_fork+0x14/0x2c) Tested-by: Alan Tull Signed-off-by: Frank Rowand Signed-off-by: Sasha Levin --- drivers/of/overlay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index eda57ef12fd0..baa9cee6fa2c 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -378,7 +378,9 @@ static int add_changeset_node(struct overlay_changeset *ovcs, if (ret) return ret; - return build_changeset_next_level(ovcs, tchild, node); + ret = build_changeset_next_level(ovcs, tchild, node); + of_node_put(tchild); + return ret; } if (node->phandle && tchild->phandle) -- 2.19.1