Re: [PATCH 1/2] ext4: Fix use-after-free about sbi->s_mmp_tsk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux