From: Jan Kara <jack@suse.cz>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>,
Jan Kara <jack@suse.cz>, Ye Bin <yebin10@huawei.com>
Subject: Re: [PATCH -v3] ext4: fix possible UAF when remounting r/o a mmp-protected file system
Date: Tue, 6 Jul 2021 21:49:10 +0200 [thread overview]
Message-ID: <20210706194910.GC17149@quack2.suse.cz> (raw)
In-Reply-To: <20210706171208.3540887-1-tytso@mit.edu>
On Tue 06-07-21 13:12:08, Theodore Ts'o wrote:
> After commit 618f003199c6 ("ext4: fix memory leak in
> ext4_fill_super"), after the file system is remounted read-only, there
> is a race where the kmmpd thread can exit, causing sbi->s_mmp_tsk to
> point at freed memory, which the call to ext4_stop_mmpd() can trip
> over.
>
> Fix this by only allowing kmmpd() to exit when it is stopped via
> ext4_stop_mmpd().
>
> Link: https://lore.kernel.org/r/YONtEGojq7LcXnuC@mit.edu
> Reported-by: Ye Bin <yebin10@huawei.com>
> Bug-Report-Link: <20210629143603.2166962-1-yebin10@huawei.com>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
The patch looks mostly fine. Two comments below.
> @@ -242,9 +237,13 @@ static int kmmpd(void *data)
> mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
> mmp->mmp_time = cpu_to_le64(ktime_get_real_seconds());
>
> - retval = write_mmp_block(sb, bh);
> + return write_mmp_block(sb, bh);
I think we need to keep retval = write_mmp_block() here. Otherwise we could
exit early in sb_rdonly() case and still have potential use-after-free.
>
> -exit_thread:
> +wait_to_exit:
> + set_current_state(TASK_INTERRUPTIBLE);
> + while (!kthread_should_stop())
> + schedule();
> + set_current_state(TASK_RUNNING);
> return retval;
> }
This is more or less fine but if we get a spurious wakeup for whatever
reason (which sets task to TASK_RUNNING state) we would still be
potentially looping in that loop burning cpu...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2021-07-06 19:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 14:36 [PATCH 0/2] Fix use-after-free about sbi->s_mmp_tsk Ye Bin
2021-06-29 14:36 ` [PATCH 1/2] ext4: " Ye Bin
2021-07-05 11:15 ` Jan Kara
2021-07-05 20:35 ` Theodore Ts'o
2021-07-06 11:11 ` Jan Kara
2021-07-06 16:03 ` Theodore Ts'o
2021-07-06 17:12 ` [PATCH -v3] ext4: fix possible UAF when remounting r/o a mmp-protected file system Theodore Ts'o
2021-07-06 19:49 ` Jan Kara [this message]
2021-07-07 0:24 ` [PATCH -v4] " Theodore Ts'o
2021-07-07 9:30 ` Jan Kara
2021-06-29 14:36 ` [PATCH 2/2] ext4: Fix potential uas-after-free about sbi->s_mmp_tsk when kmmpd kthread exit before set sbi->s_mmp_tsk Ye Bin
2021-07-05 10:52 ` Jan Kara
2021-07-06 0:44 ` Andreas Dilger
2021-07-02 16:57 ` [PATCH] ext4: possible use-after-free when remounting r/o a mmp-protected file system Theodore Ts'o
2021-07-02 21:36 ` kernel test robot
2021-07-03 12:57 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210706194910.GC17149@quack2.suse.cz \
--to=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yebin10@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).