From: Al Viro <viro@zeniv.linux.org.uk>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 2/2] proc: Protect readers of /proc/mounts from remount
Date: Tue, 11 Dec 2018 19:14:52 +0000 [thread overview]
Message-ID: <20181211191451.GJ2217@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20181211185831.GH2217@ZenIV.linux.org.uk>
On Tue, Dec 11, 2018 at 06:58:31PM +0000, Al Viro wrote:
> > +static bool mounts_trylock_super(struct proc_mounts *p, struct super_block *sb)
> > +{
> > + if (p->locked_sb == sb)
> > + return true;
> > + if (p->locked_sb) {
> > + drop_super(p->locked_sb);
> > + p->locked_sb = NULL;
> > + }
> > + if (down_read_trylock(&sb->s_umount)) {
> > + hold_sb(sb);
> > + p->locked_sb = sb;
> > + return true;
> > + }
> > + return false;
> > +}
>
> Bad calling conventions, and you are paying for those with making
> hold_sb() non-static (and having it, in the first place).
>
> > + if (mounts_trylock_super(p, sb))
> > + return p->cached_mount;
> > + /*
> > + * Trylock failed. Since namepace_sem ranks below s_umount (through
> > + * sb->s_umount > dir->i_rwsem > namespace_sem in the mount path), we
> > + * have to drop it, wait for s_umount and then try again to guarantee
> > + * forward progress.
> > + */
> > + hold_sb(sb);
>
> That. Just hoist that hold_sb() into your trylock (and put it before the
> down_read_trylock() there, while we are at it). And turn the other caller
> into
> if (unlikely(!.....))
> ret = -EAGAIN;
> else
> ret = p->show(m, &r->mnt);
> followed by unconditional drop_super(). And I would probably go for
> mount_trylock_super(&p->locked_super, sb)
> while we are at it, so that it's isolated from proc_mounts and can
> be moved to fs/super.c
Looking at it some more... I still hate it ;-/ Take a look at traverse()
in fs/seq_file.c and think what kind of clusterfuck will it cause...
next prev parent reply other threads:[~2018-12-11 19:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 17:24 [PATCH 0/2 RESEND] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-12-11 17:24 ` [PATCH 1/2] vfs: Provide function to grab superblock reference Jan Kara
2018-12-11 17:24 ` [PATCH 2/2] proc: Protect readers of /proc/mounts from remount Jan Kara
2018-12-11 18:36 ` Al Viro
2018-12-11 18:37 ` Al Viro
2018-12-11 18:58 ` Al Viro
2018-12-11 19:14 ` Al Viro [this message]
2018-12-12 12:56 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2018-12-18 13:46 [PATCH 0/2 v2] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-12-18 13:46 ` [PATCH 2/2] proc: Protect readers of /proc/mounts from remount Jan Kara
2018-10-18 13:17 [PATCH 0/2] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-10-18 13:17 ` [PATCH 2/2] proc: Protect readers of /proc/mounts from remount Jan Kara
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=20181211191451.GJ2217@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.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;
as well as URLs for NNTP newsgroup(s).