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

From
Theodore Ts'o <tytso@mit.edu>
Date
2021-07-06 16:04:09
Also in
lkml
Reply to
Jan Kara, 2021-07-06
On Tue, Jul 06, 2021 at 01:11:37PM +0200, Jan Kara wrote:
quoted
--- 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.
quoted
+		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.
quoted
+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
Thread (16 messages) 16 messages, 6 authors, last reply 2021-07-07
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help