Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2287391imm; Thu, 18 Oct 2018 12:04:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV60WpSNjdTLrUyYt5WhLMWSZReESdAujf+nJuHzBGyN+IBqz0ANe7h0jjf9ykyU4TjezCOjP X-Received: by 2002:a63:d805:: with SMTP id b5-v6mr29094300pgh.174.1539889462293; Thu, 18 Oct 2018 12:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539889462; cv=none; d=google.com; s=arc-20160816; b=Ea6adl+3NUpZaB9MD/jl2DrS6IbC2VmAhzv39F//ZQhMYQv9hpADdmealklN7C5qFb uOEWB31DWgZCKzEt0TCmi66LUQVJgKut3B+36d+sDQGYyuCHpwVjfqkJ8flD0D+mlghO jlW9dup6u/lBvv1xkTD3V8ycNmmHEm/MyHO7MFp0MSbJChFpKYDykeaBPceAiA83ugGL /0iRxYAzd1MWqQoIz7aLmwP1shDEOe5CUVqcp+deUbHdJ+pX24IfmXCojQ8yNIoCA+or i40uEtj1pn6tujd4iF4ndovA8naP83fdpOydme0IOxXf6q4b2G1I23TBxlPMc3lcsITJ VjmA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=7Zuyi2L6RFcg8t6RIwhB1Ct3UzeFe1haCtGu9hCmFEI=; b=GKDxjHeLrSp2lEuu6WjXcc81dXJ9zB2QmyzLRFZ6/52CeNiYyoD5/lq9kNZ0fLqIOt ZWAReXe9xct6nfFf/pcomyqwJBB6MDMwLDEKOCulsKDboZUnbBNSB+JvQt9WE+pwnt+x nO4uHBC7waruN7yNEWBCpU5e7wd4REMUo5cnyfxGd2PNWcbf7BCm8giBYe9AaDFTN2T/ tES+C4H6aUbtb9DP2p5TdMUOrTkWNmyS02PnlNHiA0PWShXkrlUT0ZZaWEoxmlUuE5id 1MW1aeis6Siix+R510S/cvJBQujAAoPr4qru+WrkPTPWfl6wxedBwOIH3MLhUI8MEfVc srdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lmOmbQ1D; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be12-v6si21098185plb.347.2018.10.18.12.04.05; Thu, 18 Oct 2018 12:04:22 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=lmOmbQ1D; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726647AbeJSDEv (ORCPT + 99 others); Thu, 18 Oct 2018 23:04:51 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43952 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726340AbeJSDEv (ORCPT ); Thu, 18 Oct 2018 23:04:51 -0400 Received: by mail-pf1-f196.google.com with SMTP id p24-v6so15301617pff.10; Thu, 18 Oct 2018 12:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=7Zuyi2L6RFcg8t6RIwhB1Ct3UzeFe1haCtGu9hCmFEI=; b=lmOmbQ1D5MH7rtrW5vBLYiRemArOAiWw3Ki2nyDAU+xnz/g3qLlq071DxMhl7DkOFO YmrvpsEBTAYBtuPmf8DRt36lKO8NDwv7TIYBNj7WxPz+P+m/SxyvNvbvSp/hrmLgvtnt sQD8JXiWQQ1PpaWdhkGGkczdmMwYerfR8drv3o8pdXdvJvuk7mKXEqSbl4cb03WTD9O0 1hUaxlTx44NoUeejMH94dKQ9fzSNgSs7ZC/KibKa9QxP/AukD1M1G+xzOEYRYT2x0Npm Vr0MbaSbzmJg5rCX54M18u51Vl+uZLC9Itx+2U9+eQy3JDYLCBwm8y8g8lFvMM+kPfQa 0XgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7Zuyi2L6RFcg8t6RIwhB1Ct3UzeFe1haCtGu9hCmFEI=; b=kc1a4HvWqA7pRGQzGsyhfKQ5oWMWrLuH6Vdh210sQNlUVpQJIIZbQVYH1Fe/2fxDn3 +2Aq3JmF98e2QDGF9ftTEeQ8UXIEug1parXBN7rcaKTqWaIDpfA890dLD3dFfuDVqamZ +VVnSdZ2In8n1d4/HQ/aODHsM6wOla0+bqPWFjEiE6dCUOEgQnV4NlsT/F1U2l90dpVU Jf+OfaGpdEVHrK7NgqojDMG/LnLK0G6D8UZYVibJ40L+DkWEJwJ4sUC0QqZgFR9xCWNn ZmzPH8LzG2rnMkvPiP+7sh+8vmr9KXrlk9yjnLNHRO8XPswb1Jyd203aigJNvZaVCvzI 2BMg== X-Gm-Message-State: ABuFfohetGwdiMuyRTVBgeZDAYksVyjerFxhp1AcsR31Xg+6oOXYMlRH 1u1Fvqe77rWSKRjfIKwiIKo= X-Received: by 2002:a62:509a:: with SMTP id g26-v6mr31331087pfj.62.1539889348097; Thu, 18 Oct 2018 12:02:28 -0700 (PDT) Received: from [192.168.1.70] (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id m20-v6sm21901819pgv.93.2018.10.18.12.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 12:02:27 -0700 (PDT) Subject: Re: [PATCH v4 02/18] of: overlay: add missing of_node_put() after add new node to changeset To: Rob Herring Cc: Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org References: <1539657458-24401-1-git-send-email-frowand.list@gmail.com> <1539657458-24401-3-git-send-email-frowand.list@gmail.com> <20181018170502.GB15557@bogus> From: Frank Rowand Message-ID: <02a879fb-49b1-62b8-275c-d5ae6ccacecb@gmail.com> Date: Thu, 18 Oct 2018 12:02:26 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181018170502.GB15557@bogus> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/18/18 10:05, Rob Herring wrote: > On Mon, Oct 15, 2018 at 07:37:22PM -0700, frowand.list@gmail.com wrote: >> From: Frank Rowand >> >> 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 of_node_release() overlay node /testcase-data/overlay-node/test-bus/test-unittest4 before free overlay changeset > > Same comment on formatting. OK. >> >> 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) >> >> Signed-off-by: Frank Rowand >> --- >> 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 1176cb4b6e4e..32cfee68f2e3 100644 >> --- a/drivers/of/overlay.c >> +++ b/drivers/of/overlay.c >> @@ -379,7 +379,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) >> -- >> Frank Rowand >> >