Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-ext4@vger.kernel.org
Cc: Jaegeuk Kim <jaegeuk@kernel.org>,
	linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	stable@vger.kernel.org
Subject: Re: [PATCH] ext4: fix race between ext4_sync_parent() and rename()
Date: Fri, 15 May 2020 12:14:15 -0700	[thread overview]
Message-ID: <20200515191415.GC1009@sol.localdomain> (raw)
In-Reply-To: <20200506183140.541194-1-ebiggers@kernel.org>

On Wed, May 06, 2020 at 11:31:40AM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> 'igrab(d_inode(dentry->d_parent))' without holding dentry->d_lock is
> broken because without d_lock, d_parent can be concurrently changed due
> to a rename().  Then if the old directory is immediately deleted, old
> d_parent->inode can be NULL.  That causes a NULL dereference in igrab().
> 
> To fix this, use dget_parent() to safely grab a reference to the parent
> dentry, which pins the inode.  This also eliminates the need to use
> d_find_any_alias() other than for the initial inode, as we no longer
> throw away the dentry at each step.
> 
> This is an extremely hard race to hit, but it is possible.  Adding a
> udelay() in between the reads of ->d_parent and its ->d_inode makes it
> reproducible on a no-journal filesystem using the following program:
> 
>     #include <fcntl.h>
>     #include <unistd.h>
> 
>     int main()
>     {
>         if (fork()) {
>             for (;;) {
>                 mkdir("dir1", 0700);
>                 int fd = open("dir1/file", O_RDWR|O_CREAT|O_SYNC);
>                 write(fd, "X", 1);
>                 close(fd);
>             }
>         } else {
>             mkdir("dir2", 0700);
>             for (;;) {
>                 rename("dir1/file", "dir2/file");
>                 rmdir("dir1");
>             }
>         }
>     }
> 
> Fixes: d59729f4e794 ("ext4: fix races in ext4_sync_parent()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@google.com>


Any comments on this patch?

- Eric

  parent reply	other threads:[~2020-05-15 19:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 18:31 Eric Biggers
2020-05-09 12:30 ` Sasha Levin
2020-05-15 19:14 ` Eric Biggers [this message]
2020-05-22  3:34 ` Eric Biggers

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=20200515191415.GC1009@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH] ext4: fix race between ext4_sync_parent() and rename()' \
    /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

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).