From nobody Sat Feb 7 18:15:17 2026 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 68F30267B05 for ; Sat, 20 Dec 2025 05:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766209234; cv=none; b=lK9a8g/vznKMdBnih3Cvs93CnSNCyzMe9+FMSlRdoROCTTszsG/YVoHpUnq98AWuwWEFNBpXE5qpl3qttBUxl0kxhHjL15ZZ0w2hYNg3F9YL76C9D2kU8zjkI7iXf7+YbwdCDg0np2mosZacw8CxZF4zyCL4mArifX2gycf3/Cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766209234; c=relaxed/simple; bh=p42BJNupHuIS+VpYjjVjkRpU78a/l7ZJSRdNnBbDs8I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KHKuCjOV0ccNyjhOzQ0Yqj0CmzaqIdenVWy2eChfMcl/cVvQ12AnEUPEAqFdCQ0LTAaNZT9rrht/Q0k0Py1gN8wR4covQAFb/g77+LilCwRoqqh71eGTyjbaDzWJ9SQp5b4naab4toAYQIKRqCiS2bPpu6a4uGCyTpx6JZyYxAQ= 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=G2/DcTnc; arc=none smtp.client-ip=209.85.218.45 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="G2/DcTnc" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b736d883ac4so430284966b.2 for ; Fri, 19 Dec 2025 21:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766209231; x=1766814031; 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; bh=C8prGX8mCG0hlpIUxCwCqtaCOrf4LfFVDrIHbCsEcuY=; b=G2/DcTncR/tdE9SGjPTShYB4J939dQydgy6mvg7nFKjSFzybbppdxY+Sr7WeEyY2wV sMXNwjMdXM4nBG+TS9M6Jo2y/KuNXYBN6mTv0O/DEp5qJkcD2yGPTVS+BquRUVe85NkF DJHHjtRP/0e1oLena1krlBhfZti2+rZHGxKluR98QhIzcRvSgTH/ayWiZW4AjHe6nWQ4 e0Iib/DmqhxGjGgVeulq+9QjIj5N/3HaI29tnPcQv2ueTi9sd4bi0vRdRjMHylFjkMWN rCIyJmy13u/6C176eYo1ciwJw+aQy3Hf1dq/KzAKMOAYJ1vptiGuSml0Au3rPaTEwfow OQcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766209231; x=1766814031; 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; bh=C8prGX8mCG0hlpIUxCwCqtaCOrf4LfFVDrIHbCsEcuY=; b=NZEHA3gXIXe6EhfbJ9wTWHR0b+jEvhoQNBACsbVAO7QqdbuPcbSpKV1ptGdujGK+zA 7DjWJhWygHnofMB1W5HMGBLHkviId8mw75NkvQcvKbsxx1Sj4Ib7W20wvqpChc+2okV7 bi/g8axOzybNPIYsvgUkh1+YtXVuLh6soC/0U01tcv2c9jia9tw0XJy+xqM1+U6qWXia Z+0XWHfK9nuLiSq8RE9Gcu0ialdWwbKrz97v6Iz5w0SUXA0U4vQ44FacRllT93cW/eKC rJyrNr3IyQXdaydxVDblnCfcAfH65XbrxuIOuDpsz8Rd4/0p4vhPMR3JAi16Ssk42yo2 lJAQ== X-Forwarded-Encrypted: i=1; AJvYcCUOaTSrRht6EHZin1PYkNwO8pLBMqm4z2i2HnXvciLHELpGQWaUUMuw0aA9g93o+2Ex0T5KueJSVhfcuwc=@vger.kernel.org X-Gm-Message-State: AOJu0YztAdeq/06+2BYVlin1E4h/SD92YEB39Va5yHa/9MxjDVvwMH7g 32qH8AhXXYHX1FJB1X1PRnMDVlJVMAi1tiieUXtkRKcQdCceXEutS1SP X-Gm-Gg: AY/fxX5kiLgDR0RKwjUFbvjvZT/uvDb7dtzWQTgLp3q1PwyH/vpCsIiFqkbKqKAgmLK BBNGp3xwxRb3TXsk3/JSar2vQSuq/FsNlnJ8iIWab7UWL+GHF3XEFY7J5Fuc0JcnaljgpprErMK hZXbKwbo5OtqUztKJQekJnc/AGCV9l8r85HyPSclx046KQ/bP1MZ0wBfA5Or5ALxsQPKlzEAfky GigPy+bpOYL0zM8Jn4SZGXK64bBUxqXpZ763oQbp6Y07QM7PFjrjay29B+Ezm3pg2ZsZAxjkzpj VOMlBkA7mAbGrIj7ydkfkHI3cDXycdtszyUvqEe0Baz9n5uORajM31HWw+kwlQvr9+o4p+UlYku eh9A83gZOKPOztbcTwWIiSiZS5GX/TzKAqKGexmRJ7iOdEb2JfAlmC7X7rK6zGMnEXVwwauHtug XvFEDp6NbsqLVL1bXo+kLc09WIg88HXw4LAsRPp5dhXn1bJQ4qauCvSzY58Luepqd5u4oXWQ== X-Google-Smtp-Source: AGHT+IEq/HNbwlXVDbvScjeQpoQYsBu8b0ZfA8ZLBC5usoKuom4CFt9Fhy6b6qXz23H6iI2r4T8l8A== X-Received: by 2002:a17:907:8690:b0:b76:63b8:7394 with SMTP id a640c23a62f3a-b80371d9dcbmr515084466b.51.1766209230538; Fri, 19 Dec 2025 21:40:30 -0800 (PST) Received: from f.. (cst-prg-91-72.cust.vodafone.cz. [46.135.91.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037f3e271sm412429566b.60.2025.12.19.21.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 21:40:29 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org, viro@zeniv.linux.org.uk Cc: jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, clm@meta.com, Mateusz Guzik Subject: [PATCH v3] fs: make sure to fail try_to_unlazy() and try_to_unlazy() for LOOKUP_CACHED Date: Sat, 20 Dec 2025 06:40:22 +0100 Message-ID: <20251220054023.142134-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 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" Otherwise the slowpath can be taken by the caller, defeating the flag. This regressed after calls to legitimize_links() started being conditionally elided and stems from the routine always failing after seeing the flag, regardless if there were any links. In order to address both the bug and the weird semantics make it illegal to call legitimize_links() with LOOKUP_CACHED and handle the problem at the two callsites. Fixes: 7c179096e77eca21 ("fs: add predicts based on nd->depth") Reported-by: Chris Mason Signed-off-by: Mateusz Guzik --- v3: - keep nd->depth =3D 0 out of drop_links to further simplify the patch The thread for v2 got derailed with a discussion unrelated to the fix itself. Whatever future cleanups or lack thereof can be discussed after the regression is fixed so I'm keep anything of the sort out of this patch. The easiest way out I can think of would merely remove the ->depth checks before calling legitimize_mnt, but it would be a bummer to reintroduce the func call. The second easiest way out literally copy-pastes the current body into the 2 callers, which I implemented in this patch. fs/namei.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index bf0f66f0e9b9..f7a8b5b000c2 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -830,11 +830,9 @@ static inline bool legitimize_path(struct nameidata *n= d, static bool legitimize_links(struct nameidata *nd) { int i; - if (unlikely(nd->flags & LOOKUP_CACHED)) { - drop_links(nd); - nd->depth =3D 0; - return false; - } + + VFS_BUG_ON(nd->flags & LOOKUP_CACHED); + for (i =3D 0; i < nd->depth; i++) { struct saved *last =3D nd->stack + i; if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { @@ -883,6 +881,11 @@ static bool try_to_unlazy(struct nameidata *nd) =20 BUG_ON(!(nd->flags & LOOKUP_RCU)); =20 + if (unlikely(nd->flags & LOOKUP_CACHED)) { + drop_links(nd); + nd->depth =3D 0; + goto out1; + } if (unlikely(nd->depth && !legitimize_links(nd))) goto out1; if (unlikely(!legitimize_path(nd, &nd->path, nd->seq))) @@ -918,6 +921,11 @@ static bool try_to_unlazy_next(struct nameidata *nd, s= truct dentry *dentry) int res; BUG_ON(!(nd->flags & LOOKUP_RCU)); =20 + if (unlikely(nd->flags & LOOKUP_CACHED)) { + drop_links(nd); + nd->depth =3D 0; + goto out2; + } if (unlikely(nd->depth && !legitimize_links(nd))) goto out2; res =3D __legitimize_mnt(nd->path.mnt, nd->m_seq); --=20 2.48.1