All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Fabian Frederick <fabf@skynet.be>
Cc: Al Viro <viro@ZenIV.linux.org.uk>, Jan Kara <jack@suse.cz>,
	akpm@linux-foundation.org, mm-commits@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: Elevated i_writecount doesn't guarantee ->release to be called
Date: Thu, 29 Jan 2015 17:57:16 +0100	[thread overview]
Message-ID: <20150129165716.GD11635@quack.suse.cz> (raw)
In-Reply-To: <1928119748.16961.1422550076048.open-xchange@webmail.nmp.proximus.be>

On Thu 29-01-15 17:47:56, Fabian Frederick wrote:
> > On 29 January 2015 at 13:46 Jan Kara <jack@suse.cz> wrote:
> >
> >
> >   Changed subject and added linux-fsdevel to CC so that other developers
> > read this don't fall into the same trap :).
> >
> > On Wed 28-01-15 22:45:34, Al Viro wrote:
> > > On Wed, Jan 28, 2015 at 01:45:24PM -0800, akpm@linux-foundation.org wrote:
> > > > atomic_t i_opencnt was used to free allocation in case there were no more
> > > > opens.  This patch replaces affs_file_open by generic_file_open and uses
> > > > FMODE_WRITE/i_writecount==1 for the task like other FS.
> > >
> > >
> > > >  affs_file_release(struct inode *inode, struct file *filp)
> > > >  {
> > > > - pr_debug("release(%lu, %d)\n",
> > > > -          inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt));
> > > > + pr_debug("release(%lu)\n", inode->i_ino);
> > > > 
> > > > - if (atomic_dec_and_test(&AFFS_I(inode)->i_opencnt)) {
> > > > + if ((filp->f_mode & FMODE_WRITE) &&
> > > > +     (atomic_read(&inode->i_writecount) == 1)) {
> > >
> > > I'm not at all convinced that this is correct for affs.  Or for anything
> > > else, for that matter.  Look: suppose somebody else is trying to open
> > > that sucker with O_TRUNC at that moment and they'd already gotten past
> > > get_write_access() in handle_truncate(), only to fail on
> > > locks_verify_locked().
> > > _That_ open() won't get anywhere near opening the file, so there won't be
> > > ->release() for it.  And our ->release() will see ->i_writecount greater
> > > than 1, due to get_write_access() done in handle_truncate() and still not
> > > balanced by coming put_write_access() in there - we'll call it after the
> > > locks_verify_locked() reports failure, but that hasn't happened yet.
> > >
> > > Similar scenarios can almost certainly be constructed for other calls of
> > > get_write_access() as well, but this one is enough to NAK this patch, _and_
> > > to make the similar logics in other filesystems very suspicious...
> >   Thanks for pointing this out. You made me at look where exactly is
> > get_write_access() called and there are even places where we call it
> > without having file descriptor at all (e.g.  truncate path). So ext3, ext4,
> > udf, and gfs2 are racy. If we race, results aren't that bad (we just keep
> > preallocated blocks in the inode) but still it would be nice to fix.
> >
> > Obviously we could maintain a private writecount in ->open() method but it
> > would seem a bit sad to do that for this mostly theoretical issue. Maybe we
> > just verify whether preallocation is truncated when evicting inode from
> > memory and if not, do it there. It's not perfect but even with current racy
> > solution noone noticed in practice.
> Note that udf is slightly different ; it checks for i_writecount > 1 not =1
> which means it would release the file in scenario described above ...
  I know but that's because it has two bugs in a single condition ;) I have
a patch queued for udf which changes the condition to == 1.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2015-01-29 16:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28 21:45 + fs-affs-use-inode-writecount-instead-of-local-i_opencnt.patch added to -mm tree akpm
     [not found] ` <20150128224534.GB29656@ZenIV.linux.org.uk>
2015-01-29 12:46   ` Elevated i_writecount doesn't guarantee ->release to be called Jan Kara
2015-01-29 16:47     ` Fabian Frederick
2015-01-29 16:57       ` Jan Kara [this message]
2015-01-29 17:35     ` Al Viro
2015-01-30  5:33       ` Fabian Frederick

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=20150129165716.GD11635@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=fabf@skynet.be \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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 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.