From nobody Thu Apr 2 15:41:21 2026 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2F3334EEEE for ; Sat, 28 Mar 2026 15:32:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711935; cv=none; b=hl7h3vi9PpKC/ksOMEZLeUMPKILJ88CGqnnIoFlVSB0wTLdZlxep0h9q7C5doLcZn0cG51AO7QsDMcw6TBemOCKW9gAUUkrYFpfVcfcSVUcsWbhAULyqvfvOC0JOjVjueUUjaI5KeaZ2vnhJGVWnHJV8GLe5kizn3jjPtrf71EQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711935; c=relaxed/simple; bh=jKFU9ClukmgrQPWCuZbiDz6loGcaVsfq+0devSW3yqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RNiJA4pHTVKJ2BUifPiFHjzeeYzUghzpWqr7M+QQ0ooch80unLbVNezCOyGVK18D9k56g//gU2hteDih66BcmH0O5fgpoidiJ6+5dYL4CPJcMlRARfcEdZmReOkckDVK7F/C7OPWum4xiS3g+Z+EHN+jcyiarbRos0wgBB/RXb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dxgofVFi; arc=none smtp.client-ip=209.85.221.51 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.b="dxgofVFi" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-43b41b545d9so3298633f8f.2 for ; Sat, 28 Mar 2026 08:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774711928; x=1775316728; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VSDysc2SqFR5k0dxgouFFuDk3xltDf+gaI9kO7u+6DU=; b=dxgofVFikwbbfUGmAV2oys2keYy5+lYHw64IgnkA0JppqOiS73WB9MYU36St/kR9N8 EjLUljLEry11sj1yQJ6K/bxyeVpuWesbNMsh4oGyZlwFla9C2GQ0cVtDZQI3EOO4xblu JMRgCA7tz6EGEgXtOlWJ52PByzofecrhQMCOvr33wv+LB5zfIQJLRsFAQN1L0AlWTDj+ SQ8SbJaDYMSTC+ZlBiv0tlQJIQqTInWk0oH6epFOj2NEqmyRk4TcY6oj2w6aHXZK/68N TgiV+bmwNUPXhPNK2mkVj+G+6FtgoJbiAYzMkkSDTGZQ5JCPpaT8JI7KijF4QVcbPmR9 Hagg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774711928; x=1775316728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VSDysc2SqFR5k0dxgouFFuDk3xltDf+gaI9kO7u+6DU=; b=jb9CvA+R5diPUNYQVyrCoZCvHSK2HlcAfHXJ/rH1A5Cj84nZk1fo0rccS3tAwYJGP0 2L2Bk7w45qh2jzMiKPlPUa6F5Bd8XfoIghBrOKTHocHguRJ1RVmwljAZrEkaNws+cSV6 iAQ3D6/IXF3olv8gCiAwAGH+k2NhhtMFnpJiLXgr4KePsNc7uQqgxDrFLnQVschzNwHn hWs9bsNkKo7ZYVnY7Q/TEoCjdtVU33gMPtwSXqo6wZTdf/1/8vWNEkSUzfqPWZLRG+Qc qwb297jB0t7lW891MN4lEijvYfvPo12ymkd6PjyP+27/R7Y7ZyfdMu6SYR97vJwrO2Lj Q7+Q== X-Forwarded-Encrypted: i=1; AJvYcCXQ8zVKW+Tc+WS04AaaFZJM0+QmfVGHot62lAvj2UIIhygKziRBxROlM6gX4DaX9p9Soj2KNUZCawUykWI=@vger.kernel.org X-Gm-Message-State: AOJu0YyWkK43q6Oa6ASBbZgz9Rfvcm/QrTXnGDqevNO5eV/c8Bq98g+m Ag0CzkAeLXFaN0DHkqGzad+5vQRdstHnOhlzbZVre1oGBTnXuMRNj4UT X-Gm-Gg: ATEYQzw5U9p+duVrpv3vJFHlVOqEZqcQ0BeNUfhXM3S/HcAmX9zljFMOXtGLtXhgHUR i6hyXpc55EupFepLtSikFE/NPiNQlqe5MojmCVVW3OzqnkLXEZDsguEdn6Q4oZXv6Cs7GIdChPm b/O23Yj8pkU/TgOthgosx5woQUdaaT+hWzZdRgZm34o/ihjyDf2B3XSORh8LIeIJBz4Isak+pVJ GOgdtC/MTwfZM8vSG/cUCBfg9wKtQKo4TdO4dIPOqjKC9mnnd+L+1eUAduuP1mGhvUNBLaEyGeS 6Sg7lDK4rg5CDliG0o7dLA5NTpvb06QFY1lQnWUuY9x8uJnOGbPKJ8JA/VI4ZQYgwXuBlucUeGi 2ZkWfaGV16O5rAA8nDk3R3MkbIFzv0tEqjGpOlAQb43wtfSJteFqjnGJNQrML9NCDy9qT5fB+O0 ua1KBlJSYZnDpOb5/F5nB9PITdTpjR/qLV+xV49SFIr5yvGNBeaVVio88W9EmG93OAbxEIXc45X g== X-Received: by 2002:a05:6000:40dd:b0:439:b8b2:fad0 with SMTP id ffacd0b85a97d-43b9e9da56amr10027000f8f.5.1774711928055; Sat, 28 Mar 2026 08:32:08 -0700 (PDT) Received: from f.. (cst-prg-89-171.cust.vodafone.cz. [46.135.89.171]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf245f8a3sm6725310f8f.24.2026.03.28.08.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 08:32:07 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Mateusz Guzik Subject: [PATCH 4/5] fs: handle hypothetical filesystems hich use I_DONTCACHE and drop the lock in ->drop_inode Date: Sat, 28 Mar 2026 16:31:45 +0100 Message-ID: <20260328153146.3368470-6-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260328153146.3368470-1-mjguzik@gmail.com> References: <20260328153146.3368470-1-mjguzik@gmail.com> 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" f2fs and ntfs play games where they transitiong the refcount 0->1 and relea= se the inode spinlock, allowing other threads to grab a ref of their own. They also return 0 in that case, making this problem harmless. Should they start using the I_DONTCACHE machinery down the road while retaining the above, iput_final() will get a race where it can proceed to teardown an inode with references. Future-proof it. Developing better ->drop_inode and sanitizing all users is left as en exercise for the reader. Signed-off-by: Mateusz Guzik --- fs/inode.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1f5a383ccf27..fc6045e6d43f 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1933,20 +1933,29 @@ static void iput_final(struct inode *inode) else drop =3D inode_generic_drop(inode); =20 - if (!drop && - !(inode_state_read(inode) & I_DONTCACHE) && - (sb->s_flags & SB_ACTIVE)) { + /* + * XXXCRAP: there are ->drop_inode hooks playing nasty games releasing the + * spinlock and temporarily grabbing refs. This opens a possibility someo= ne + * else will sneak in and grab a ref while it happens. + * + * If such a hook returns 0 (=3D=3D don't drop) this happens to be harmle= ss as long + * as the inode is not marked with I_DONTCACHE. Otherwise we are proceedi= ng with + * teardown despite references being present. + * + * Damage-control the problem by including the count in the decision. How= ever, + * assert no refs showed up if the hook decided to drop the inode. + */ + if (drop) + VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); + + if (icount_read(inode) > 0 || + (!drop && !(inode_state_read(inode) & I_DONTCACHE) && + (sb->s_flags & SB_ACTIVE))) { __inode_lru_list_add(inode, true); spin_unlock(&inode->i_lock); return; } =20 - /* - * Re-check ->i_count in case the ->drop_inode() hooks played games. - * Note we only execute this if the verdict was to drop the inode. - */ - VFS_BUG_ON_INODE(icount_read(inode) !=3D 0, inode); - if (drop) { inode_state_set(inode, I_FREEING); } else { --=20 2.48.1