From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796558173; b=HdN056dm46fBFTIsLqrAuKxuBaVkbOWWF7KA4vhLFcn5vNu+FQlFGTkg+d3yi/d7lzjm 0p9WVZ+UiDqKI6Qge+U4qJm9RUmuWFdhjpptsrOafsYkmZLla0Z11nqNbvAkn6Ro6X+zY PsvB5z7qGRaHLcYoQ3z/jMOCTEn5l4oUmtJLChHiZh8hVAc4Lm85r4qMZAHY1vWu0oKeI nfhN1oql0L8doJNfT1EWXV/u0VjnPLsrKEp3c+6CzP8WeCMJBcFCEKgm0H6MPj8KKq9xd /FL9PtkhgG74Inn5uSFHv4x/3SVKehzujgjlyV2UYwjVYhBv6tvt5dvGsUZyi9Hk4mg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796558173; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=WFiqMV8A7yudCkFFy4kUQHwVjLG+y+WnEdMy/SK22qA=; b=KbUrS0DsqOl2jD1yEWDnANT/dOXoxQKPyAfzTe1n2jfUdRmzobrERDGokCkWSh7Akoon lGteRxFB2yQZ3qbUI5YUd2Fvkm+na44CydePL/hf6guuHq15IMdhYhPD33rGA0pZtvjlH 4onxEQf09Mvn35irx2jzUUN272f2Frj0aJje5/V088WVAvohBNllzh2Yk8r0kpCFQwYga LWZQQDQgnjLbQq343rrM/CYO+RIXEUmPyq4AHXYwlGQW5Sr+7UMyE87hw15BuxjAuyybR ezxplO2BQnCYmDJFvByICyaDdejItIGR7ZAi+glMUp0ClFkPUwFTZP3q9z6oMTiUuyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KYIh3pls; arc=none smtp.remote-ip=209.85.214.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15344606A31F for ; Sun, 6 Dec 2026 11:56:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 15344606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KYIh3pls Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2f0481b35c9so16336025ad.0 for ; Sun, 06 Dec 2026 03:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796558172; x=1797162972; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=WFiqMV8A7yudCkFFy4kUQHwVjLG+y+WnEdMy/SK22qA=; b=KYIh3plsTNod8P8qTiPNbcAIlPntirgTQRuF8931q0ooCVQJr2ke9d/eWbkk+wwu6s PQxZlD2Lv9MIf+FGQIuDmLOZPqELJz/xmyrK8tviaeV0OXhS7P8HcHOA+l+n7sNjwts/ 1DshySzVttN7rueliEe69XYyMp+2QPdHVH8zgkA+fnOizx+VibX2XWRJmvN5K875/Al8 6amth3ZwJfCV2AYFAwsDyY7EKEI9pJRbU17eC3aD+aRWvITqfij1+bHdzoxsikTCP6+v qaESje2jp39+WDLaMAoiY4MWlnNxLakB38ijZtB1f37rMfBXLsUbXkyoiCSYrYgFS4Lx eOgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796558172; x=1797162972; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WFiqMV8A7yudCkFFy4kUQHwVjLG+y+WnEdMy/SK22qA=; b=BmOoc5JrtsiN0Tgy5jnWA1kiC4aMzSqmIe8i5jCG2Yb++nsFrWDDGwc9O4jWApuMKN 0o2SO8QtyE3sdwc26AQIVcKai1gsPYF9YDK+YfBkvlssJP4ltCdiq6KqxoK98mV8rTDp 69qerVdOeuzRUn4XPXiATiUA3PC0nC9ZGc0uZRSRJlqGSqrTbbIUKLV6/qKiKiqCM0df Z002SIk2seT1Y5wxQ3R6Aq4BoXU3qAuEGwjHbB9+bnaJDvdQl8IR1ioPav7nAiSt8SXR qmPY2Efl60/79SAP11y2M7JRs5TdBrMFNS84Am4Z7CXMJYAYHZYCGokkq4N4J4l8zyov ssQg== X-Gm-Message-State: AB4q+uHelqsHH4rZqmt+iTIHtbHC8JYgKkjQx8FT6glGT8vfMcqe9UwE q442Tp9oSfBTm6oWyCHBJpAYzANIcbeIdGo3i7JhKPSnIER+jFRW7d9V X-Gm-Gg: AZFdTZeQCZLpeDLUWnH0G8ofaTSuwMVzifExzmef4vOoWtQVmio8iVyCWa13zwEEJgL ehAreiBoDlcm4bBIkpk7/DFpgVMPfHK/Hu6Uyx+VFjWc/Uq4BC47U3exmbyoEp96rwIB7YJGLEU 45mWif5eY958Tb532f1ekuy7OiICUXOP0izkPOEOb+7+rL2pIXiQFYIbxXw9SwqxWisCg46IPeE wTKhfEZT5EPSDPXrCbTZWvNwyqAmfZBhho7HsnJ7iuzusKQGRfMw/wpRr8SqqN33SnsqGGoWLtX aqjB2KBtPgqucVeFoyuhdbTCRYzSg728qm8qJbi01bS7q1/Zy2ZZ8jm79WzontjuwWD01pIo1lY pLqI8jW6v2jFzI8wT/A1VjJXI2ArftddQbLHE3MjLF1rV7x/IAZjCnRvz/mTv1ucsGiXml0mIc2 RH+BcrneeGDIC+U4QBXxGCysNH5ROyGtc7ED2ft7fL4jo3Aij/Ruld4MTveo7vHHjQ3AnTJ+tcm rk3LA7ncx/K9Yp8PEJmBLyfTHWxXEBeqi3Mfq5kUGCb21Fr2W321Vwuz1zJSQmFqdUAgGbCNxwB nfjn3I/Pgn3M6cXSwuHHRTkw9wrszZaQLuAiQNOXBTc= X-Received: by 2002:a17:903:4590:b0:2ef:eaa8:9b55 with SMTP id d9443c01a7336-2f1ba16f003mr67354135ad.53.1796558172191; Sun, 06 Dec 2026 03:56:12 -0800 (PST) Received: from ustb520lab-MS-7E07.. ([123.124.147.27]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1e21b9acbsm25894195ad.63.2026.12.06.03.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 03:56:11 -0800 (PST) From: Jiaming Zhang To: Andreas Gruenbacher , gfs2@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Jiaming Zhang , stable@vger.kernel.org Subject: [PATCH] gfs2: avoid infinite retry on inode hash collision in gfs2_create_inode Date: Sun, 6 Dec 2026 19:56:01 +0800 Message-ID: <20261206115601.482515-1-r772577952@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When creating a new file or directory, gfs2_create_inode() allocates a free disk block via alloc_dinode() and hashes the new VFS inode by its block address ip->i_no_addr, assuming any -EBUSY collision from insert_inode_locked4() is transient: if (error == -EBUSY) goto retry; if (error) goto fail_gunlock2; Commit 4ec3c19d058f ("gfs2: Handle -EBUSY result of insert_inode_locked4") added that retry loop for brief races against a concurrent lookup or failing create of a prior inode at that block. On a corrupt image whose resource group bitmap marks a live dinode block (such as statfs, rindex, quota, or root) as GFS2_BLKST_FREE, alloc_dinode() hands out that already-live block address. inode_insert5() finds the live inode in inode_hashtable, increments its reference count, and returns it; insert_inode_locked4() drops that extra reference without unhashing the live inode and returns -EBUSY. gfs2_create_inode() then spins at retry forever while holding inode_lock(dir) and the exclusive directory glock. Any concurrent lookup or permission check on that directory blocks forever in TASK_UNINTERRUPTIBLE waiting on the directory glock, hanging the directory and triggering a hung-task report in gfs2_permission(). Triggering this requires mounting a crafted GFS2 image (CAP_SYS_ADMIN) and creating a file in a directory. Use inode_insert5() directly after setting I_CREATING and defer writing io_gl->gl_no_formal_ino until insertion succeeds. Retry with a bounded 1-second deadline only when the colliding inode is NULL (I_CREATING) or has zero links; otherwise report corruption via gfs2_consist_inode(), skip deallocating the live block, and fail with -EIO. Fixes: 4ec3c19d058f ("gfs2: Handle -EBUSY result of insert_inode_locked4") Closes: https://lore.kernel.org/lkml/CANypQFZ_xTpeMAMNh_yQBsyEMvGYEQ-NeHv=tGghj3LHpR=muA@mail.gmail.com/ Cc: stable@vger.kernel.org Assisted-by: Antigravity:Gemini Signed-off-by: Jiaming Zhang --- fs/gfs2/inode.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 75fb1a0c9142..2541c04b9d1f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "gfs2.h" @@ -709,13 +710,14 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, const struct qstr *name = &dentry->d_name; struct posix_acl *default_acl, *acl; struct gfs2_holder d_gh, gh; - struct inode *inode = NULL; + struct inode *inode = NULL, *old; struct gfs2_inode *dip = GFS2_I(dir), *ip; struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); struct gfs2_glock *gl = NULL, *io_gl; int error, dealloc_error; u32 aflags = 0; unsigned blocks = 1; + unsigned long deadline = 0; struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, }; bool xattr_initialized = false; @@ -846,14 +848,33 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, if (error) goto fail_dealloc_inode; gfs2_cancel_delete_work(io_gl); - io_gl->gl_no_formal_ino = ip->i_no_formal_ino; + inode_state_set_raw(inode, I_CREATING); retry: - error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr); - if (error == -EBUSY) - goto retry; - if (error) - goto fail_gunlock2; + old = inode_insert5(inode, ip->i_no_addr, iget_test, NULL, + &ip->i_no_addr); + if (old != inode) { + bool retry = !old || !old->i_nlink; + + iput(old); + if (retry && !fatal_signal_pending(current)) { + if (!deadline) { + deadline = jiffies + HZ; + cond_resched(); + goto retry; + } + if (time_before(jiffies, deadline)) { + schedule_timeout_killable(1); + goto retry; + } + } + gfs2_consist_inode(dip); + error = -EIO; + gfs2_glock_put(io_gl); + ip->i_no_addr = 0; + goto fail_free_inode; + } + io_gl->gl_no_formal_ino = ip->i_no_formal_ino; error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT | GL_NOPID, &ip->i_iopen_gh); base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.43.0