Received: by 10.223.164.202 with SMTP id h10csp63160wrb; Thu, 30 Nov 2017 07:03:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMbRjbbpOZtJ4SGjejwgB90EiNgm7Z0NKeCcu+Xx7EfpVVBEWqMWLEkEtwns5RCzEq9s428D X-Received: by 10.84.143.131 with SMTP id 3mr2981876plz.113.1512054190752; Thu, 30 Nov 2017 07:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512054190; cv=none; d=google.com; s=arc-20160816; b=eEVxx9VuFRdBuAOXtNJq4e01md6BpOYvvcxs/S7vDn+u4YgpggVUAIWzvF7wi2rQH0 /Z/GMfpVTsyUh8bdWwyEP48e9GdxW3fpNnKYq1XKLAff0DhCOdF6i9cQsNyqUSDJ8dUx w566PKa7yqypQdD+42bxVcNQ59b577fGW+9+VcKtujbSETJLgUsJeh40NmqfcWbuoh2x Py42kvNCd0VNkcoExzMHpMR6NPI7zb6NcD7+sDA1iboOWQVx9oaKppUVQpnyszKHgry6 IM1xpnkus4flJRl2A5dAWT/n2jRigzJrxht24hOUI4QF5TRz+2HeJGeb6tlUOjAkf7P+ lZcw== 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:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=Pm8oNo6kLbgQujSf3O086ocGbCPRGHJSaCysehwIhoM=; b=FKLlf0rZDALdzbpaKdpZ14FLjhXDflD6IFAL51mNLf0JhQlaIeA1tgboYOPM5c5hnM o2bj4C8IyHuBVrINaB3xDqsvy4REdC0M1+IBUaYdYOpYkr+HghQX/RNklUH7TUJiV0Md zhjmO7p8qu1QF3pN6qXPoC/lOsn6agmjVtgTZ2ME8NmbS+ooBJy0GsWR2PeDlygL30op VhBOxG8nKEqLpHB6sPnmtAlNb09OJDLJkPsgAsC5tibnFEuFMJ/tojgoflX/Ea0vEbAX NLW28coiZGTc9EO24qY5PmKa7LflA+v5yQrGi7fD2CXTMPJoCfQ5G2eWrqXl7kjy84RN C4DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=owcqisWt; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si3220230plt.771.2017.11.30.07.02.28; Thu, 30 Nov 2017 07:03:10 -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=@gmail.com header.s=20161025 header.b=owcqisWt; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753001AbdK3PCH (ORCPT + 99 others); Thu, 30 Nov 2017 10:02:07 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:37858 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752470AbdK3PCF (ORCPT ); Thu, 30 Nov 2017 10:02:05 -0500 Received: by mail-pl0-f65.google.com with SMTP id v41so4363963plg.4; Thu, 30 Nov 2017 07:02:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Pm8oNo6kLbgQujSf3O086ocGbCPRGHJSaCysehwIhoM=; b=owcqisWtdzNdY3oQp8U4WDtiuY93UTnsaJgCofkdwijBODEeclwBKDjQ6e5miq4L0/ 2o4TcAkhlQmMPG/3PO8b9jDoquef/jaumdRulvlOT+upn7V2MiH8YuZxUapepr2yLoBS Vb82QIpSW+yDjHDNpqB4KfVQxEpzyVlKIwVWt+IvgdVUsVb7AtSlnezer/bASJAKbzzO FVOOC76giqTqQ7GwByL1TH0hiDGzkShr3WWoR71Bw6ZfmN5g2Ga0+p1k8cm8f5LsRwey W6ZO1gqUT9lYPn1oFGUvPZgAT8+3le9Aqlpjryi4SGxhLK0LSzmXxvZdDuK7A5nt1qJY squw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Pm8oNo6kLbgQujSf3O086ocGbCPRGHJSaCysehwIhoM=; b=IKc5wIHiXW8Gs2INs4GIvB9yZE9pERJPAkMjTj9ZxAO2BZrNURYrsnEwfmElexpH3E Bwe1vOz0OLliksjbPZQZE+Q93fGpq/aw59HEpQVW3p2X+aJ88qmy3mSsAwEmpZ4okHFq fAWmLLtctCcT8Bnqo4o1H5dzPRkRNEIrCJJl9Ps8yKhqCsbQCqmKBbYqZq3gs/rCSpiF +MR+tOf2p9gbscHZAqzJLRgCCrw6Oid2ScyxEJvyTW0yoq8M+7ejiIVxlxCifoxx0702 LhOD6KjnIs3lm2Qxiu6q6okUENdoM42gyuMDJEviK3QW2oYoVmImKu2uolHSsagESmDX pAkA== X-Gm-Message-State: AJaThX5hYiXDo1s5AKO62sbYKDUU6plNhLeI6JuiaNKMPC+k61UqIpvh OuPnDQYWeLjlzhcCi9BtGnk= X-Received: by 10.84.202.194 with SMTP id q2mr2944127plh.19.1512054124936; Thu, 30 Nov 2017 07:02:04 -0800 (PST) Received: from [192.168.43.210] (mobile-166-170-39-92.mycingular.net. [166.170.39.92]) by smtp.gmail.com with ESMTPSA id l13sm8477132pfj.73.2017.11.30.07.01.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 07:02:04 -0800 (PST) Subject: Re: [PATCH] of: overlay: fix memory leak of ovcs on error exit path From: Frank Rowand To: Colin Ian King , Pantelis Antoniou , Rob Herring , devicetree@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20171129191750.25254-1-colin.king@canonical.com> <806a0467-87c8-4100-c7f2-54cfa8732465@canonical.com> <75d7d1c8-8a19-1a4c-0796-7cf69fdebe6d@gmail.com> Message-ID: <788fe2e4-03b2-6f9d-f5dd-5bdf0c48892f@gmail.com> Date: Thu, 30 Nov 2017 10:01:50 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <75d7d1c8-8a19-1a4c-0796-7cf69fdebe6d@gmail.com> 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 11/30/17 08:37, Frank Rowand wrote: > Hi Colin, Rob, > > On 11/30/17 07:18, Colin Ian King wrote: >> On 30/11/17 12:14, Frank Rowand wrote: >>> On 11/29/17 14:17, Colin King wrote: >>>> From: Colin Ian King >>>> >>>> Currently if the call to of_resolve_phandles fails then then ovcs >>>> is not kfree'd on the error exit path. Rather than try and make >>>> the clean up exit path more convoluted, fix this by just kfree'ing >>>> ovcs at the point of error detection and exit via the same exit >>>> path. >>>> >>>> Detected by CoverityScan, CID#1462296 ("Resource Leak") >>>> >>>> Fixes: f948d6d8b792 ("of: overlay: avoid race condition between applying multiple overlays") >>>> Signed-off-by: Colin Ian King >>>> --- >>>> 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 53bc9e3f0b98..6c8efe7d8cbb 100644 >>>> --- a/drivers/of/overlay.c >>>> +++ b/drivers/of/overlay.c >>>> @@ -708,8 +708,10 @@ int of_overlay_apply(struct device_node *tree, int *ovcs_id) >>>> of_overlay_mutex_lock(); >>>> >>>> ret = of_resolve_phandles(tree); >>>> - if (ret) >>>> + if (ret) { >>>> + kfree(ovcs); >>>> goto err_overlay_unlock; >>>> + } >>>> >>>> mutex_lock(&of_mutex); >>>> >>>> >>> >>> False coverity warning. ovcs is freed in free_overlay_changeset(). >>> >> >> The error exit path is via err_overlay_unlock: >> >> err_overlay_unlock: >> of_overlay_mutex_unlock(); >> >> out: >> pr_debug("%s() err=%d\n", __func__, ret); >> >> return ret; >> >> ..so there is no call to free_overlay_changeset there. >> >> Colin >> > > OK, I was looking at 4.15-rc1. You must be looking at a later version where > "[PATCH 1/2] of: overlay: Fix cleanup order in of_overlay_apply()" has been > applied. Thanks for providing the extra details about the exit path so I > could see that. > > Rob, I think that the fix for cleanup order was not the best way to fix that > problem. A better method would have been to move "mutex_lock(&of_mutex);" > up 5 lines, to just before calling of_reserve_phandles(). It is getting late (midnight my time), so I really should revisit this all tomorrow. My last comment ("move ... up 5 lines") is probably wrong. I'll look at this after some sleep. > The problem > found by coverity was caused by the "Fix cleanup order" patch. > > I can create that alternate fix if you would like, but I am traveling > right now and don't want to submit a patch without boot testing, so > there will be a slight delay. > > -Frank From 1585499339452170881@xxx Thu Nov 30 13:53:18 +0000 2017 X-GM-THRID: 1585429190845296766 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread