Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8559252ybl; Thu, 16 Jan 2020 19:35:13 -0800 (PST) X-Google-Smtp-Source: APXvYqx9hghfzhhSPPO5LwHwbQXBxPZNjvWw8dtM8YTUp8Rwao1p1D5QINzKob1IKLJtd50VZaar X-Received: by 2002:aca:4d4f:: with SMTP id a76mr2020359oib.26.1579232113487; Thu, 16 Jan 2020 19:35:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579232113; cv=none; d=google.com; s=arc-20160816; b=IajfTCe070gSfpQmjSgh8eAYRExFvXFs0xXifFjdhL+o2lhGSNkp82OafRy/UfKGT9 pF0SmVlcNBBQTFHyLftjKSM/zKa5Dk1To7/1TJQLihN6P/xbFW1TsyCK5C1xNshjIrZX HD48goAShiwoToljaVEzDzIzBTVlwuB9QUXyiWqM8eE0RxUgULgV8n8WTGa5cgITET6o M0FvbD5RgL75GLi3cNwL6bfqeSlS5otRknYAptzqwShIEsxKK9ZmXVxwdrPUNdTFTkHu n85ruh/gl/2ckMSnzXuCtSMvai1ezS/yxXOylddmnkYltLiM7ckBYji/4/lMQc+wgQaH a6dA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uPxJPWzyGRH+XE3Z3eb5SGZKZ/dwv7lkD7VJBpXQjKI=; b=g7SteNoQb1J83kURyVa3Mf9EgvruM9f3D2mJ8mMmr1LiNlZKzLviJD4VzOxGcMoNug iSefi1NL3eQv1Uyyb0/j6x1T7kNIrThK7Fm7xOd26CDyYlWcxlorGY2vvYQ60055tuoP OIUUbvkLcMH+179xdmuAH038ci0bHyLf8TyzeIotgn5qqPlirifJdpa99HSkxSMOBsND dPcYHpoVAac6hu7anbOfYpWKR7ISkr3SRzat5xf+RcHIQNzd6t+GPucjbc831iWW/8kB CnXUWsYq40ygWMSatIQbBL3hQK3lGk2GOoo4Yo0+6aR3+h28urEblM/p7rcJFG40E3W9 +05A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vd3/qxNo"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16si14030283otq.92.2020.01.16.19.34.57; Thu, 16 Jan 2020 19:35:13 -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="vd3/qxNo"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391733AbgAPXm2 (ORCPT + 99 others); Thu, 16 Jan 2020 18:42:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:57492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729414AbgAPX0k (ORCPT ); Thu, 16 Jan 2020 18:26:40 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 93D0920684; Thu, 16 Jan 2020 23:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579217200; bh=3gmjdTaVUXoSoGNgiGnKtLI5R2KJxvEfY/3ptwXubSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vd3/qxNo4DXqBp1N8odiO342AgKBy417suU9disaPqELo3bFWLyjdFn7w8aoyvCqD NeCf2qhjnp1Zcwz0KSdY8B/PFQYdyFnMqlYARmbdtYmOgAIdXgQHFeqCiJMfHdX2x5 GAA5XvEdObOuj3k2oxU2oCX17HZvJyvdivrG6BuE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , "zhangyi (F)" , Richard Weinberger Subject: [PATCH 5.4 164/203] ubifs: do_kill_orphans: Fix a memory leak bug Date: Fri, 17 Jan 2020 00:18:01 +0100 Message-Id: <20200116231759.013280402@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200116231745.218684830@linuxfoundation.org> References: <20200116231745.218684830@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng commit 10256f000932f12596dc043cf880ecf488a32510 upstream. If there are more than one valid snod on the sleb->nodes list, do_kill_orphans will malloc ino more than once without releasing previous ino's memory. Finally, it will trigger memory leak. Fixes: ee1438ce5dc4 ("ubifs: Check link count of inodes when...") Signed-off-by: Zhihao Cheng Signed-off-by: zhangyi (F) Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- fs/ubifs/orphan.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c @@ -631,12 +631,17 @@ static int do_kill_orphans(struct ubifs_ ino_t inum; int i, n, err, first = 1; + ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS); + if (!ino) + return -ENOMEM; + list_for_each_entry(snod, &sleb->nodes, list) { if (snod->type != UBIFS_ORPH_NODE) { ubifs_err(c, "invalid node type %d in orphan area at %d:%d", snod->type, sleb->lnum, snod->offs); ubifs_dump_node(c, snod->node); - return -EINVAL; + err = -EINVAL; + goto out_free; } orph = snod->node; @@ -663,20 +668,18 @@ static int do_kill_orphans(struct ubifs_ ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d", cmt_no, sleb->lnum, snod->offs); ubifs_dump_node(c, snod->node); - return -EINVAL; + err = -EINVAL; + goto out_free; } dbg_rcvry("out of date LEB %d", sleb->lnum); *outofdate = 1; - return 0; + err = 0; + goto out_free; } if (first) first = 0; - ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS); - if (!ino) - return -ENOMEM; - n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3; for (i = 0; i < n; i++) { union ubifs_key key1, key2;