Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5098952imu; Tue, 8 Jan 2019 11:28:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN7N8lU7v7mci0X60E+E8YD+/+svreZVqbSa6eLfnXwq1U+IjUrdVPUdfhDCRj1QiYoEn3Z4 X-Received: by 2002:a62:1d4c:: with SMTP id d73mr3021925pfd.90.1546975704699; Tue, 08 Jan 2019 11:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546975704; cv=none; d=google.com; s=arc-20160816; b=eii1vFJlA1194hKpp+LYfuzo0J0NqLB8xBb4XFZ7b8kOQZJJ1ntwHuGaUWv0CYBmrt gLXk+mASEUnIR6kfvFqlzoSMN6O3htS3EX7vAJOh6CiauMvao2VQicVwwNF3jAuwdoeg LMIzlF3qYaDgbGcv2Q9Cgt425T19FITfaH+FWjDgeCOfBMeFZyJrbYDmjgCN4i+8nVr1 WzT/rXK3xf6L54wkMrjjOPMDOhSRVthXhFr2F8ZHR5QgNgULA1P3lfOmgwdBkoBSrMOF 59XX72Lfobonpb9zfK/fbD+DvI6BerAXLmP9ivbumB+Deq+zXuyyRz/x1eTjDNjU7XBT qPEA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ePjySoDkC6WPh9Nsr70e3S69p/AKfC+wi6JmIRRcVkE=; b=iCLpCYSk6YPhZi1lgxfGgptNcPmukzrvBR+C0YnSyNDRr2Ra+oKVbxVMa15Z7ZPrhA 2l5/6eRQ/HNIjtqa9EHzDBRGR+23qrAnDmo4DwsKl/vWeCLDsvst/1Q5rdnfFtN8we0n PJNJJY+wyI9m9nUjp4BFW7IqY9TS77wR0cON8l9CubRz3tp1wIxrXVFTQ9EEbSGhQzFq 1idJBN7uuiZNRtyPLa6HHpaZicA3Oyn1ZJKB8f9p6hE0O7gUYZUjPJe7D4Zwkm8shUN7 nuZBIjobCfnTE25LdOWSu3NuPCY+2OIO7zns1ky33OXA6QTI0YzyYd+wsl0gUssQSCUi 7brw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A25w9AC0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si628746pgn.551.2019.01.08.11.28.09; Tue, 08 Jan 2019 11:28:24 -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=A25w9AC0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729319AbfAHT0y (ORCPT + 99 others); Tue, 8 Jan 2019 14:26:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:60888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729148AbfAHT0u (ORCPT ); Tue, 8 Jan 2019 14:26:50 -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 2E55B20883; Tue, 8 Jan 2019 19:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975609; bh=YaT1tGfXdBj9KomnnX0NcNptWWp0E2WfpRcig9w1rI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A25w9AC0sTevGT6VrZBeQzImq+8HvmmhVRYs5zi+4YNZROIAYRYQ9FYrEX934WLNx +e1r8BVCLyko9OZWbHYL+xBuoIMWYKQI2CJfFMKUUrCy3zH85BffmCcZr0ajOePO9d 9nqOmXajh4dIJTgBzCt8xugFztXzi/+qkzJ4IyCE= 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.20 012/117] of: overlay: add missing of_node_put() after add new node to changeset Date: Tue, 8 Jan 2019 14:24:40 -0500 Message-Id: <20190108192628.121270-12-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-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 42b1f73ac5f6..1e058196f23f 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