* [PATCH] ext4: protect ext4_acquire_dquot against freezing
@ 2026-11-23 11:46 Ye Bin
2026-11-23 12:02 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Ye Bin @ 2026-11-23 11:46 UTC (permalink / raw)
To: tytso, adilger.kernel, linux-ext4; +Cc: jack, brauner
From: Ye Bin <yebin10@huawei.com>
A writable open of a regular file reaches the filesystem's ->open()
callback without holding any superblock write (freeze) protection, but
ext4_file_open() -> dquot_file_open() -> dquot_initialize() may need to
acquire a dquot and write the quota file. If the filesystem reaches
SB_FREEZE_COMPLETE in that window, ext4_journal_check_start() hits
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
and the open then sleeps in jbd2 until the filesystem is thawed.
The background and the earlier discussion of this problem are described
in:
https://patchwork.kernel.org/project/linux-fsdevel/patch/20261112135245.3347102-1-yebin@huaweicloud.com/
The initial attempt added mnt_want_write() for every writable open of a
regular file in do_open(). Christian Brauner pointed out that this would
make a plain open(O_WRONLY|O_RDWR) on a frozen filesystem block even when
it never writes -- log files, editors and backup tools would hang rather
than fail on a later write, which is a drastic and unacceptable uapi
change. As Jan Kara noted, the write comes from the quota acquisition
path, so it should be fixed there instead of penalizing the whole VFS
layer. Jan also suggested using sb_start_intwrite() in the filesystem's
.acquire_dquot method, which neither deadlocks nor changes VFS semantics.
ocfs2 is already fine because ocfs2_start_trans() takes sb_start_intwrite()
itself, so only ext4 needs the fix.
Protect the quota acquisition path itself: take sb_start_intwrite()
around ext4_acquire_dquot() when no transaction is already running.
Running transactions are already protected against freezing and taking
sb_start_intwrite() inside one can deadlock.
Fixes: 907f4554e252 ("dquot: move dquot initialization responsibility into the filesystem")
Suggested-by: Jan Kara <jack@suse.cz>
Link: https://patchwork.kernel.org/project/linux-fsdevel/patch/20261112135245.3347102-1-yebin@huaweicloud.com/
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/ext4/super.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index d0415e5948e1..fc63219f5972 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7110,11 +7110,25 @@ static int ext4_acquire_dquot(struct dquot *dquot)
{
int ret, err;
handle_t *handle;
+ bool freeze_protected = false;
+
+ /*
+ * Trying to sb_start_intwrite() in a running transaction
+ * can result in a deadlock. Further, running transactions
+ * are already protected from freezing.
+ */
+ if (!ext4_journal_current_handle()) {
+ sb_start_intwrite(dquot->dq_sb);
+ freeze_protected = true;
+ }
handle = ext4_journal_start(dquot_to_inode(dquot), EXT4_HT_QUOTA,
EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
- if (IS_ERR(handle))
+ if (IS_ERR(handle)) {
+ if (freeze_protected)
+ sb_end_intwrite(dquot->dq_sb);
return PTR_ERR(handle);
+ }
ret = dquot_acquire(dquot);
if (ret < 0)
ext4_error_err(dquot->dq_sb, -ret,
@@ -7123,6 +7137,10 @@ static int ext4_acquire_dquot(struct dquot *dquot)
err = ext4_journal_stop(handle);
if (!ret)
ret = err;
+
+ if (freeze_protected)
+ sb_end_intwrite(dquot->dq_sb);
+
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: protect ext4_acquire_dquot against freezing
2026-11-23 11:46 [PATCH] ext4: protect ext4_acquire_dquot against freezing Ye Bin
@ 2026-11-23 12:02 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 12:02 UTC (permalink / raw)
To: Ye Bin, linux-ext4; +Cc: tytso
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ext4: deadlock with thaw_super() in ext4_acquire_dquot() via
Q_XGETQUOTA
--
commit f23e3eb68e6a88d3c8dec26c7efee607385b6388
Author: Ye Bin <yebin10@huawei.com>
ext4: protect ext4_acquire_dquot against freezing
This commit wraps ext4_acquire_dquot() with sb_start_intwrite() and
sb_end_intwrite() when no journal transaction is currently active to
protect quota acquisition against filesystem freezing.
Link: https://patchwork.kernel.org/project/linux-fsdevel/patch/20261112135245.3347102-1-yebin@huaweicloud.com/
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 359f9d4ed4479..a06d5f298c849 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -7118,11 +7118,25 @@ static int ext4_acquire_dquot(struct dquot *dquot)
> {
> int ret, err;
> handle_t *handle;
> + bool freeze_protected = false;
> +
> + /*
> + * Trying to sb_start_intwrite() in a running transaction
> + * can result in a deadlock. Further, running transactions
> + * are already protected from freezing.
> + */
> + if (!ext4_journal_current_handle()) {
> + sb_start_intwrite(dquot->dq_sb);
> + freeze_protected = true;
> + }
[Severity: High]
Can calling sb_start_intwrite() here cause an ABBA deadlock between
sb->s_umount and SB_FREEZE_FS when Q_XGETQUOTA or Q_XGETNEXTQUOTA runs on
a frozen filesystem?
quotactl_cmd_write() returns 0 for Q_XGETQUOTA and Q_XGETNEXTQUOTA, so
quotactl_block() and quotactl_fd() acquire down_read(&sb->s_umount)
without waiting for the filesystem to thaw. If the queried dquot is not
yet active in memory, dquot_get_dqblk() calls dqget() ->
ext4_acquire_dquot() with no running transaction and blocks in
sb_start_intwrite() while holding s_umount:
CPU0 CPU1
---- ----
down_read(&sb->s_umount)
sb_freeze_unlock(sb, SB_FREEZE_FS)
sb_start_intwrite(sb)
down_write(&sb->s_umount)
*** DEADLOCK ***
CPU0: do_quotactl() -> quota_getxquota() -> dquot_get_dqblk() ->
dqget() -> ext4_acquire_dquot()
CPU1: thaw_super() -> super_lock_excl() -> thaw_super_locked()
Once this happens, thaw_super() cannot acquire s_umount to unfreeze the
filesystem, leaving the filesystem permanently wedged.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123114602.66520-1-yebin@huaweicloud.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 12:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 11:46 [PATCH] ext4: protect ext4_acquire_dquot against freezing Ye Bin
2026-11-23 12:02 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox