[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241007205430.492090-3-pZ010001011111@proton.me>
Date: Mon, 07 Oct 2024 20:55:49 +0000
From: Piotr Zalewski <pZ010001011111@...ton.me>
To: kent.overstreet@...ux.dev, linux-bcachefs@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: skhan@...uxfoundation.org, Piotr Zalewski <pZ010001011111@...ton.me>, syzbot+4d24267b490e2b68a5fa@...kaller.appspotmail.com
Subject: [PATCH v1] bcachefs: use mutex_trylock in bch2_replicas_entry_validate
Use mutex_trylock instead of mutex_lock in bch2_replicas_entry_validate to
prevent potential deadlock[1].
[1] https://syzkaller.appspot.com/bug?extid=4d24267b490e2b68a5fa
Reported-by: syzbot+4d24267b490e2b68a5fa@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4d24267b490e2b68a5fa
Fixes: 49fd90b2cc33 ("bcachefs: Fix unlocked access to c->disk_sb.sb in bch2_replicas_entry_validate()")
Signed-off-by: Piotr Zalewski <pZ010001011111@...ton.me>
---
fs/bcachefs/replicas.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c
index bcb3276747e0..d301832c5a1b 100644
--- a/fs/bcachefs/replicas.c
+++ b/fs/bcachefs/replicas.c
@@ -98,9 +98,10 @@ int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *r,
struct bch_fs *c,
struct printbuf *err)
{
- mutex_lock(&c->sb_lock);
+ int acquired = mutex_trylock(&c->sb_lock);
int ret = bch2_replicas_entry_validate_locked(r, c->disk_sb.sb, err);
- mutex_unlock(&c->sb_lock);
+ if (acquired)
+ mutex_unlock(&c->sb_lock);
return ret;
}
--
2.46.2
Powered by blists - more mailing lists