Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4784167pxv; Tue, 6 Jul 2021 09:04:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNBKTL63SHoj5qBdlz3h1kYzNj+QglUzduACW5KEqxWqDbXYJBr07B0yzo+rPAff6i5y3u X-Received: by 2002:a5e:d80e:: with SMTP id l14mr16248182iok.79.1625587467350; Tue, 06 Jul 2021 09:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625587467; cv=none; d=google.com; s=arc-20160816; b=DFUbmT5if3husTfLl69hayXWna+cXCgREaAdh/V8rDePhl6sVJGMhmt4OrAOKYZsB7 /e1t//ipLnsF/8MnPCLZekQGE5oUdiSBEmRFLjxsD8lvOaTehHTlXHmzLzF/HW98JYX7 1wOKrREf9Wlu0bytu2LKwcIYcoBm2c0jX6ltle/cOlg6h+jYzdYSvuSC194ES1jNMIny QiyF65NqobRnrONsfN5DMf09RUj0QD2H2so1tF6Cc+ASbUV3HFdp0RktMeaeGqUcxgPG hH9MhmEvj4HZOguzqA2WQ6eJVJ1L+DtWrcZ4gY6S9fSsCe2u2g3Svvft4+xLRaonSE7T n/0w== 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=FuIsA+KRohALgrM+2IDDiFB2132A5PMzDVSFWayp1uI=; b=S6xkEzdcj4NaN+eJrmYoGBi4RYEOxhas5dFPG6AKfL1WADHDFco52p9wGCGts+g3/X WXXzwpsYjbEzeESr+BjO+7gdIex1w/EBuSkK7JLVDcYyHnK5Mzcwz2qUVhW44Iy5kQMo 7nLQqxf672RbY8BfcfO/eVDT/KPWeWXVREwu5U45tvomkLdTeO0QPWsW62jlNa9XyGLZ SI/omlYg0kDuQu7BW0BpJ4qu9MTX39mkFxjLeI4qClejBCxUw46odHxzQglbrdTDkOk3 5YW1rs6ff3D5grh8qejbISlCpwbd4zgdiGAUzl6HAtFItWvS+NbahqDAjrMzm0xnSFAu PZjw== 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 w13si16897985jar.0.2021.07.06.09.04.12; Tue, 06 Jul 2021 09:04:27 -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 S229818AbhGFQGo (ORCPT + 99 others); Tue, 6 Jul 2021 12:06:44 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:41982 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229811AbhGFQGn (ORCPT ); Tue, 6 Jul 2021 12:06:43 -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 166G3mOc032309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 6 Jul 2021 12:03:49 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id 3C2CD15C3CC6; Tue, 6 Jul 2021 12:03:48 -0400 (EDT) Date: Tue, 6 Jul 2021 12:03:48 -0400 From: "Theodore Ts'o" To: Jan Kara Cc: Ye Bin , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] ext4: Fix use-after-free about sbi->s_mmp_tsk Message-ID: References: <20210629143603.2166962-1-yebin10@huawei.com> <20210629143603.2166962-2-yebin10@huawei.com> <20210705111548.GD15373@quack2.suse.cz> <20210706111137.GA7922@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210706111137.GA7922@quack2.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Jul 06, 2021 at 01:11:37PM +0200, Jan Kara wrote: > > --- a/fs/ext4/mmp.c > > +++ b/fs/ext4/mmp.c > > @@ -157,6 +157,17 @@ static int kmmpd(void *data) > > sizeof(mmp->mmp_nodename)); > > > > while (!kthread_should_stop()) { > > + if (!(le32_to_cpu(es->s_feature_incompat) & > > + EXT4_FEATURE_INCOMPAT_MMP)) { > > We can probably use ext4_has_feature_mmp() macro when changing this? Ack, I'll make that change. > > + if (sb_rdonly(sb)) { > > + if (!kthread_should_stop()) > > + schedule_timeout_interruptible(HZ); > > Cannot this effectively block remount RO for 1s when we wait for kmmpd to > exit? I think doing 'break' when we detected RO super is fine. We'll write > the mmp block and then wait for kthread_should_stop() condition as in any > other abort case. Am I missing something? Yeah, we do want to update the mmp block when remounting the file system read-only. So breaking out to exit is the right thing to do here. > > +wait_to_exit: > > + while (!kthread_should_stop()) > > + schedule(); > > This makes me a bit nervous that we could unnecessarily burn CPU for > potentially a long time (e.g. if somebody uses tune2fs to disable MMP, we > would be sitting in this loop until the fs in remounted / unmounted). So > maybe we should have something like: > > while (!kthread_should_stop()) { > set_task_state(TASK_INTERRUPTIBLE); > if (!kthread_should_stop()) > schedule(); > } > > This should safely synchronize with (and not miss wakeup from) > kthread_stop() since that first sets KTHREAD_SHOULD_STOP and after that > calls wake_up_process(). Yep, good catch. I'll fix this and send out revised patch. - Ted