From nobody Sun Feb 8 10:55:02 2026 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 225AB30F7E3 for ; Fri, 12 Dec 2025 12:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765541507; cv=none; b=efe9yHMuhHp7Y6U1yHK22VmLTfqVCnYHM1hDQF0L6tgp+RPVme10soRlMcozRMWjmYYHLlkX02LWOVt1ueWk90cNTr51XR+lKMfOs2crE9i9oU8f8pPq27RbRMlVOpDqwkUJKm1hbfl3mHYLDIromu9cxaBMMSmBLew16YVzal4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765541507; c=relaxed/simple; bh=2b2+OvJ6KKMed/C5RLpRc/P6FDnmtGu5C563yfFTdko=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rBemAf6nmhoQT5NnpMc49KmN34GGQu22mb+HTNQoLtl8EoaKzMxeMFECYDEN3sIgyF7nvUAiUnacVoz6yrZPAr4LHN/0901bIC3yG0DpGSoLDFlo+/uvdjDTnbZY5nu/XN4cpRc2xkBUEDhypnonTTRvCSXUNYTlTm7yyduyzUA= 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=Ap8CaL7z; arc=none smtp.client-ip=209.85.208.43 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="Ap8CaL7z" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-640a0812658so2069115a12.0 for ; Fri, 12 Dec 2025 04:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765541504; x=1766146304; 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=koBQsfPOu5asWBoZ6zB8+3jGGJJhQLlpQdEqu3VmDp0=; b=Ap8CaL7zY6viDZPXYZbe7nq6Myw974WPLuvFU6+voGuM6ErlHIce3G8xzoOCoHxsDr vY+1NQHVOoclTmGJQk+Lll5clz9ctA+tUC9qRaaqEvvVew5XjZfiNHg9yW8Vhr6OjonW 34H5LRIThV7f31RmKWwEZ35B1dwL5imG/m/25+2gt9cvUjM+737YJcJFxrpK1A/Q5LdT 8PG3KxAm3VKRXPgvNuPTJhUJ31WlJzi9wtVK4JeVmS/Uw9evWC7vPdyYEHI+FI5ngDK3 gRBsCB+a5wQQvgdD8w7pLB+6KHg0bRdcq+CHxB8IAJ97bAkmV/huS0iCxHJlh2A+sYVh Yd5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765541504; x=1766146304; 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=koBQsfPOu5asWBoZ6zB8+3jGGJJhQLlpQdEqu3VmDp0=; b=fNV6zSmGt6stzLYlVEddgzjrMjWUiu3LKGEPhZcsK4ljVYD2Q2rCdaVBhAdQHHY/YX 3KV4dPaQ/NlJnXUdPWFf//RYV1KYFakWcvHqwwXHS3ssMegod/cNKOtoTEtvlQzAHIz2 ZLlOxXV6g48xNA6e3fmVYpHpGEvsU4h8gOkql9xNfDBjA0j3K4LnVtlzeSzMOEZlbKJ8 gwHOXLGl/zndL5YTcx6ymgIkwMtmjy49VfO+gMjUiuwKqhFpKLbs/KDrZoubevfP0jEY aU2zo99BvpdxmsGgq+s4F1MeNzxEpIuD1+CaTG4HJHPg7fk0MDHCzNF+ZO8/nmJVWZr5 xRgw== X-Forwarded-Encrypted: i=1; AJvYcCWAtof+n2DKzjUTTNUMZ2z77OvPK4tT0L3mgESy7UUnRo2fJCiw6QLPMiUr9QntSP5bpR1gZw+YvsjRE/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/GgcS5hx220ujLG/H7+xW9X5qkET4gi3uqtm/0Kn3VrquQmGx vxpTvRQgzxo4PzTMZUld+Z2A+rNqDNAfwnkW7+Rvfq4/9eZwFEDiVPsSrQ5SfA== X-Gm-Gg: AY/fxX7eibkg5zYBNcdXjcAciGAZYmlTijTCV22n6sRdtUsceK6Mrone1GnEaPuT20b X/Ny5m2AlvXHhh1FAu4T698D7J0+QPd+i+CSMC3hJrnitFurWFcNl1Sn2g/UH1AyWKLgaH6kSW8 ZE+zEBxCWVCPUSX193XMpaB6KMTzbRpljtYBLRI5fBU4IR7MI11wwUaBd3ZN5GoPMzjdiR1mJ9Z eZost0LRSJyqdFeEOLtUQoA2gWHAPJQcCRg0dl8XrTNuwlhzDyHLXXzS/d7L9YJx+wNNuCR3uTv RXZGpCia3G253qwVIOscFusHrIBo5wnKxSShwry/cei3C1LWFY4YL4MIwK4dZ2Td/iUHWPcoqlz 4HtnyUrI730m/E75d9DrDN2Z8Xhx67vZTQK2L2f736sVvC1hssGe69SaYcJQGMVha3nmcjbm5Rx qhAJKKhtP7ibCPFkHyh5FNDc5radNat7sj0jvCZwgj+ju66urmB2cTsMdiTaD0649bcGCVjp4F X-Google-Smtp-Source: AGHT+IFCpSEfd4LaFO6M+tPUkmFHhAEEOJ1sSHWWLhQek5ePCHqBviABc8XZoiiaey3UFyr0cUR24g== X-Received: by 2002:a05:6402:2709:b0:649:593b:baf4 with SMTP id 4fb4d7f45d1cf-6499b1cd664mr1618177a12.27.1765541504152; Fri, 12 Dec 2025 04:11:44 -0800 (PST) Received: from f.. (cst-prg-23-145.cust.vodafone.cz. [46.135.23.145]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-649820f785csm5154463a12.21.2025.12.12.04.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 04:11:43 -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] fs: make sure to fail try_to_unlazy() and try_to_unlazy() for LOOKUP_CACHED Date: Fri, 12 Dec 2025 13:11:18 +0100 Message-ID: <20251212121119.1577170-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. While here another tiny tidyp: ->depth =3D 0 can be moved into drop_links(). Fixes: 7c179096e77eca21 ("fs: add predicts based on nd->depth") Reported-by: Chris Mason Signed-off-by: Mateusz Guzik --- fs/namei.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index bf0f66f0e9b9..648567c77716 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) @@ -799,7 +800,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 +831,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 +882,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 +921,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