Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp738470imm; Thu, 5 Jul 2018 08:06:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfgljbYXYaNEfa+KLHaLXPtEwRuhGmVNrUZNTPfyjuVdmMBXQHLcNj1uD9hcd+59+aYgzcH X-Received: by 2002:a62:32c4:: with SMTP id y187-v6mr6839136pfy.241.1530803160971; Thu, 05 Jul 2018 08:06:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530803160; cv=none; d=google.com; s=arc-20160816; b=AfuRsrbn9SrifA/yBowCPUcj/foJPRxXlGl2y8I3LBjAcXn88ZgD8m3qSrBdNqClND wxihLsX3jKI8AaOkgTQVWBL32Gyw9tMNnOMkZk51ECu+33tMGDq7Stle1poQaIloRcHT nAKrGyD2e3XFSZkKlV0B47UX8W/Y36V0b7i7IVfYRD/dI4OimpuDhOxPAplfl1YCx29C ZiQuaeF+iwFIVUeTidV4EPopK/EN5pzk7JAmreaGwVs0VILyhS7cHp0SGhxR/I9FMuCz 4NgUjAAwtIg53gTZWvDr2TWpc3+vM5/eg6Kw/hWasEwhCj0/q8wpdZyx1s1t7g26qdKH 0NxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HLF1wfXlh9sraVDuKjrF3Tn88a/CwNzLBpL8/DZw3ww=; b=NryzCH5nzlsot9Fxc7Xe6Qf4Y+F3ib5VjE44dBbI+qF179LNShr6ZknZsiUqqZBrrV e/jc0IwmXhQstP3ZTd0b5xMhuGQDbNE2HYrtOvd4Vek+PJCdJKUjAuEMEdQiuroOgJEi 2bLoLpl/eCXp+bc8XqeNtY+CSgq1NAjbw3ShVj7bQALWJFyJ3KKNsUA0htgl0RiMHHfx MmtCHiWwaefoCw53LZM5elAP7CFy796BXsPySpGT1qyn+tiJYgV+mxPjqKmfjJ9aIgdy JIDzvRsiJgp2sm+sAe597mfVqR3RXc53LLVCCVHsIlRIj/sIzGp4qlBpfMAgWTUJG/MF 2UXw== ARC-Authentication-Results: i=1; mx.google.com; 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 r73-v6si3460963pfk.83.2018.07.05.08.05.30; Thu, 05 Jul 2018 08:06:00 -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; 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 S1754002AbeGEPD3 (ORCPT + 99 others); Thu, 5 Jul 2018 11:03:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:51896 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753655AbeGEPD2 (ORCPT ); Thu, 5 Jul 2018 11:03:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EA8F1AD12; Thu, 5 Jul 2018 15:03:26 +0000 (UTC) From: Luis Henriques To: Evgeniy Dushistov Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Henriques Subject: [PATCH] ufs: Fix memory leak in the unlink path Date: Thu, 5 Jul 2018 16:04:15 +0100 Message-Id: <20180705150415.25070-1-lhenriques@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While running generic xfstests against ufs (ufstype=44bsd), a lot of memory leaks were reported by kmemleak (in particular with generic/074). It is easily reproducible by simply doing: dd if=/dev/zero of=test bs=1024 count=1024 unlink test which will result in having kmemleak reporting: unreferenced object 0xffff8800623f8980 (size 96): comm "unlink", pid 172, jiffies 4294905029 (age 60.804s) hex dump (first 32 bytes): e0 06 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ................ 50 51 df 59 00 88 ff ff a8 50 df 59 00 88 ff ff PQ.Y.....P.Y.... backtrace: [<00000000ceff4f7a>] free_full_branch+0xdc/0x6b0 [<0000000085b47ac6>] ufs_truncate_blocks+0x1532/0x19f0 [<000000008edf50d0>] ufs_evict_inode+0xa5/0xe0 [<00000000561ed122>] evict+0x384/0x530 [<0000000082158199>] iput+0x407/0x5f0 [<00000000a3a41e2b>] do_unlinkat+0x470/0x4d0 [<0000000006651ccb>] do_syscall_64+0x21e/0x580 [<000000008771be7f>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [<000000005a459012>] 0xffffffffffffffff Fix this by kfree'ing the ufs_buffer_head allocated through ubh_bread in free_full_branch. While there, drop the NULL check as this is already done in bforget. Cc: stable@vger.kernel.org Signed-off-by: Luis Henriques --- fs/ufs/util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ufs/util.c b/fs/ufs/util.c index 4fa633f84274..76df052701b0 100644 --- a/fs/ufs/util.c +++ b/fs/ufs/util.c @@ -131,8 +131,9 @@ void ubh_bforget (struct ufs_buffer_head * ubh) unsigned i; if (!ubh) return; - for ( i = 0; i < ubh->count; i++ ) if ( ubh->bh[i] ) + for ( i = 0; i < ubh->count; i++ ) bforget (ubh->bh[i]); + kfree (ubh); } int ubh_buffer_dirty (struct ufs_buffer_head * ubh)