* [PATCH] fs: hold freeze protection across writable regular file ->open()
@ 2026-11-12 13:52 Ye Bin
2026-11-12 17:56 ` Josef Bacik
2026-11-20 11:19 ` Christian Brauner
0 siblings, 2 replies; 6+ messages in thread
From: Ye Bin @ 2026-11-12 13:52 UTC (permalink / raw)
To: viro, brauner, jack, linux-fsdevel
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.
->open() can nevertheless write to the filesystem: ext4_file_open() ->
dquot_file_open() -> dquot_initialize() may acquire a dquot and write
the quota file, which starts a jbd2 transaction. 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 hole was created over time:
- Commit 907f4554e252 ("dquot: move dquot initialization responsibility
into the filesystem") moved quota initialization into ->open() and
introduced dquot_file_open(), making ->open() a potentially writing
operation for writable opens.
- Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
mnt_drop_write()") added sb_start_write() to mnt_want_write() but
deliberately kept the write reference held by an open file on the
non-freezing __mnt_want_write() variant, so the file's own write
reference does not protect its ->open().
- Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
temporary mnt_want_write() early") moved the temporary write count
into do_last() and dropped it before finish_open(), so a writable
open that is not O_TRUNC reaches ->open() with no sb write count at
all.
Since then only O_TRUNC opens take mnt_want_write() in do_open().
Fix this by taking mnt_want_write() for any writable open of a regular
file and holding it across vfs_open()/->open(). Regular files are
checked explicitly so that opening device nodes on a read-only mount is
not newly rejected. Read-only opens are unaffected.
Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
fs/namei.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index f573fd0aacaf..0ee4cf282cf5 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
const struct mnt_idmap *idmap;
int open_flag = op->open_flag;
bool do_truncate;
+ bool got_write;
int acc_mode;
int error;
@@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
return -ENOTDIR;
do_truncate = false;
+ got_write = false;
acc_mode = op->acc_mode;
if (file->f_mode & FMODE_CREATED) {
/* Don't check for write permission, don't truncate */
open_flag &= ~O_TRUNC;
acc_mode = 0;
} else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
+ do_truncate = true;
+ }
+
+ /*
+ * ->open() can write to the filesystem, e.g. when it initializes
+ * quota, so writable opens of regular files need freeze protection
+ * as well. O_TRUNC opens already need it for handle_truncate().
+ */
+ if (do_truncate ||
+ (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
error = mnt_want_write(nd->path.mnt);
if (error)
return error;
@@ -4950,7 +4962,7 @@ static int do_open(struct nameidata *nd,
* while we need to undo write access below.
*/
mnt = mntget(nd->path.mnt);
- do_truncate = true;
+ got_write = true;
}
error = may_open(idmap, &nd->path, acc_mode, open_flag);
if (!error && !(file->f_mode & FMODE_OPENED))
@@ -4963,7 +4975,7 @@ static int do_open(struct nameidata *nd,
WARN_ON(1);
error = -EINVAL;
}
- if (do_truncate) {
+ if (got_write) {
mnt_drop_write(mnt);
mntput(mnt);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: hold freeze protection across writable regular file ->open()
2026-11-12 13:52 [PATCH] fs: hold freeze protection across writable regular file ->open() Ye Bin
@ 2026-11-12 17:56 ` Josef Bacik
2026-11-16 7:11 ` yebin
2026-11-20 11:19 ` Christian Brauner
1 sibling, 1 reply; 6+ messages in thread
From: Josef Bacik @ 2026-11-12 17:56 UTC (permalink / raw)
To: Ye Bin; +Cc: viro, brauner, jack, linux-fsdevel
On Thu, Nov 12, 2026 at 09:52:45PM +0800, Ye Bin wrote:
> 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.
> ->open() can nevertheless write to the filesystem: ext4_file_open() ->
> dquot_file_open() -> dquot_initialize() may acquire a dquot and write
> the quota file, which starts a jbd2 transaction. 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 hole was created over time:
>
> - Commit 907f4554e252 ("dquot: move dquot initialization responsibility
> into the filesystem") moved quota initialization into ->open() and
> introduced dquot_file_open(), making ->open() a potentially writing
> operation for writable opens.
>
> - Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
> mnt_drop_write()") added sb_start_write() to mnt_want_write() but
> deliberately kept the write reference held by an open file on the
> non-freezing __mnt_want_write() variant, so the file's own write
> reference does not protect its ->open().
>
> - Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
> temporary mnt_want_write() early") moved the temporary write count
> into do_last() and dropped it before finish_open(), so a writable
> open that is not O_TRUNC reaches ->open() with no sb write count at
> all.
>
> Since then only O_TRUNC opens take mnt_want_write() in do_open().
>
> Fix this by taking mnt_want_write() for any writable open of a regular
> file and holding it across vfs_open()/->open(). Regular files are
> checked explicitly so that opening device nodes on a read-only mount is
> not newly rejected. Read-only opens are unaffected.
>
> Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
> fs/namei.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index f573fd0aacaf..0ee4cf282cf5 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
> const struct mnt_idmap *idmap;
> int open_flag = op->open_flag;
> bool do_truncate;
> + bool got_write;
> int acc_mode;
> int error;
>
> @@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
> return -ENOTDIR;
>
> do_truncate = false;
> + got_write = false;
> acc_mode = op->acc_mode;
> if (file->f_mode & FMODE_CREATED) {
> /* Don't check for write permission, don't truncate */
> open_flag &= ~O_TRUNC;
> acc_mode = 0;
> } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
> + do_truncate = true;
> + }
> +
> + /*
> + * ->open() can write to the filesystem, e.g. when it initializes
> + * quota, so writable opens of regular files need freeze protection
> + * as well. O_TRUNC opens already need it for handle_truncate().
> + */
> + if (do_truncate ||
> + (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
This is convoluted, you can get rid of the do_truncate flag altogether,
just do
if (d_is_reg(nd->path.dentry) &&
((open_flag & O_TRUNC) || (file->f_mode & FMOD_WRITE))) {
// mntwrite thing
go_write = true;
}
And the delete the extra else if block. Thanks,
Josef
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: hold freeze protection across writable regular file ->open()
2026-11-12 17:56 ` Josef Bacik
@ 2026-11-16 7:11 ` yebin
0 siblings, 0 replies; 6+ messages in thread
From: yebin @ 2026-11-16 7:11 UTC (permalink / raw)
To: Josef Bacik; +Cc: viro, brauner, jack, linux-fsdevel
On 2026/11/13 1:56, Josef Bacik wrote:
> On Thu, Nov 12, 2026 at 09:52:45PM +0800, Ye Bin wrote:
>> 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.
>> ->open() can nevertheless write to the filesystem: ext4_file_open() ->
>> dquot_file_open() -> dquot_initialize() may acquire a dquot and write
>> the quota file, which starts a jbd2 transaction. 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 hole was created over time:
>>
>> - Commit 907f4554e252 ("dquot: move dquot initialization responsibility
>> into the filesystem") moved quota initialization into ->open() and
>> introduced dquot_file_open(), making ->open() a potentially writing
>> operation for writable opens.
>>
>> - Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
>> mnt_drop_write()") added sb_start_write() to mnt_want_write() but
>> deliberately kept the write reference held by an open file on the
>> non-freezing __mnt_want_write() variant, so the file's own write
>> reference does not protect its ->open().
>>
>> - Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
>> temporary mnt_want_write() early") moved the temporary write count
>> into do_last() and dropped it before finish_open(), so a writable
>> open that is not O_TRUNC reaches ->open() with no sb write count at
>> all.
>>
>> Since then only O_TRUNC opens take mnt_want_write() in do_open().
>>
>> Fix this by taking mnt_want_write() for any writable open of a regular
>> file and holding it across vfs_open()/->open(). Regular files are
>> checked explicitly so that opening device nodes on a read-only mount is
>> not newly rejected. Read-only opens are unaffected.
>>
>> Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>> ---
>> fs/namei.c | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/namei.c b/fs/namei.c
>> index f573fd0aacaf..0ee4cf282cf5 100644
>> --- a/fs/namei.c
>> +++ b/fs/namei.c
>> @@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
>> const struct mnt_idmap *idmap;
>> int open_flag = op->open_flag;
>> bool do_truncate;
>> + bool got_write;
>> int acc_mode;
>> int error;
>>
>> @@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
>> return -ENOTDIR;
>>
>> do_truncate = false;
>> + got_write = false;
>> acc_mode = op->acc_mode;
>> if (file->f_mode & FMODE_CREATED) {
>> /* Don't check for write permission, don't truncate */
>> open_flag &= ~O_TRUNC;
>> acc_mode = 0;
>> } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
>> + do_truncate = true;
>> + }
>> +
>> + /*
>> + * ->open() can write to the filesystem, e.g. when it initializes
>> + * quota, so writable opens of regular files need freeze protection
>> + * as well. O_TRUNC opens already need it for handle_truncate().
>> + */
>> + if (do_truncate ||
>> + (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
>
> This is convoluted, you can get rid of the do_truncate flag altogether,
> just do
>
> if (d_is_reg(nd->path.dentry) &&
> ((open_flag & O_TRUNC) || (file->f_mode & FMOD_WRITE))) {
> // mntwrite thing
> go_write = true;
> }
>
> And the delete the extra else if block. Thanks,
>
Thank you for your reply.
At first, I also wanted to remove the 'do_truncate' parameter, but this
parameter is still used later. So I decided to keep it.
do_open() :
...
if (!error)
error = security_file_post_open(file, op->acc_mode);
if (!error && do_truncate) // The 'do_truncate' parameter is required.
error = handle_truncate(idmap, file);
if (unlikely(error > 0)) {
WARN_ON(1);
error = -EINVAL;
}
...
> Josef
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: hold freeze protection across writable regular file ->open()
2026-11-12 13:52 [PATCH] fs: hold freeze protection across writable regular file ->open() Ye Bin
2026-11-12 17:56 ` Josef Bacik
@ 2026-11-20 11:19 ` Christian Brauner
2026-11-20 12:56 ` Jan Kara
1 sibling, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2026-11-20 11:19 UTC (permalink / raw)
To: Ye Bin; +Cc: viro, jack, linux-fsdevel
On Thu, Nov 12, 2026 at 09:52:45PM +0800, Ye Bin wrote:
> 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.
> ->open() can nevertheless write to the filesystem: ext4_file_open() ->
> dquot_file_open() -> dquot_initialize() may acquire a dquot and write
> the quota file, which starts a jbd2 transaction. 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 hole was created over time:
>
> - Commit 907f4554e252 ("dquot: move dquot initialization responsibility
> into the filesystem") moved quota initialization into ->open() and
> introduced dquot_file_open(), making ->open() a potentially writing
> operation for writable opens.
>
> - Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
> mnt_drop_write()") added sb_start_write() to mnt_want_write() but
> deliberately kept the write reference held by an open file on the
> non-freezing __mnt_want_write() variant, so the file's own write
> reference does not protect its ->open().
>
> - Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
> temporary mnt_want_write() early") moved the temporary write count
> into do_last() and dropped it before finish_open(), so a writable
> open that is not O_TRUNC reaches ->open() with no sb write count at
> all.
>
> Since then only O_TRUNC opens take mnt_want_write() in do_open().
>
> Fix this by taking mnt_want_write() for any writable open of a regular
> file and holding it across vfs_open()/->open(). Regular files are
> checked explicitly so that opening device nodes on a read-only mount is
> not newly rejected. Read-only opens are unaffected.
>
> Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
> fs/namei.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index f573fd0aacaf..0ee4cf282cf5 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
> const struct mnt_idmap *idmap;
> int open_flag = op->open_flag;
> bool do_truncate;
> + bool got_write;
> int acc_mode;
> int error;
>
> @@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
> return -ENOTDIR;
>
> do_truncate = false;
> + got_write = false;
> acc_mode = op->acc_mode;
> if (file->f_mode & FMODE_CREATED) {
> /* Don't check for write permission, don't truncate */
> open_flag &= ~O_TRUNC;
> acc_mode = 0;
> } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
> + do_truncate = true;
> + }
> +
> + /*
> + * ->open() can write to the filesystem, e.g. when it initializes
> + * quota, so writable opens of regular files need freeze protection
> + * as well. O_TRUNC opens already need it for handle_truncate().
> + */
> + if (do_truncate ||
> + (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
> error = mnt_want_write(nd->path.mnt);
No, I don't think that's the right thing to do. Every
open(O_WRONLY|O_RDWR) would now block for a regular file on a frozen
filesystem even if it never writes. That's not acceptable. Log files,
editors, backup tools, they all would hang rather than fail on write.
It's a drastic uapi change.
The write in ->open() is from the quota stuff. So that should be a quota
fix and not penalize the whole VFS layer.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: hold freeze protection across writable regular file ->open()
2026-11-20 11:19 ` Christian Brauner
@ 2026-11-20 12:56 ` Jan Kara
2026-11-21 1:19 ` yebin
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2026-11-20 12:56 UTC (permalink / raw)
To: Christian Brauner; +Cc: Ye Bin, viro, jack, linux-fsdevel
On Fri 20-11-26 12:19:03, Christian Brauner wrote:
> On Thu, Nov 12, 2026 at 09:52:45PM +0800, Ye Bin wrote:
> > 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.
> > ->open() can nevertheless write to the filesystem: ext4_file_open() ->
> > dquot_file_open() -> dquot_initialize() may acquire a dquot and write
> > the quota file, which starts a jbd2 transaction. 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 hole was created over time:
> >
> > - Commit 907f4554e252 ("dquot: move dquot initialization responsibility
> > into the filesystem") moved quota initialization into ->open() and
> > introduced dquot_file_open(), making ->open() a potentially writing
> > operation for writable opens.
> >
> > - Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
> > mnt_drop_write()") added sb_start_write() to mnt_want_write() but
> > deliberately kept the write reference held by an open file on the
> > non-freezing __mnt_want_write() variant, so the file's own write
> > reference does not protect its ->open().
> >
> > - Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
> > temporary mnt_want_write() early") moved the temporary write count
> > into do_last() and dropped it before finish_open(), so a writable
> > open that is not O_TRUNC reaches ->open() with no sb write count at
> > all.
> >
> > Since then only O_TRUNC opens take mnt_want_write() in do_open().
> >
> > Fix this by taking mnt_want_write() for any writable open of a regular
> > file and holding it across vfs_open()/->open(). Regular files are
> > checked explicitly so that opening device nodes on a read-only mount is
> > not newly rejected. Read-only opens are unaffected.
> >
> > Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
> > Signed-off-by: Ye Bin <yebin10@huawei.com>
> > ---
> > fs/namei.c | 16 ++++++++++++++--
> > 1 file changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/namei.c b/fs/namei.c
> > index f573fd0aacaf..0ee4cf282cf5 100644
> > --- a/fs/namei.c
> > +++ b/fs/namei.c
> > @@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
> > const struct mnt_idmap *idmap;
> > int open_flag = op->open_flag;
> > bool do_truncate;
> > + bool got_write;
> > int acc_mode;
> > int error;
> >
> > @@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
> > return -ENOTDIR;
> >
> > do_truncate = false;
> > + got_write = false;
> > acc_mode = op->acc_mode;
> > if (file->f_mode & FMODE_CREATED) {
> > /* Don't check for write permission, don't truncate */
> > open_flag &= ~O_TRUNC;
> > acc_mode = 0;
> > } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
> > + do_truncate = true;
> > + }
> > +
> > + /*
> > + * ->open() can write to the filesystem, e.g. when it initializes
> > + * quota, so writable opens of regular files need freeze protection
> > + * as well. O_TRUNC opens already need it for handle_truncate().
> > + */
> > + if (do_truncate ||
> > + (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
> > error = mnt_want_write(nd->path.mnt);
>
> No, I don't think that's the right thing to do. Every
> open(O_WRONLY|O_RDWR) would now block for a regular file on a frozen
> filesystem even if it never writes. That's not acceptable. Log files,
> editors, backup tools, they all would hang rather than fail on write.
> It's a drastic uapi change.
>
> The write in ->open() is from the quota stuff. So that should be a quota
> fix and not penalize the whole VFS layer.
Conceptually I agree with you but we cannot easily grab freeze protection
from ->open() where we do quota stuff because VFS may but need not be already
holding it.
Somewhat paradoxical is that quota code will actually write anything only
if we are creating quota structures for a new user but that never happens
from ->open (it would happen already during vfs_create() in
dentry_create()). It is just ext4 that unconditionally starts a transaction
because it doesn't know the context... But ocfs2 actually does write if we
are touching the first inode of this user so there the problem is real.
Hrm, but I think we could just use sb_start_intwrite() in filesystem's
.acquire_dquot methods and be done with that. That won't deadlock and it
will silence the warnings / fix ocfs2 breakage. AFAICS only ext4 & ocfs2
actually need anything done. Ye?
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: hold freeze protection across writable regular file ->open()
2026-11-20 12:56 ` Jan Kara
@ 2026-11-21 1:19 ` yebin
0 siblings, 0 replies; 6+ messages in thread
From: yebin @ 2026-11-21 1:19 UTC (permalink / raw)
To: Jan Kara, Christian Brauner; +Cc: viro, linux-fsdevel
On 2026/11/20 20:56, Jan Kara wrote:
> On Fri 20-11-26 12:19:03, Christian Brauner wrote:
>> On Thu, Nov 12, 2026 at 09:52:45PM +0800, Ye Bin wrote:
>>> 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.
>>> ->open() can nevertheless write to the filesystem: ext4_file_open() ->
>>> dquot_file_open() -> dquot_initialize() may acquire a dquot and write
>>> the quota file, which starts a jbd2 transaction. 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 hole was created over time:
>>>
>>> - Commit 907f4554e252 ("dquot: move dquot initialization responsibility
>>> into the filesystem") moved quota initialization into ->open() and
>>> introduced dquot_file_open(), making ->open() a potentially writing
>>> operation for writable opens.
>>>
>>> - Commit eb04c28288bb ("fs: Add freezing handling to mnt_want_write() /
>>> mnt_drop_write()") added sb_start_write() to mnt_want_write() but
>>> deliberately kept the write reference held by an open file on the
>>> non-freezing __mnt_want_write() variant, so the file's own write
>>> reference does not protect its ->open().
>>>
>>> - Commit 64894cf84327 ("simplify lookup_open()/atomic_open() - do the
>>> temporary mnt_want_write() early") moved the temporary write count
>>> into do_last() and dropped it before finish_open(), so a writable
>>> open that is not O_TRUNC reaches ->open() with no sb write count at
>>> all.
>>>
>>> Since then only O_TRUNC opens take mnt_want_write() in do_open().
>>>
>>> Fix this by taking mnt_want_write() for any writable open of a regular
>>> file and holding it across vfs_open()/->open(). Regular files are
>>> checked explicitly so that opening device nodes on a read-only mount is
>>> not newly rejected. Read-only opens are unaffected.
>>>
>>> Fixes: eb04c28288bb ("fs: Add freezing handling to mnt_want_write() / mnt_drop_write()")
>>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>>> ---
>>> fs/namei.c | 16 ++++++++++++++--
>>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/namei.c b/fs/namei.c
>>> index f573fd0aacaf..0ee4cf282cf5 100644
>>> --- a/fs/namei.c
>>> +++ b/fs/namei.c
>>> @@ -4906,6 +4906,7 @@ static int do_open(struct nameidata *nd,
>>> const struct mnt_idmap *idmap;
>>> int open_flag = op->open_flag;
>>> bool do_truncate;
>>> + bool got_write;
>>> int acc_mode;
>>> int error;
>>>
>>> @@ -4935,12 +4936,23 @@ static int do_open(struct nameidata *nd,
>>> return -ENOTDIR;
>>>
>>> do_truncate = false;
>>> + got_write = false;
>>> acc_mode = op->acc_mode;
>>> if (file->f_mode & FMODE_CREATED) {
>>> /* Don't check for write permission, don't truncate */
>>> open_flag &= ~O_TRUNC;
>>> acc_mode = 0;
>>> } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
>>> + do_truncate = true;
>>> + }
>>> +
>>> + /*
>>> + * ->open() can write to the filesystem, e.g. when it initializes
>>> + * quota, so writable opens of regular files need freeze protection
>>> + * as well. O_TRUNC opens already need it for handle_truncate().
>>> + */
>>> + if (do_truncate ||
>>> + (d_is_reg(nd->path.dentry) && (file->f_mode & FMODE_WRITE))) {
>>> error = mnt_want_write(nd->path.mnt);
>>
>> No, I don't think that's the right thing to do. Every
>> open(O_WRONLY|O_RDWR) would now block for a regular file on a frozen
>> filesystem even if it never writes. That's not acceptable. Log files,
>> editors, backup tools, they all would hang rather than fail on write.
>> It's a drastic uapi change.
>>
>> The write in ->open() is from the quota stuff. So that should be a quota
>> fix and not penalize the whole VFS layer.
>
> Conceptually I agree with you but we cannot easily grab freeze protection
> from ->open() where we do quota stuff because VFS may but need not be already
> holding it.
>
> Somewhat paradoxical is that quota code will actually write anything only
> if we are creating quota structures for a new user but that never happens
> from ->open (it would happen already during vfs_create() in
> dentry_create()). It is just ext4 that unconditionally starts a transaction
> because it doesn't know the context... But ocfs2 actually does write if we
> are touching the first inode of this user so there the problem is real.
>
> Hrm, but I think we could just use sb_start_intwrite() in filesystem's
> .acquire_dquot methods and be done with that. That won't deadlock and it
> will silence the warnings / fix ocfs2 breakage. AFAICS only ext4 & ocfs2
> actually need anything done. Ye?
>
I checked the code of ocfs2 and it should be fine, because sb_start_intwrite()
is called when starting a transaction.
ocfs2_acquire_dquot
ocfs2_start_trans
sb_start_intwrite(osb->sb);
So, it should only require fixing the EXT4 file system. That should be enough.
In the ext4_evict_inode() process, calling dquot_initialize() and freezing the
file system concurrently may also trigger a warning.
ext4_evict_inode
dquot_initialize(inode);
if (!ext4_journal_current_handle())
sb_start_intwrite(inode->i_sb);
ext4_journal_start()
The same processing logic in ext4_acquire_dquot() and ext4_evict_inode() should
be fine.
> Honza
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-21 1:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 13:52 [PATCH] fs: hold freeze protection across writable regular file ->open() Ye Bin
2026-11-12 17:56 ` Josef Bacik
2026-11-16 7:11 ` yebin
2026-11-20 11:19 ` Christian Brauner
2026-11-20 12:56 ` Jan Kara
2026-11-21 1:19 ` yebin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.