From: Matthew Wilcox <willy@infradead.org>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Bernd Schubert <bschubert@ddn.com>,
linux-fsdevel@vger.kernel.org, bernd.schubert@fastmail.fm,
miklos@szeredi.hu, dsingh@ddn.com,
Josef Bacik <josef@toxicpanda.com>,
linux-btrfs@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH 0/2] Use exclusive lock for file_remove_privs
Date: Wed, 6 Sep 2023 16:13:40 +0100 [thread overview]
Message-ID: <ZPiXJMh/qYQ09Y2R@casper.infradead.org> (raw)
In-Reply-To: <CAGudoHE6LVCFU6w6+4WHY=Bx7SSTCggzO+CihWeaRgWRy+EXtg@mail.gmail.com>
On Fri, Sep 01, 2023 at 01:47:10PM +0200, Mateusz Guzik wrote:
> On 9/1/23, Matthew Wilcox <willy@infradead.org> wrote:
> > On Thu, Aug 31, 2023 at 12:18:24PM +0200, Mateusz Guzik wrote:
> >> So I figured an assert should be there on the write lock held, then the
> >> issue would have been automagically reported.
> >>
> >> Turns out notify_change has the following:
> >> WARN_ON_ONCE(!inode_is_locked(inode));
> >>
> >> Which expands to:
> >> static inline int rwsem_is_locked(struct rw_semaphore *sem)
> >> {
> >> return atomic_long_read(&sem->count) != 0;
> >> }
> >>
> >> So it does check the lock, except it passes *any* locked state,
> >> including just readers.
> >>
> >> According to git blame this regressed from commit 5955102c9984
> >> ("wrappers for ->i_mutex access") by Al -- a bunch of mutex_is_locked
> >> were replaced with inode_is_locked, which unintentionally provides
> >> weaker guarantees.
> >>
> >> I don't see a rwsem helper for wlock check and I don't think it is all
> >> that beneficial to add. Instead, how about a bunch of lockdep, like so:
> >> diff --git a/fs/attr.c b/fs/attr.c
> >> index a8ae5f6d9b16..f47e718766d1 100644
> >> --- a/fs/attr.c
> >> +++ b/fs/attr.c
> >> @@ -387,7 +387,7 @@ int notify_change(struct mnt_idmap *idmap, struct
> >> dentry *dentry,
> >> struct timespec64 now;
> >> unsigned int ia_valid = attr->ia_valid;
> >>
> >> - WARN_ON_ONCE(!inode_is_locked(inode));
> >> + lockdep_assert_held_write(&inode->i_rwsem);
> >>
> >> error = may_setattr(idmap, inode, ia_valid);
> >> if (error)
> >>
> >> Alternatively hide it behind inode_assert_is_wlocked() or whatever other
> >> name.
> >
> > Better to do it like mmap_lock:
> >
> > static inline void mmap_assert_write_locked(struct mm_struct *mm)
> > {
> > lockdep_assert_held_write(&mm->mmap_lock);
> > VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
> > }
> >
>
> May I suggest continuing this with responses to the patch I sent? ;)
That's annoying. Don't split this kind of conversation up if you don't
have to.
> [RFC PATCH] vfs: add inode lockdep assertions on -fsdevel
>
> I made it line up with asserts for i_mmap_rwsem.
>
> btw your non-lockdep check suffers the very problem I'm trying to fix
> here -- checking for *any* locked state.
I'll respond to this over there then.
prev parent reply other threads:[~2023-09-06 15:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 18:15 [PATCH 0/2] Use exclusive lock for file_remove_privs Bernd Schubert
2023-08-30 18:15 ` [PATCH 1/2] fs: Add and export file_needs_remove_privs Bernd Schubert
2023-09-01 6:48 ` Christoph Hellwig
2023-08-30 18:15 ` [PATCH 2/2] btrfs: file_remove_privs needs an exclusive lock Bernd Schubert
2023-08-31 7:40 ` [PATCH 0/2] Use exclusive lock for file_remove_privs Christoph Hellwig
2023-08-31 10:17 ` Bernd Schubert
2023-08-31 10:18 ` Mateusz Guzik
2023-08-31 14:41 ` Bernd Schubert
2023-09-01 6:49 ` Christoph Hellwig
2023-09-01 11:38 ` Matthew Wilcox
2023-09-01 11:47 ` Mateusz Guzik
2023-09-06 15:13 ` Matthew Wilcox [this message]
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=ZPiXJMh/qYQ09Y2R@casper.infradead.org \
--to=willy@infradead.org \
--cc=bernd.schubert@fastmail.fm \
--cc=brauner@kernel.org \
--cc=bschubert@ddn.com \
--cc=dsingh@ddn.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mjguzik@gmail.com \
--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 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).