From nobody Wed Nov 27 22:36:42 2024 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1D5C81727 for ; Mon, 7 Oct 2024 20:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728334561; cv=none; b=DHCxV0rKPoBi71fWvKXhyImatwxNHpbDnZoYmZ4uToT/17PS8f/ZkL03rJ8G+Y3jK6M3gcKq8YHhtfKlymID/DoG6JCStZ6fXOcG4TAhlwosNV4o1aTCltTBwmIqI9qMuW8Cspk7wSAqEaniV68I36ozjQORNF5mbFPJBqZfOGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728334561; c=relaxed/simple; bh=UHPb3s0aO8AlvsA8FlkpPnp/+BstHy9v1B+zYtBQuO0=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=pPrqdB+969qdWwfhLs5SjPrldRAb5udKpICE/qSTkZp1Hi/VXcnPvnLxHjO3w/bc3FnsO71JBDUGrJI4HMyW1VBoLLAUxCvzgvFMsnA9rUlbqjPWY8kS5cg65Y11fy2ubr4Kxb4/OuCy2g5RQfJ8keb+8/tW9vqQXmUy+wY87JE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=T352ba2h; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="T352ba2h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1728334551; x=1728593751; bh=UHPb3s0aO8AlvsA8FlkpPnp/+BstHy9v1B+zYtBQuO0=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=T352ba2hlQh6f0u3ry+uY/ZuzT6syWPNy/1CTRzTBpMBun7oi+9jj37SaQ7O61LWd eeHL1MYvNOiQ1ttWe0J/ZSAqYavdotW8M4n8MIC6QbCAxbgaRM5J+d9aQfwP0KzEKe h7WxrAhwJisJQ19ekqYRysfUpeUMhK9e2/t0jDsj5IuTNXrOUCx85Y+XQLAUhOsMid bfSHB5mKJlF5oRHzyQzST8/JGFTuk+MW/kiQNTN+xm0vPiQMUdi0ZQW4EbXg7jBZZp rx4gvDu6gNeYmaDixk7Dr7uvRI05lA0ToOenAuE7AYFNykFfYOAEWCW9wZwmwKiwFR f8JCLEwzwRVhQ== Date: Mon, 07 Oct 2024 20:55:49 +0000 To: kent.overstreet@linux.dev, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org From: Piotr Zalewski Cc: skhan@linuxfoundation.org, Piotr Zalewski , syzbot+4d24267b490e2b68a5fa@syzkaller.appspotmail.com Subject: [PATCH v1] bcachefs: use mutex_trylock in bch2_replicas_entry_validate Message-ID: <20241007205430.492090-3-pZ010001011111@proton.me> Feedback-ID: 53478694:user:proton X-Pm-Message-ID: 20c7915fb4820f21b71d2d7da571445dcd2b1d9b Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use mutex_trylock instead of mutex_lock in bch2_replicas_entry_validate to prevent potential deadlock[1]. [1] https://syzkaller.appspot.com/bug?extid=3D4d24267b490e2b68a5fa Reported-by: syzbot+4d24267b490e2b68a5fa@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D4d24267b490e2b68a5fa Fixes: 49fd90b2cc33 ("bcachefs: Fix unlocked access to c->disk_sb.sb in bch= 2_replicas_entry_validate()") Signed-off-by: Piotr Zalewski --- 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_ent= ry_v1 *r, struct bch_fs *c, struct printbuf *err) { - mutex_lock(&c->sb_lock); + int acquired =3D mutex_trylock(&c->sb_lock); int ret =3D 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; } =20 --=20 2.46.2