Received: by 10.223.164.202 with SMTP id h10csp665919wrb; Thu, 30 Nov 2017 05:38:22 -0800 (PST) X-Google-Smtp-Source: AGs4zMbCBmVAOkZdqqNkL7KwHOpSf5ibSTHGMd0scmZTpFam5DHSELF+FHBu/UHVovc0xOcL0AI/ X-Received: by 10.84.235.1 with SMTP id o1mr2696096plk.168.1512049102524; Thu, 30 Nov 2017 05:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512049102; cv=none; d=google.com; s=arc-20160816; b=RhgBjIonVU/NGiUh2qVQjRdW3iyKRAtvZk36uRLs0ACiXdZRqvD4N2aIHC7Zynhn5i yZtmnxgjpvwJr869BNBm11sO1meLOPFwQ/bWmwWVyUf+DdRlFlTFZ6FcFpa4GLZWqrYN QKU3mh+xJyfU5cRHwsLTJC+/wposmKOiXObWLOL9ARQtjEq9SU5W3oZ6U6K46Tunc9i1 1zysXlfjBEv0rhkiJoFrrPwDfwQGrTRoYlNiFNh0hZAZPDEd37Yw/Zn/NeBDsxkB3pNX +1pfu2Cp5KH0aUBSBF7uNQBBnX9oWrcMXm1i82OECixnJLyrSNi2jHzshshrp/Hui+Tu JvRQ== 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 :arc-authentication-results; bh=5rmyBOJkTzteZ3RCE9o9CZ1OPQqOpvyk8P0NzghvfM4=; b=eg2huL+GQ+36TJ4RTbJvl0q/A3CPURc3QGyHJ1mSc07RauHC1VONMNjMcIbS4Bc+NH /lvtVGMDtT9XmCk2LGP3eOUVTZVMdQNPcnkdUaXK/nyWUuBSRL4+CdUELhSpa9h6b6Yy lHrKw3MChi2moc5SxbvwiYs1fjI2xj147QbBVJVnV0l3e7cqVKG3dDyw/S1lIrjUKakP MB8u5o8vk2qMBWYDy6dcmT3hvT5RubjB2jBefA7AjflK/5bGyNCNin2wDXil9jp2exzm Ifeqz81hwLVZ9+v5ogTAU8JrDtNPmSHRxPJQrddX9Sr43pWsoXMQi48kB7qHU1pU65/F eZRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l+NbVPTL; 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 f7si3266688pff.45.2017.11.30.05.38.09; Thu, 30 Nov 2017 05:38:22 -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=l+NbVPTL; 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 S1752812AbdK3Nh1 (ORCPT + 99 others); Thu, 30 Nov 2017 08:37:27 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:37082 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752054AbdK3NhZ (ORCPT ); Thu, 30 Nov 2017 08:37:25 -0500 Received: by mail-pf0-f194.google.com with SMTP id n6so3117890pfa.4; Thu, 30 Nov 2017 05:37:24 -0800 (PST) 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=5rmyBOJkTzteZ3RCE9o9CZ1OPQqOpvyk8P0NzghvfM4=; b=l+NbVPTLM0R5ebEvmL9aGZc2TfbnHmAiq7LjFdZ70K4+wFUmb0dtyV5npWQl2gP050 MuPplyCnElcO6k9lHkGlSJ4kedc1O8EIA2/XY1fPsiIBM1LuGkfsnstBuU4buMa559ZQ GoO4DK3iE369k64at8yxE6Vq/WcpqkOjC4z++pvOJCiGMarnwPcxlWlNAPDbBQLmc2C+ eB0JbBsHGrbSBx8aXbjYHJldaYhw+p+lBaVXcyNROwXafJNUI1pua+7O1M1pMKjwPj3l ZRsdOuK6q06hVVbuw5di78cThaxkzG9L1Apg7V9ecXl/u3H61XQD6zFeoOf7lsq9/aOL +sIA== 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=5rmyBOJkTzteZ3RCE9o9CZ1OPQqOpvyk8P0NzghvfM4=; b=f6w372c4/8GU5TvTwNtFk/Kuj5Pn0Uso8V+SrD6N53MfD5khPgTJ3OsK5mjeIPANAC dIWbZ/3cnUKV/p0UIiJSH4c67b4kUahEhU4seL6UtCydSWSOHsuBtGITYxgFRa/Cta3e 4fdNzbLKlnwz4bZ1mtppzb8guhn9pLQQSXGQmRzzqvGGA4fbvZCLiICJCNh0WtBlqVr2 7ErNvsJ2UAr1yoPXWROhLgdhDcBvp6Bms8hKU8GPKVZpvIDRmd7g6ByY9MsDLNS/TVIR jRdBCEShOOPF68mKErXy4n5spek1l5U8xIPR+0RGqJYl9l84LG4bOqAUdK98pHNMzvrc SBAw== X-Gm-Message-State: AJaThX7iI7KquP+kcvFh7SqwAclQlezTqKaFEVaHq9/jtaKj4KA/9hBo pO1PqvDZFAn+IyhoZarjBtwS1I3K X-Received: by 10.98.105.8 with SMTP id e8mr6065741pfc.170.1512049044554; Thu, 30 Nov 2017 05:37:24 -0800 (PST) Received: from [192.168.43.210] (mobile-166-170-39-52.mycingular.net. [166.170.39.52]) by smtp.gmail.com with ESMTPSA id x21sm6083926pfi.174.2017.11.30.05.37.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 05:37:24 -0800 (PST) Subject: Re: [PATCH] of: overlay: fix memory leak of ovcs on error exit path 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> From: Frank Rowand Message-ID: <75d7d1c8-8a19-1a4c-0796-7cf69fdebe6d@gmail.com> Date: Thu, 30 Nov 2017 08:37:09 -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: <806a0467-87c8-4100-c7f2-54cfa8732465@canonical.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 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(). 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 1585495847263891866@xxx Thu Nov 30 12:57:48 +0000 2017 X-GM-THRID: 1585429190845296766 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread