From: Christian Brauner <brauner@kernel.org>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, bernd.schubert@fastmail.fm
Subject: Re: [RFC PATCH] vfs: add inode lockdep assertions
Date: Fri, 1 Sep 2023 14:43:07 +0200 [thread overview]
Message-ID: <20230901-begehbar-schubsen-4f59559ad581@brauner> (raw)
In-Reply-To: <20230831151414.2714750-1-mjguzik@gmail.com>
On Thu, Aug 31, 2023 at 05:14:14PM +0200, Mateusz Guzik wrote:
> Thread "Use exclusive lock for file_remove_privs" [1] reports an issue
> which should have been found by asserts -- inode not write locked by the
> caller.
>
> It did not happen because the attempt to do it in notify_change:
> WARN_ON_ONCE(!inode_is_locked(inode));
>
> passes if the inode is only read-locked:
> static inline int rwsem_is_locked(struct rw_semaphore *sem)
> {
> return atomic_long_read(&sem->count) != 0;
> }
>
> According to git blame this regressed from 2 commits:
> 1. 5955102c9984 ("wrappers for ->i_mutex access") which replaced a
> bunch of mutex_is_locked with inode_is_locked
> 2. 9902af79c01a ("parallel lookups: actual switch to rwsem") which
> implemented inode_is_locked as a mere check on the semaphore being
> held in *any* manner
>
> In order to remedy this I'm proposing lockdep-ing the check with 2
> helpers: inode_assert_locked and inode_assert_write_locked
>
> Below I'm adding the helpers and converting *some* of the spots modified
> by the first patch. I boot tested it and nothing blow up on ext4, but
> btrfs should cause a complaint.
>
> I can finish the other spots originally touched by 1 and touch up the 3
> uses I grepped in fs/namei.c, but ultimately filesystem maintainers are
> going to have to patch their code at their leasure. On top of that there
> are probably quite a few places which should assert, but don't.
>
> Comments?
I think this is useful and I would be supportive of this.
next prev parent reply other threads:[~2023-09-01 12:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-31 15:14 [RFC PATCH] vfs: add inode lockdep assertions Mateusz Guzik
2023-09-01 12:43 ` Christian Brauner [this message]
2023-09-06 15:20 ` Matthew Wilcox
2023-09-06 15:23 ` Bernd Schubert
2023-09-06 15:27 ` Matthew Wilcox
2023-09-14 13:16 ` Mateusz Guzik
2023-09-06 15:29 ` Darrick J. Wong
2023-09-06 16:00 ` Matthew Wilcox
2023-09-06 17:07 ` Darrick J. Wong
2023-09-06 18:33 ` Matthew Wilcox
2023-09-06 18:43 ` Darrick J. Wong
2023-09-06 19:01 ` Matthew Wilcox
2023-09-06 19:19 ` Darrick J. Wong
2023-09-06 21:10 ` Matthew Wilcox
2023-09-06 21:26 ` Darrick J. Wong
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=20230901-begehbar-schubsen-4f59559ad581@brauner \
--to=brauner@kernel.org \
--cc=bernd.schubert@fastmail.fm \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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).