]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: make sure to fail try_to_unlazy() and try_to_unlazy() for LOOKUP_CACHED
authorMateusz Guzik <mjguzik@gmail.com>
Sat, 20 Dec 2025 05:40:22 +0000 (06:40 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 24 Dec 2025 12:31:56 +0000 (13:31 +0100)
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 <clm@meta.com>
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20251220054023.142134-1-mjguzik@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namei.c

index bf0f66f0e9b92c106fc92759d22f8158187c29d1..f7a8b5b000c23a4884de2d4e9c2b18108eef33f2 100644 (file)
@@ -830,11 +830,9 @@ static inline bool legitimize_path(struct nameidata *nd,
 static bool legitimize_links(struct nameidata *nd)
 {
        int i;
-       if (unlikely(nd->flags & LOOKUP_CACHED)) {
-               drop_links(nd);
-               nd->depth = 0;
-               return false;
-       }
+
+       VFS_BUG_ON(nd->flags & LOOKUP_CACHED);
+
        for (i = 0; i < nd->depth; i++) {
                struct saved *last = nd->stack + i;
                if (unlikely(!legitimize_path(nd, &last->link, last->seq))) {
@@ -883,6 +881,11 @@ static bool try_to_unlazy(struct nameidata *nd)
 
        BUG_ON(!(nd->flags & LOOKUP_RCU));
 
+       if (unlikely(nd->flags & LOOKUP_CACHED)) {
+               drop_links(nd);
+               nd->depth = 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, struct dentry *dentry)
        int res;
        BUG_ON(!(nd->flags & LOOKUP_RCU));
 
+       if (unlikely(nd->flags & LOOKUP_CACHED)) {
+               drop_links(nd);
+               nd->depth = 0;
+               goto out2;
+       }
        if (unlikely(nd->depth && !legitimize_links(nd)))
                goto out2;
        res = __legitimize_mnt(nd->path.mnt, nd->m_seq);