From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "frank.li@vivo.com" <frank.li@vivo.com>,
"glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
"penguin-kernel@I-love.SAKURA.ne.jp"
<penguin-kernel@I-love.SAKURA.ne.jp>,
"slava@dubeyko.com" <slava@dubeyko.com>,
"brauner@kernel.org" <brauner@kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file()
Date: Fri, 11 Jul 2025 17:21:09 +0000 [thread overview]
Message-ID: <ead8611697a8a95a80fb533db86c108ff5f66f6f.camel@ibm.com> (raw)
In-Reply-To: <244c8da9-4c5e-42ed-99c7-ceee3e039a9c@I-love.SAKURA.ne.jp>
On Fri, 2025-07-11 at 20:35 +0900, Tetsuo Handa wrote:
> On 2025/07/10 7:03, Tetsuo Handa wrote:
> > On 2025/07/10 3:33, Viacheslav Dubeyko wrote:
> > > My worry that we could have a race condition here. Let's imagine that two
> > > threads are trying to call __hfsplus_setxattr() and both will try to create the
> > > Attributes File. Potentially, we could end in situation when inode could have
> > > not zero size during hfsplus_create_attributes_file() in one thread because
> > > another thread in the middle of Attributes File creation. Could we double check
> > > that we don't have the race condition here? Otherwise, we need to make much
> > > cleaner fix of this issue.
> >
> > I think that there is some sort of race window, for
> > https://elixir.bootlin.com/linux/v6.15.5/source/fs/hfsplus/xattr.c#L145
> > explains that if more than one thread concurrently reached
> >
> > if (!HFSPLUS_SB(inode->i_sb)->attr_tree) {
> > err = hfsplus_create_attributes_file(inode->i_sb);
> > if (unlikely(err))
> > goto end_setxattr;
> > }
> >
> > path, all threads except one thread will fail with -EAGAIN.
> >
>
> Do you prefer stricter mount-time validation shown below?
> Is vhdr->attr_file.total_blocks == 0 when sbi->attr_tree exists and is empty?
>
> diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
> index 948b8aaee33e..f6324a0458f3 100644
> --- a/fs/hfsplus/super.c
> +++ b/fs/hfsplus/super.c
> @@ -482,13 +482,17 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
> goto out_close_ext_tree;
> }
> atomic_set(&sbi->attr_tree_state, HFSPLUS_EMPTY_ATTR_TREE);
> - if (vhdr->attr_file.total_blocks != 0) {
> - sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
> - if (!sbi->attr_tree) {
> - pr_err("failed to load attributes file\n");
> - goto out_close_cat_tree;
> + sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
> + if (sbi->attr_tree) {
> + if (vhdr->attr_file.total_blocks != 0) {
> + atomic_set(&sbi->attr_tree_state, HFSPLUS_VALID_ATTR_TREE);
> + } else {
> + pr_err("found attributes file despite total blocks is 0\n");
> + goto out_close_attr_tree;
> }
> - atomic_set(&sbi->attr_tree_state, HFSPLUS_VALID_ATTR_TREE);
> + } else if (vhdr->attr_file.total_blocks != 0) {
> + pr_err("failed to load attributes file\n");
> + goto out_close_cat_tree;
> }
> sb->s_xattr = hfsplus_xattr_handlers;
>
Frankly speaking, I still don't see the whole picture here. If we have created
the Attribute File during mount operation, then why should we try to create the
Attributes File during __hfsplus_setxattr() call? If we didn't create the
Attributes File during the mount time and HFSPLUS_SB(inode->i_sb)->attr_tree is
NULL, then how i_size_read(attr_file) != 0? Even if we are checking vhdr-
>attr_file.total_blocks, then it doesn't provide guarantee that
i_size_read(attr_file) is zero too. Something is wrong in this situation and
more stricter mount time validation cannot guarantee against the situation that
you are trying to solve in the issue. We are missing something here.
Thanks,
Slava.
next prev parent reply other threads:[~2025-07-11 17:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 10:10 Tetsuo Handa
2025-06-30 17:18 ` Viacheslav Dubeyko
2025-07-07 14:22 ` Yangtao Li
2025-07-07 14:45 ` Tetsuo Handa
2025-07-07 19:03 ` Viacheslav Dubeyko
2025-07-09 14:02 ` Tetsuo Handa
2025-07-09 18:33 ` Viacheslav Dubeyko
2025-07-09 22:03 ` Tetsuo Handa
2025-07-11 11:35 ` Tetsuo Handa
2025-07-11 17:21 ` Viacheslav Dubeyko [this message]
2025-07-12 11:22 ` Tetsuo Handa
2025-07-14 23:30 ` Viacheslav Dubeyko
2025-07-15 5:17 ` [PATCH v2] " Tetsuo Handa
2025-07-15 18:49 ` Viacheslav Dubeyko
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=ead8611697a8a95a80fb533db86c108ff5f66f6f.camel@ibm.com \
--to=slava.dubeyko@ibm.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=slava@dubeyko.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
all inboxes | Powered by JetHome®