Skip to content

Commit 46af9ae

Browse files
mjguzikbrauner
authored andcommitted
fs: make sure to fail try_to_unlazy() and try_to_unlazy() for LOOKUP_CACHED
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: 7c17909 ("fs: add predicts based on nd->depth") Reported-by: Chris Mason <[email protected]> Signed-off-by: Mateusz Guzik <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 570ad25 commit 46af9ae

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

fs/namei.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,9 @@ static inline bool legitimize_path(struct nameidata *nd,
830830
static bool legitimize_links(struct nameidata *nd)
831831
{
832832
int i;
833-
if (unlikely(nd->flags & LOOKUP_CACHED)) {
834-
drop_links(nd);
835-
nd->depth = 0;
836-
return false;
837-
}
833+
834+
VFS_BUG_ON(nd->flags & LOOKUP_CACHED);
835+
838836
for (i = 0; i < nd->depth; i++) {
839837
struct saved *last = nd->stack + i;
840838
if (unlikely(!legitimize_path(nd, &last->link, last->seq))) {
@@ -883,6 +881,11 @@ static bool try_to_unlazy(struct nameidata *nd)
883881

884882
BUG_ON(!(nd->flags & LOOKUP_RCU));
885883

884+
if (unlikely(nd->flags & LOOKUP_CACHED)) {
885+
drop_links(nd);
886+
nd->depth = 0;
887+
goto out1;
888+
}
886889
if (unlikely(nd->depth && !legitimize_links(nd)))
887890
goto out1;
888891
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)
918921
int res;
919922
BUG_ON(!(nd->flags & LOOKUP_RCU));
920923

924+
if (unlikely(nd->flags & LOOKUP_CACHED)) {
925+
drop_links(nd);
926+
nd->depth = 0;
927+
goto out2;
928+
}
921929
if (unlikely(nd->depth && !legitimize_links(nd)))
922930
goto out2;
923931
res = __legitimize_mnt(nd->path.mnt, nd->m_seq);

0 commit comments

Comments
 (0)