Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4691060ybg; Tue, 29 Oct 2019 10:57:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqweZOZBOv3J/XQqXeB7wd9p5gzFyI0Ydq2itEM3WJ4C8Xquv2fpf5Z42w0ekFlCX0m06GRd X-Received: by 2002:a05:6402:1490:: with SMTP id e16mr13208872edv.64.1572371857366; Tue, 29 Oct 2019 10:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572371857; cv=none; d=google.com; s=arc-20160816; b=TC0uvay7vqTsLEuACrw6TuPds611yBIiM4hC6yqnsYiDdZsRx+TkMo2GGdTuvppyw4 T4UZfpFPzKTptWG0t+iS0aGDBNWcMW1EB8L5IV3Cw4aTHzfPmTDm6/gD/q0Zyhtox57N JAjZxNg7IQYPx0F1uUm0Df4/xeIVb6mBTCuvoQP46sJ909b1vyV0j95VhqlJwJB+E3Ed kHqBNmGZOCGGMUHqvDmlzgZ3BtRfFFMCFBqbwDdrogBKfps65SR7xzsDb5lSNZSSPGkP giiHDvfVuvund+bXThaClULtpfQ9Zmr79dYG8gURsK0/RZp/Tz4+aNUAfz6GmXmieniS 5ZvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/Tn/VVMmRjmEpU72/PP+0DOD99ZkAIL+sJmfdc1SevY=; b=OT0q+31o4Xtat9kZSiclmdGhdtX0wEBBtK/ReG76Lxi7ZylEy3xjESNH0nAzqITro7 7iwGlaB3zCK6shXuJq7YMIEnn/ZLIGgS+CKhzRn2cvErxzzCNfoaaf2rmvsEtM291KKJ xgSpQnWpaFhiagEVgwo7+54zJy5otmkXLXCOL2DiUcpF0xyWJPO/4MvNHJ6yntDalO3A uz3jTK7lQCNX6TEBxiDr7B1zV+1I3jxy/ANuoxTyiCNurJZj0M0zvEYswtBzU6IfSm6V VWSUQ9uDCNJ7S8Rt2fkZkfEBhtdURWSSNc/pn924IbwamRxqITLTLdwO7GUs1lN+okxL ulHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rvhypy4F; 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 v16si9406178edc.142.2019.10.29.10.57.14; Tue, 29 Oct 2019 10:57:37 -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=rvhypy4F; 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 S1730075AbfJ2KZQ (ORCPT + 99 others); Tue, 29 Oct 2019 06:25:16 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43660 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729109AbfJ2KZP (ORCPT ); Tue, 29 Oct 2019 06:25:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id n1so5534011wra.10 for ; Tue, 29 Oct 2019 03:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/Tn/VVMmRjmEpU72/PP+0DOD99ZkAIL+sJmfdc1SevY=; b=rvhypy4FIQfjiYeZ4plidaSIM4JrY4orvXUW6HjHg6kevotVv9VGQd4BgsRA7F11+R +8a+WkS1dWV8QQqPpCt2OjlK+kWDuoNnmgZAms8s/8q1qYY1jeJ3Qt4Z537cp4+rusfQ FSCMQ9/McSCpYXjFNnAbguHqwyZh16rPv3N4oWNEJdNHmJMvQ+acHezUpMSCDP4c1gX4 ZCj9HeWg5SLFeph3IsZvumFAbxxoy7JOVIHrb+rqcav5TAlW+e/s/jEkduiy/6mAkNYt ReOJLrbIg0jaNMt5hwgB1PU1Ty404vy9KJ5Wkpgito8kUatOIAOxNm3YevOrrrDmRUUS M8mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/Tn/VVMmRjmEpU72/PP+0DOD99ZkAIL+sJmfdc1SevY=; b=hrnUoP6OJKeESKL7ykniFmvXheevP5iL61aR4LlyeDelbJMpsR7nBvEV8F70fgnmq1 6om3kkY8mxYIcW+Og5Sxul+xwRI6MDZna6ZiW/yIrMrCPaIJczsD0iHWHn5YRMDb8xXO 3zfu6hevWMP6+yZhzK1bpENEyXYhKRXksQeG+j+cXY4TJn1nKBSYDrnXRFOf+MfMzQLL U9BlDwgm3Dt4mep4SUOPC3PvwhRquequYcS+w4XJs1gt8TCdvCqZSEivLD3X3ODM7n/m uFT7Xc9ugoMYU0B5iEsVrCOLmrnRAB7Rje9+byaI5MeCQo2v8N/YNXoekyfSIzxcT/Fd EShA== X-Gm-Message-State: APjAAAWEHSHkCEaproMtgnovRQjSxK8CUnftpDBNc3HFRz0b8PIdd9bi dtRvr3cl20tvxofI4zZl7QBzie9EuEN9ZgD4NBo= X-Received: by 2002:a5d:4dd2:: with SMTP id f18mr18366035wru.4.1572344713587; Tue, 29 Oct 2019 03:25:13 -0700 (PDT) MIME-Version: 1.0 References: <1572339670-68694-1-git-send-email-chengzhihao1@huawei.com> <20191029092057.fsklsibqrmbmacar@pengutronix.de> In-Reply-To: <20191029092057.fsklsibqrmbmacar@pengutronix.de> From: Richard Weinberger Date: Tue, 29 Oct 2019 11:25:01 +0100 Message-ID: Subject: Re: [PATCH] ubifs: do_kill_orphans: Fix a memory leak bug To: Sascha Hauer Cc: Zhihao Cheng , Richard Weinberger , "zhangyi (F)" , linux-mtd@lists.infradead.org, LKML , Artem Bityutskiy Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 29, 2019 at 10:21 AM Sascha Hauer wrote: > > On Tue, Oct 29, 2019 at 05:01:10PM +0800, Zhihao Cheng wrote: > > 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) > > --- > > fs/ubifs/orphan.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c > > index 3b4b411..f211ed3 100644 > > --- a/fs/ubifs/orphan.c > > +++ b/fs/ubifs/orphan.c > > @@ -673,9 +673,11 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb, > > if (first) > > first = 0; > > > > - ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS); > > - if (!ino) > > - return -ENOMEM; > > + if (!ino) { > > + ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS); > > + if (!ino) > > + return -ENOMEM; > > + } > > This solves only part of the problem. There are several places in the > loop that just return instead of jumping to out_free. These need to be > fixed as well. > I am not sure if it's worth it to allocate ino on demand. It would be > more straight forward to allocate it once initially before the loop. > Not sure though what Richard prefers. Yeah, allocating it outside the loop once would be the best solution. I don't know why I did it in the loop. ;-\ -- Thanks, //richard