Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1784638pxy; Thu, 29 Apr 2021 14:41:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySo6v2xkmAaljw/pIgDiXo7VaaqJFAh3cGy90DLKjq/7tIu4BUgDJUcHW4kX6YQpjx/rrl X-Received: by 2002:a17:90a:fb97:: with SMTP id cp23mr11478918pjb.169.1619732515720; Thu, 29 Apr 2021 14:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619732515; cv=none; d=google.com; s=arc-20160816; b=TCq8EtKHCTSvmN/EMwPjoTTiBfklrr2jgK+dZwR3JkDQxNfqu7uXYUGsCHyYl250Ji 1V1g1g/kyHlRfch0pEVEMSK87UUhT0Bs8VFF6izNltgwAYQbApU8vC4O9RUEpuUKryok KAPQE7YLyP6ywR8RS0k6fwybH6smnZZh0Is/b1NNSvNoblEsgTw0usAKAOmBNJ8563qb 8u5Z54g8Ad0SJLcFAAFTV63dmImQSy4XJsPoCiT2xKwuoD81YkCeBiysMvmadVIi1W0X xkVc64S46FFWbC4X2q2TmYC+Gb/RPkNrNPIwuFpGFe0cQ5tjDT8aw/pnCXLVQ/soEvku Ge6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=lNNZ3OW7s3iiaDFjUfhl+Dh0Q1Vu36zbUtsRfHkkQ3c=; b=OM1TSFJuDbllxftqNtQSu7yX6rU6zo71XcYbzZN4NxeJ1LAf1hbVMmjcsdjMypUWXu N+crvEUgFXVU4dgX3v8bu7xeOTO6n7GvcAcGvApgYvQ0G4P9EOhCVi+a5mUu+3hYRiZ5 z2WAYgO/mBvp0CIoq2vfOHxhAe/tu3mBK397SJgjFHQW1sAt2HQcP7NIEsMxI6PF9BvA vRLiYvL0kMtZLYBaKb3NyPF2Wr/z5WLbH6H6vQ8pVVGUL808NwhwXsok+1Ixwc1/wmEW 7yBCd3/Kjz484OtEyQxzekQKs2shXWiNNPkEkmscB2j/Zmg2RiC0PTsZdndR4nkPbxWL y10Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q36si976997pgl.469.2021.04.29.14.41.37; Thu, 29 Apr 2021 14:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235775AbhD2VmW (ORCPT + 99 others); Thu, 29 Apr 2021 17:42:22 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:55614 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237191AbhD2VmW (ORCPT ); Thu, 29 Apr 2021 17:42:22 -0400 Received: from cwcc.thunk.org (pool-72-74-133-215.bstnma.fios.verizon.net [72.74.133.215]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 13TLfCYp030461 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Apr 2021 17:41:13 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id B3F0815C39C4; Thu, 29 Apr 2021 17:41:12 -0400 (EDT) Date: Thu, 29 Apr 2021 17:41:12 -0400 From: "Theodore Ts'o" To: Pavel Skripkin Cc: Vegard Nossum , akpm@linux-foundation.org, peterz@infradead.org, axboe@kernel.dk, pmladek@suse.com, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+d9e482e303930fa4f6ff@syzkaller.appspotmail.com Subject: Re: [PATCH] ext4: fix memory leak in ext4_fill_super Message-ID: References: <20210428172828.12589-1-paskripkin@gmail.com> <3c3877a4-fef2-9e24-f99f-2ecc46deb7e4@oracle.com> <20210429143354.418248a7@gmail.com> <20210429230956.6ad23897@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429230956.6ad23897@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Apr 29, 2021 at 11:09:56PM +0300, Pavel Skripkin wrote: > > we will exit with -ENOMEM. So at the very least all callers of > > kthread_stop() also need to check for -ENOMEM as well as -EINTR --- > > or, be somehow sure that the thread function was successfully called > > and started. In this particular case, the ext4 mount code had just > > started the kmmpd thread, and then detected that something else had > > gone wrong, and failed the mount before the kmmpd thread ever had a > > chance to run. > > There is a small problem about -ENOMEM... What I'd suggest is that we simply move > exit_thread: > EXT4_SB(sb)->s_mmp_tsk = NULL; > kfree(data); > brelse(bh); > return retval; > } out of the thread function. That means hanging struct mmpd_data off the struct ext4_sb_info structure, and then adding a function like this to fs/ext4/mmp.c static void ext4_stop_mmpd(struct ext4_sb_info *sbi) { if (sbi->s_mmp_tsk) { kthread_stop(sbi->s_mmp_tsk); brelse(sbi->s_mmp_data->bh); kfree(sbi->s_mmp_data); sbi->s_mmp_data = NULL; sbi->s_mmp_tsk = NULL; } } Basically, just move all of the cleanup so it is done after the kthread is stopped, so we don't have to do any fancy error checking. We just do it unconditionally. - Ted P.S. Actually, we could drop the struct mmpd_data altogether, and just hang the buffer head as sbi->s_mmp_bh. Then we can just pass the struct super * as the private pointer to kmmpd().