From: Amir Goldstein <amir73il@gmail.com>
To: Icenowy Zheng <icenowy@aosc.io>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
Xiao Yang <yangx.jy@cn.fujitsu.com>,
overlayfs <linux-unionfs@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
stable <stable@vger.kernel.org>
Subject: Re: [PATCH] ovl: use a dedicated semaphore for dir upperfile caching
Date: Sun, 3 Jan 2021 16:10:55 +0200 [thread overview]
Message-ID: <CAOQ4uxgNWkzVphdB7cAkwdUXagM_NsCUYDRT1f-=X1rn1-KpUQ@mail.gmail.com> (raw)
In-Reply-To: <20210101201230.768653-1-icenowy@aosc.io>
On Fri, Jan 1, 2021 at 10:12 PM Icenowy Zheng <icenowy@aosc.io> wrote:
>
> The function ovl_dir_real_file() currently uses the semaphore of the
> inode to synchronize write to the upperfile cache field.
>
> However, this function will get called by ovl_ioctl_set_flags(), which
> utilizes the inode semaphore too. In this case ovl_dir_real_file() will
> try to claim a lock that is owned by a function in its call stack, which
> won't get released before ovl_dir_real_file() returns.
oops. I wondered why I didn't see any warnings on this from lockdep.
Ah! because the xfstest that exercises ovl_ioctl_set_flags() on directory,
generic/079, starts with an already upper dir.
And the xfstest that checks chattr+i on lower/upper files, overlay/040,
does not check chattr on dirs (ioctl on overlay dirs wasn't supported at
the time the test was written).
Would you be able to create a variant of test overlay/040 that also tests
chattr +i on lower/upper dirs to test your patch and confirm that the test
fails on master with the appropriate Kconfig debug options.
>
> Define a dedicated semaphore for the upperfile cache, so that the
> deadlock won't happen.
>
> Fixes: 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories")
> Cc: stable@vger.kernel.org # v5.10
> Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
> ---
> fs/overlayfs/readdir.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
> index 01620ebae1bd..f10701aabb71 100644
> --- a/fs/overlayfs/readdir.c
> +++ b/fs/overlayfs/readdir.c
> @@ -56,6 +56,7 @@ struct ovl_dir_file {
> struct list_head *cursor;
> struct file *realfile;
> struct file *upperfile;
> + struct semaphore upperfile_sem;
mutex please
> };
>
> static struct ovl_cache_entry *ovl_cache_entry_from_node(struct rb_node *n)
> @@ -883,7 +884,7 @@ struct file *ovl_dir_real_file(const struct file *file, bool want_upper)
> ovl_path_upper(dentry, &upperpath);
> realfile = ovl_dir_open_realfile(file, &upperpath);
>
> - inode_lock(inode);
> + down(&od->upperfile_sem);
> if (!od->upperfile) {
> if (IS_ERR(realfile)) {
> inode_unlock(inode);
You missed this unlock
Thanks,
Amir.
next prev parent reply other threads:[~2021-01-03 14:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-01 20:12 [PATCH] ovl: use a dedicated semaphore for dir upperfile caching Icenowy Zheng
2021-01-03 14:10 ` Amir Goldstein [this message]
2021-01-04 7:28 ` Icenowy Zheng
2021-01-04 8:35 ` Amir Goldstein
2021-01-04 8:36 ` Icenowy Zheng
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='CAOQ4uxgNWkzVphdB7cAkwdUXagM_NsCUYDRT1f-=X1rn1-KpUQ@mail.gmail.com' \
--to=amir73il@gmail.com \
--cc=icenowy@aosc.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=stable@vger.kernel.org \
--cc=yangx.jy@cn.fujitsu.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).