Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6512001rdb; Tue, 2 Jan 2024 04:42:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDnQMbedKfCj700rgpAV9RDlR13MCJPBMPyYV3Pc66nazsJa1NhAoQNBTrgJ+5dUy7M9qB X-Received: by 2002:a05:6870:4190:b0:203:ef6e:2319 with SMTP id y16-20020a056870419000b00203ef6e2319mr22294624oac.10.1704199343791; Tue, 02 Jan 2024 04:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704199343; cv=none; d=google.com; s=arc-20160816; b=qudh+DV82kQInGL7wnotlrviMJ6JrlNPx6b3viPQ2E/JegT3k75B/wBTHeR25hLFII JttAzgczXZ1eXU7u6VcBqRZBBYtZXZ0BLMRlQwLkmLY9XVTft4pPkQrYsxcvQFz3hpmR UsRCwkgQNK0qFQ/vbLCepWnyOItHTXuWG+O0zeE9ONeajMrPrnC8d89Nv2OED/mRxX7n N6huusWZvCrfwGb5Nf/VWUjpwBmiSISeqnDYwWgFTPLFzPnj1bL1yzou5pBxz4h0R0Pj 8tUmFb3MFeu6DoZxnoKCdpQUYB9ju7mV0CBw+izG7ZtIIRx51ReCiD4wL3UpWGjGKR7D 7pFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:date :subject:cc:to:from:message-id:dkim-signature; bh=KccDZNyBw07ctq/DN3VElW8F3A1ia8xExihctND/oh4=; fh=PpFnhuOnj8EytqqU1I92Ikm1dwmWz75kmSRqact6Obw=; b=yxwZDUAstGV5ljEKtqULPUITJJlmRM3JhzFl8iuHmq51y9SA2gE+Qe+tobbz8UgOdL q9bFPwaSRKj443HRWgE8VWUhlnhkUHjdlL0HS3VG5JJnOe5snKh9cIvINlpUnbQZcicV Vl7YVBej0epq48eC06D7iMER+sOKzbJE+oauLkdyBFQJ95Qowa/B1EfJllnQxvUlImZ9 TAYRt1Lp0ZsKCh8Guja+ah6LJQKn1N2iyIbr9n9WjIHNQGmC1V75C2L1IMUKMDwm/5ja v/LjBrMDJuL5ssGLYWLVCk9bmzz6y5+7Vosm+8ffyeeIWEaqmoNRDMDq2BrCoPtBCosh cmxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=p5Ru6ZUz; spf=pass (google.com: domain of linux-kernel+bounces-14354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e19-20020a630f13000000b0058974d3c296si17879813pgl.815.2024.01.02.04.42.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 04:42:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=p5Ru6ZUz; spf=pass (google.com: domain of linux-kernel+bounces-14354-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AEAF0B21B2A for ; Tue, 2 Jan 2024 12:42:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31892FC00; Tue, 2 Jan 2024 12:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="p5Ru6ZUz" X-Original-To: linux-kernel@vger.kernel.org Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) (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 2227AFBF0; Tue, 2 Jan 2024 12:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1704199013; bh=KccDZNyBw07ctq/DN3VElW8F3A1ia8xExihctND/oh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=p5Ru6ZUzBdYcgAA/DvsG1qV+UwFHpVhC425WNXaVRjEB7bjlSWzJuSFfOqKovE6AU sxWNT+b/YY3bDE0VsX/qthI0XeFtJT6+/qevhbgXswmwchMG0b1OxKalQplqKGoXUM DcQI+u/SwjokXggvgUP57hbbab6wrAt0G+62F+Nk= Received: from pek-lxu-l1.wrs.com ([111.198.225.215]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 93334A1C; Tue, 02 Jan 2024 20:36:51 +0800 X-QQ-mid: xmsmtpt1704199011tmjb9ifyq Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujvVtpMWdxaTVHmbrXzaCl4eDQp1ppMvKr1B3sZmiP2rPKkpDVT2 Wx22gtapO0SWIPeDdMHzM/pDsl7mOzDQP48b0kIWc35lT2+9r8zpfTFP+HKYPUWHHLByu0/s4Ae0 x2ApYkcNEvsVXDZKfqJgLcAJayxcTN+XUyts0x5OPOhqCceFUC12mZy6McngXf/2DnTK2mJyqfHZ l4H37h5XXIRzXAclsR/47rr3lL7/VuUJ6P8siruJeUdyXbUcAiNoLnHGViUaJ6/3dTelzTVjJ7hB NYTEMxUu3l3pBaqkXHKRstFYz4tgRIIdBOWlePjNYSSTqHKnWlI39YU1FY1yFPopiTLtrK2vmg+t vfcpNz5u0lmRkF7vfwfPjxx5+t25QGqtcgwXuPRFxLLD5xpXmyoV8zwqMhpsoeGblOFxun5x8Ce+ btmdSKb2dNRV9GLxSZp/csIEVUlDim/DeIg8fJeVS1CV4EVn7Us8wR/7z7Yyjry2sk2tbSOKk/d0 fxG9ock9UqKE62M9ivXdHKIuIecQlcLBzO4xkgn3bUHCTAsmhS0VZ40mfCFKSCw5aNQ68M6PTCWt ZnRmLqFfNPSN4HHf/OF208uflBXEP6+3EYF8nGxWTfvL6OjPtcqlXPIZCtbcnMDs4JOdgrpmlXTW HPvnyHjAkVnBD6G/FofN95KWRnoadgUqQxN1yU5NjG8Iy5emIANXUeUhPrM7AvvzrwDhXky7Awnk DB7S8uapn1593i1VneE+x5cFU7zZa3A8nknRZ/OU02fTEoZ4gP2Fnpacypdcda/WpR0yk3YpdM6Z LHR6yjY+sqSrSkJt8p7VRL7YTgbVGLJ487OwXJ6++h9QKYOBgF4ca++/iIvq7Hu7fyKgVbdFzY2n 0Uz9Uk3y5OkUo1Uy4d+p+9cZ6V8ZsGwSr/H/58X2mmXGGANpazBfPYieixh0XEAbrHW4iiYF/zhK zH6adJif8= X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: Edward Adam Davis To: syzbot+41a88b825a315aac2254@syzkaller.appspotmail.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, willy@infradead.org Subject: [PATCH] hfs: fix deadlock in hfs_extend_file Date: Tue, 2 Jan 2024 20:36:51 +0800 X-OQ-MSGID: <20240102123651.1582577-2-eadavis@qq.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <0000000000004efa57060def87be@google.com> References: <0000000000004efa57060def87be@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit [syz report] syz-executor279/5059 is trying to acquire lock: ffff888079c100f8 (&HFS_I(tree->inode)->extents_lock){+.+.}-{3:3}, at: hfs_extend_file+0xa2/0xb10 fs/hfs/extent.c:397 but task is already holding lock: ffff888079c10778 (&HFS_I(tree->inode)->extents_lock){+.+.}-{3:3}, at: hfs_extend_file+0xa2/0xb10 fs/hfs/extent.c:397 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&HFS_I(tree->inode)->extents_lock); lock(&HFS_I(tree->inode)->extents_lock); *** DEADLOCK *** [Analysis] hfs_extend_file()-> hfs_ext_read_extent()-> __hfs_ext_cache_extent()-> __hfs_ext_write_extent()-> hfs_bmap_reserve()-> hfs_extend_file()-> When an inode has both the HFS_FLG_EXT_DIRTY and HFS_FLG_EXT_NEW flags, it will enter the above loop and trigger a deadlock. [Fix] In hfs_ext_read_extent(), check if the above two flags exist simultaneously, and exit the subsequent process when the conditions are met. Reported-and-tested-by: syzbot+41a88b825a315aac2254@syzkaller.appspotmail.com Signed-off-by: Edward Adam Davis --- fs/hfs/extent.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c index 6d1878b99b30..1b02c7b6a10c 100644 --- a/fs/hfs/extent.c +++ b/fs/hfs/extent.c @@ -197,6 +197,10 @@ static int hfs_ext_read_extent(struct inode *inode, u16 block) block < HFS_I(inode)->cached_start + HFS_I(inode)->cached_blocks) return 0; + if (HFS_I(inode)->flags & HFS_FLG_EXT_DIRTY && + HFS_I(inode)->flags & HFS_FLG_EXT_NEW) + return -ENOENT; + res = hfs_find_init(HFS_SB(inode->i_sb)->ext_tree, &fd); if (!res) { res = __hfs_ext_cache_extent(&fd, inode, block); -- 2.43.0