From nobody Sun Feb 8 02:21:19 2026 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.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 610A433D6CC for ; Wed, 17 Dec 2025 08:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765961236; cv=none; b=K2889YkWYWOnlfEAYI+a1K+z0QNt5rit/S6az1TdQ50a0YKO2uBc80M33U5RS+0o0Sbj/t6lgCdTU5CTdPCJ16IbkhSWepDEA8r5R+T6cF2dcx+2uAkeRl5glJCz/oUtv/JYBuqj02J7wKujaNX2qZjsjgMt6qjBu/3h6U/U7SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765961236; c=relaxed/simple; bh=rHdM58pAnaDSEgykUXG1fdDukK9XmZ8ee1wCtCQnfhE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fcNeebfjew5/eAYZcnjkye0I3t99UFgDsQuMqdimVFEO7ob0la8m7gmL9H0EguPvTRbQ/XrMKrNX5KSFsn04pmU/BWrfH1WRSb1wmNJHgzFfAL8ZhAmwsCeLiYXYPm9O3KaxL1Jo1Ual8hfdZUTsOKtGUV2oZdPJwS9+LMj9WMM= 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=abvMj5nQ; arc=none smtp.client-ip=209.85.208.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="abvMj5nQ" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-64162c04f90so10394209a12.0 for ; Wed, 17 Dec 2025 00:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765961233; x=1766566033; 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=aszomBLBoQUByCbC/oqX0FySIrenkQuSb6pWTR+FVTw=; b=abvMj5nQ9cCMIOdMJLQz69RPePLGhsjpjlJGkIODmZdtfThrj9ViwS7X/K4pLY7eMY hFFTuVlrWlYwMgmAPHxdkHPMITfOoUfzJpncyQQxncOePkLFS0aHAPbwdEQQ+SSpdcRa lYqrq7ze1ld6da23tfU6dObPd4J8kJKG04shU3FiqJB5avFp+35Gurzs21O7cejZj7EK AqsvU6ZY0CsPbNCyfCqCsCTx6leNfYMOh37M3w4nqvKtt7i9h2aTofXi32jkr93++Ura 8pahIN9yXQkWeA5Sks6YIS5XMsefYKkHX0e7MGIYDQD5CJ5ILsEZUstktg1e7QE8Cedk RMCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765961233; x=1766566033; 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=aszomBLBoQUByCbC/oqX0FySIrenkQuSb6pWTR+FVTw=; b=EkD6/rcsawECSdQFuQ8IffGy2+bawAyMHfFumm/0dTqSieXhGW8XGqiViVF3I96BP3 E32WIodUokKAVV9b793mu39pQVpWndTbBCYaxP6F92d0Oo5d1Ncf2WTwfMq30+pB1svh bLvVseFph5f2Kkpl5o5a+RSoOoDuf2Nz2xTi/YKYC9owy3eIAeiBTNSNG5Wl7FoMrfGO 8NFgRp11slPlWnxOIhl8a4vIVTYsZHC1KK8vBURY3WlZaK42eXEBKINMOhKqkgWEhihE tMmPnCHqT7wtTN68jqrQSnAdXkuWBxy9yI7o/RbcYeBHTgDd4ZpKUc/CAoJS/P3UKVW1 NKsQ== X-Forwarded-Encrypted: i=1; AJvYcCWZmheCyyPQxSQQAyQ6X3tw6FUORpJpq5KVb3BKMiD9oS4Di5sYGNmOie5LtQHnOlOZa8nj8gx2320btFg=@vger.kernel.org X-Gm-Message-State: AOJu0YyBxK5LinJE4azt35mw29yL519eLVc7p/pO+KTUb+diE65QsoZB Fk1qeLU1Fi7ZKPv7Ti7ox7oJ7Nx8dD9/zrk84Tb1d95wfnSapyiID3ui X-Gm-Gg: AY/fxX4Jpcf8sHPA2gaYXXjdjnUO48WIiAlDZVD+8hhiq8l4Z/TA2CW4W3Ldv5KNG1g GPNkigdA2c8jCINIRzFUZCFic2esJLlXuU/4vQtevWxjaTNc1W5X6z8vRDh+AoJVgVd74GMpyDA ja498GOvOpH1/JEaMF9TRPGQNRPvsHqn93fyYhG1rmYyfPq3yuy8GoM1pGQAK6JjbT8n0zo0LRa QLFznIxPdJe35LJ2ak2PVSNcVBHSnZBrkecfD2vGu2G79NlyU24v75BmlUQA5XE7VVpjjlbDFQN bxc3Q14xwLn1dbuQMEX7cLEdVvnrGFKalGpQKRlHytEu2yVi2dIqIBPMQcniEHySvuhKZu2xhyX 6MDHglxd95Qfjnta+M7bO+klaXFGk7M1qcXq69Yx8AD1P8h6uUG4qtMNVUdtfi5S9D3kJ5Nfs6o geI0DzJZHncp3EEfmJzZSuFyAbYkBgF7IpepDSW1XFZFkPqQMrC4Fk4VwRGoPRdg== X-Google-Smtp-Source: AGHT+IHfAAQ6tKmCvJCWlqYQhYa+AoAdrLEXviSWzBqJ7K61hKB+2craAY1s/YGhWoAjGDY1F/bE4g== X-Received: by 2002:a17:906:7954:b0:b73:4fbb:37a2 with SMTP id a640c23a62f3a-b7d238ee6b1mr1721436666b.5.1765961232414; Wed, 17 Dec 2025 00:47:12 -0800 (PST) Received: from f.. (cst-prg-23-145.cust.vodafone.cz. [46.135.23.145]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b3f584ba0sm1897536a12.33.2025.12.17.00.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 00:47:11 -0800 (PST) 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, clm@meta.com, Mateusz Guzik Subject: [PATCH v2] fs: make sure to fail try_to_unlazy() and try_to_unlazy() for LOOKUP_CACHED Date: Wed, 17 Dec 2025 09:47:04 +0100 Message-ID: <20251217084704.2323682-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. Pull up ->depth =3D 0 to drop_links() to avoid repeating it in the callers. One remaining weirdness is terminate_walk() walking the symlink stack after drop_links(). Fixes: 7c179096e77eca21 ("fs: add predicts based on nd->depth") Reported-by: Chris Mason Signed-off-by: Mateusz Guzik --- v2: - handle terminate_walk looking at nd->depth after drop_links fs/namei.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index bf0f66f0e9b9..69d0aa9ad2a8 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -774,6 +774,7 @@ static void drop_links(struct nameidata *nd) do_delayed_call(&last->done); clear_delayed_call(&last->done); } + nd->depth =3D 0; } =20 static void leave_rcu(struct nameidata *nd) @@ -785,12 +786,13 @@ static void leave_rcu(struct nameidata *nd) =20 static void terminate_walk(struct nameidata *nd) { - if (unlikely(nd->depth)) + int depth =3D nd->depth; + if (unlikely(depth)) drop_links(nd); if (!(nd->flags & LOOKUP_RCU)) { int i; path_put(&nd->path); - for (i =3D 0; i < nd->depth; i++) + for (i =3D 0; i < depth; i++) path_put(&nd->stack[i].link); if (nd->state & ND_ROOT_GRABBED) { path_put(&nd->root); @@ -799,7 +801,7 @@ static void terminate_walk(struct nameidata *nd) } else { leave_rcu(nd); } - nd->depth =3D 0; + VFS_BUG_ON(nd->depth); nd->path.mnt =3D NULL; nd->path.dentry =3D NULL; } @@ -830,11 +832,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 +883,10 @@ 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); + goto out1; + } if (unlikely(nd->depth && !legitimize_links(nd))) goto out1; if (unlikely(!legitimize_path(nd, &nd->path, nd->seq))) @@ -918,6 +922,10 @@ 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); + 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