linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Niels Dossche <dossche.niels@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Niels Dossche <dossche.niels@gmail.com>,
	Christoph Hellwig <hch@infradead.org>
Subject: [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock
Date: Fri, 25 Mar 2022 20:00:02 +0100	[thread overview]
Message-ID: <20220325190001.1832-1-dossche.niels@gmail.com> (raw)

Currently, there is a fallback with a WARN that uses down_read_trylock
as a safety measure for when there is no lock taken. The current
callsites expect a write lock to be taken. Moreover, the s_root field
is written to, which is not allowed under a read lock.
This code safety fallback should not be executed unless there is an
issue somewhere else.
Using a lockdep assertion better communicates the intent of the code,
and gets rid of the currently slightly wrong fallback solution.

Note:
I am currently working on a static analyser to detect missing locks
using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know.
This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created
this patch. I have both compile-tested this patch and runtime-tested
this patch on x86_64. The effect on a running system could be a
potential race condition in exceptional cases.
This issue was found on Linux v5.17.

Fixes: c636ebdb186bf ("VFS: Destroy the dentries contributed by a superblock on unmounting")
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---
 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index c84269c6e8bf..0142f15340e5 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1692,7 +1692,7 @@ void shrink_dcache_for_umount(struct super_block *sb)
 {
 	struct dentry *dentry;
 
-	WARN(down_read_trylock(&sb->s_umount), "s_umount should've been locked");
+	lockdep_assert_held_write(&sb->s_umount);
 
 	dentry = sb->s_root;
 	sb->s_root = NULL;
-- 
2.35.1


             reply	other threads:[~2022-03-25 19:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 19:00 Niels Dossche [this message]
2022-03-26  6:44 ` [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock Christoph Hellwig
2022-03-29 15:24 ` Jeff Layton
2022-03-30 10:32 ` Christian Brauner

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=20220325190001.1832-1-dossche.niels@gmail.com \
    --to=dossche.niels@gmail.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@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 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).