Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4669774pxv; Tue, 29 Jun 2021 12:36:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFdplWg3CuttYVdNuXKIBnzNfE/868PE35dQZc8Azn1fmW4CCmUjn50gd28JFEgbRooWJW X-Received: by 2002:a5d:9c43:: with SMTP id 3mr5053015iof.123.1624995410630; Tue, 29 Jun 2021 12:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624995410; cv=none; d=google.com; s=arc-20160816; b=0x665osavrQaUz6piVxP13oKeiqwaw5ER1iKg/DrYHFBgXhhWOWSCjhL9OqhIlaO04 t0v3n6QSjSt8LklsOwGoZn5tW8OllmMC7HrE4a1kqr5h6lvx6655bpRgP38vqk0xL5Lc SNeWmxX9HOHmQuiVbWBsRygLfjgqnLcqNEHxja7hIX7IuNBQnrsCkn1CFb8uGBlw7fWJ Nyy2zEyMG9feSstr+VgdBcbenXhCLACB9DdzFnIXpa4QYCu+c0Gg+IfAVSU+J6QGLdCo bCRwO+6lUlSHMb0l98Zrdam7nifV59Jb1++FfqsM8BL4sh58Hz1GIQ1w4nUURSlBf7Ap /qdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=YS2WgG+tm1E7PR+z7d8KIk2kzEbs0O6AT9o1/tVCqkY=; b=AWFJ5S7XQdLXrJkcgWv6Zgrzsn+CdMlShz7PTl3ZZO6B2iTayD4hYdzQOP2nOgIBU5 +HBIqHJ5f/JmhQOqCM4rkxABl0axh7500rqkTeWvN9nDzIBBxC7qCteBdKrQqeD8+4Be vCJ+7NkbnzSAULkvdVcofdURTNPow2UOyltgR0cAiKE4YJ4tyggsU+7uWQonWq1O7Z64 JB+jV7UdYS3OmRrMU2nOBuT296goUysaN7ZgsbrAD6MAwshVSfkxv96Psb1BENe+fp0Q rXwC/aJm8kvPJGQwPpRKSF+KxtIdklz6C1nwOik5OcmnLrGEfQ0soZOyZQWLtvWcRAC+ AQmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dubeyko-com.20150623.gappssmtp.com header.s=20150623 header.b=U3n9RwRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si20067071ilk.157.2021.06.29.12.36.37; Tue, 29 Jun 2021 12:36:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dubeyko-com.20150623.gappssmtp.com header.s=20150623 header.b=U3n9RwRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234568AbhF2TgW (ORCPT + 99 others); Tue, 29 Jun 2021 15:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232197AbhF2TgV (ORCPT ); Tue, 29 Jun 2021 15:36:21 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44292C061766 for ; Tue, 29 Jun 2021 12:33:53 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id m6-20020a9d1d060000b029044e2d8e855eso21897374otm.8 for ; Tue, 29 Jun 2021 12:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=YS2WgG+tm1E7PR+z7d8KIk2kzEbs0O6AT9o1/tVCqkY=; b=U3n9RwRXoJqysAEH+Lfdr+UguX2OEsKtMAF/USgVtXNCVreoTQim2CLR48JS18vska bmE3ofHMYRmRtU2YxWA9svI8OJEeXbMSFtzB30Em5xtphQiqf7tHqUhySlMIJpoMojXd lrqsit/Htx+PTQ3nIqybve/hPT8sLVk6/hKIRqfeCH/wnokzkTM40qjAWKY0EuRaNbsI BPQsAinHpb1RNDB7M9nIth2ZnP8R5rG3ctapDXz3T8wI2mzlWuH/XCjByQtLr+RTbUoc jbKbyqTrrIGw1OOn/z7r2Y95BDm3KRZNtB9M8+esbS2W4NgZpHncaaR+iqEhGjxX2WSr g/Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=YS2WgG+tm1E7PR+z7d8KIk2kzEbs0O6AT9o1/tVCqkY=; b=dh3HrAS5Aqlq2867VBvhPiVnjdwyORTwNHcnrHZPw2SzOhDSEv0djusmQZJ81SKs1/ hP0bOrXLdu5DajrSTPd4UAkSd5KtoLvtuE5hWArg/AAbukYWTHPUO+Zi3Db8X/x6pKlP YpSRzYS/BfSRIT2Zgaaoxt5ozCRNHuzLWpIZoG5hvwaIrXzY6RqUjobyW7y+kZhNYd3H JiIpDcb9JyeZT13umHm/mb/+A2SuZmBvO0qth0pkQC39At7DHvxIGmECLlnI5T0M3E5C L2lInubrtiOBoOvQJssctnLVkMLxVONyX4zlPWqjKsMCi6lTC9mOxsXXB08k49zSvSh0 gwLg== X-Gm-Message-State: AOAM533f2TQHYOQZ/Yp6niYtX+BNLuEoF4ge1wp6X1ZL0jD5TgobamOL AYfGRGlEre1Vsky7l/Oda/kXwg== X-Received: by 2002:a05:6830:1f51:: with SMTP id u17mr5919112oth.25.1624995232643; Tue, 29 Jun 2021 12:33:52 -0700 (PDT) Received: from smtpclient.apple ([2600:1700:42f0:6600:f8e3:a853:8646:6bc8]) by smtp.gmail.com with ESMTPSA id 35sm4374415oth.49.2021.06.29.12.33.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jun 2021 12:33:52 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Subject: Re: [PATCH 3/3] hfs: add lock nesting notation to hfs_find_init From: Viacheslav Dubeyko In-Reply-To: <20210629144803.62541-4-desmondcheongzx@gmail.com> Date: Tue, 29 Jun 2021 12:33:46 -0700 Cc: gustavoars@kernel.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com Content-Transfer-Encoding: quoted-printable Message-Id: <763B3E9F-1D48-4D0E-830C-8260D2329627@dubeyko.com> References: <20210629144803.62541-1-desmondcheongzx@gmail.com> <20210629144803.62541-4-desmondcheongzx@gmail.com> To: Desmond Cheong Zhi Xi X-Mailer: Apple Mail (2.3654.100.0.2.22) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jun 29, 2021, at 7:48 AM, Desmond Cheong Zhi Xi = wrote: >=20 > Syzbot reports a possible recursive lock: > = https://syzkaller.appspot.com/bug?id=3Df007ef1d7a31a469e3be7aeb0fde0769b18= 585db >=20 > This happens due to missing lock nesting information. =46rom the logs, > we see that a call to hfs_fill_super is made to mount the hfs > filesystem. While searching for the root inode, the lock on the > catalog btree is grabbed. Then, when the parent of the root isn't > found, a call to __hfs_bnode_create is made to create the parent of > the root. This eventually leads to a call to hfs_ext_read_extent which > grabs a lock on the extents btree. >=20 > Since the order of locking is catalog btree -> extents btree, this > lock hierarchy does not lead to a deadlock. >=20 > To tell lockdep that this locking is safe, we add nesting notation to > distinguish between catalog btrees, extents btrees, and attributes > btrees (for HFS+). This has already been done in hfsplus. >=20 > Reported-and-tested-by: = syzbot+b718ec84a87b7e73ade4@syzkaller.appspotmail.com > Signed-off-by: Desmond Cheong Zhi Xi > --- > fs/hfs/bfind.c | 14 +++++++++++++- > fs/hfs/btree.h | 7 +++++++ > 2 files changed, 20 insertions(+), 1 deletion(-) >=20 > diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c > index 4af318fbda77..ef9498a6e88a 100644 > --- a/fs/hfs/bfind.c > +++ b/fs/hfs/bfind.c > @@ -25,7 +25,19 @@ int hfs_find_init(struct hfs_btree *tree, struct = hfs_find_data *fd) > fd->key =3D ptr + tree->max_key_len + 2; > hfs_dbg(BNODE_REFS, "find_init: %d (%p)\n", > tree->cnid, __builtin_return_address(0)); > - mutex_lock(&tree->tree_lock); > + switch (tree->cnid) { > + case HFS_CAT_CNID: > + mutex_lock_nested(&tree->tree_lock, = CATALOG_BTREE_MUTEX); > + break; > + case HFS_EXT_CNID: > + mutex_lock_nested(&tree->tree_lock, = EXTENTS_BTREE_MUTEX); > + break; > + case HFS_ATTR_CNID: > + mutex_lock_nested(&tree->tree_lock, ATTR_BTREE_MUTEX); > + break; > + default: > + return -EINVAL; > + } > return 0; > } >=20 > diff --git a/fs/hfs/btree.h b/fs/hfs/btree.h > index 4ba45caf5939..0e6baee93245 100644 > --- a/fs/hfs/btree.h > +++ b/fs/hfs/btree.h > @@ -13,6 +13,13 @@ typedef int (*btree_keycmp)(const btree_key *, = const btree_key *); >=20 > #define NODE_HASH_SIZE 256 >=20 > +/* B-tree mutex nested subclasses */ > +enum hfs_btree_mutex_classes { > + CATALOG_BTREE_MUTEX, > + EXTENTS_BTREE_MUTEX, > + ATTR_BTREE_MUTEX, > +}; > + > /* A HFS BTree held in memory */ > struct hfs_btree { > struct super_block *sb; > --=20 > 2.25.1 >=20 Looks good to me. Reviewed-by: Viacheslav Dubeyko Thanks, Slava.