From: Jan Kara <jack@suse.cz>
To: yangerkun <yangerkun@huaweicloud.com>
Cc: Jan Kara <jack@suse.cz>, yangerkun <yangerkun@huawei.com>,
hch@infradead.org, chuck.lever@oracle.com, brauner@kernel.org,
viro@zeniv.linux.org.uk, hughd@google.com, zlang@kernel.org,
fdmanana@suse.com, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH] libfs: fix infinite directory reads for offset dir
Date: Wed, 31 Jul 2024 15:04:23 +0200 [thread overview]
Message-ID: <20240731130423.wztpcevyzm4cnkjg@quack3> (raw)
In-Reply-To: <57de6354-f53d-d106-aed8-9dff3e88efa6@huaweicloud.com>
On Wed 31-07-24 20:51:05, yangerkun wrote:
> 在 2024/7/31 19:51, Jan Kara 写道:
> > On Wed 31-07-24 12:38:35, yangerkun wrote:
> > > After we switch tmpfs dir operations from simple_dir_operations to
> > > simple_offset_dir_operations, every rename happened will fill new dentry
> > > to dest dir's maple tree(&SHMEM_I(inode)->dir_offsets->mt) with a free
> > > key starting with octx->newx_offset, and then set newx_offset equals to
> > > free key + 1. This will lead to infinite readdir combine with rename
> > > happened at the same time, which fail generic/736 in xfstests(detail show
> > > as below).
> > >
> > > 1. create 5000 files(1 2 3...) under one dir
> > > 2. call readdir(man 3 readdir) once, and get one entry
> > > 3. rename(entry, "TEMPFILE"), then rename("TEMPFILE", entry)
> > > 4. loop 2~3, until readdir return nothing or we loop too many
> > > times(tmpfs break test with the second condition)
> > >
> > > We choose the same logic what commit 9b378f6ad48cf ("btrfs: fix infinite
> > > directory reads") to fix it, record the last_index when we open dir, and
> > > do not emit the entry which index >= last_index. The file->private_data
> > > now used in offset dir can use directly to do this, and we also update
> > > the last_index when we llseek the dir file.
> >
> > The patch looks good! Just I'm not sure about the llseek part. As far as I
> > understand it was added due to this sentence in the standard:
> >
> > "If a file is removed from or added to the directory after the most recent
> > call to opendir() or rewinddir(), whether a subsequent call to readdir()
> > returns an entry for that file is unspecified."
> >
> > So if the offset used in offset_dir_llseek() is 0, then we should update
> > last_index. But otherwise I'd leave it alone because IMHO it would do more
> > harm than good.
>
> IIUC, what you means is that we should only reset the private_data to
> new last_index when we call rewinddir(which will call lseek to set
> offset of dir file to 0)?
Yes, exactly. Sorry for being a bit vague.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-07-31 13:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 4:38 yangerkun
2024-07-31 11:51 ` Jan Kara
2024-07-31 12:51 ` yangerkun
2024-07-31 13:04 ` Jan Kara [this message]
2024-07-31 13:10 ` Filipe Manana
2024-08-01 3:15 ` yangerkun
2024-07-31 13:44 ` Chuck Lever
2024-07-31 14:16 ` Christian Brauner
2024-07-31 15:37 ` Jan Kara
2024-08-01 3:32 ` yangerkun
2024-08-01 13:30 ` Jan Kara
2024-08-01 13:38 ` yangerkun
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=20240731130423.wztpcevyzm4cnkjg@quack3 \
--to=jack@suse.cz \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=fdmanana@suse.com \
--cc=hch@infradead.org \
--cc=hughd@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yangerkun@huawei.com \
--cc=yangerkun@huaweicloud.com \
--cc=zlang@kernel.org \
/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