diff mbox series

[pseudo,3/5] renameat2/renameat: only ignore when both old and new path are not in PSEUDO_INCLUDE_PATHS

Message ID 1778624443-20857-4-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series Fix rename/renameat w/ hardlinks | expand

Commit Message

Mark Hatle May 12, 2026, 10:20 p.m. UTC
From: Changqing Li <changqing.li@windriver.com>

The patch is for fixing failure in the following scenario:
[snip of recipe]
    do_install() {
        mv ${B}/hello.txt ${D}/hello.txt
        ln ${D}/hello.txt ${D}/hello2.txt
    }
    FILES:${PN} += "/hello2.txt /hello.txt"
[snip of recipe]

do_package will failed with pseudo abort error.

Root Cause:
For command mv, when oldpath is not in PSEUDO_INCLUDE_PATHS, the renameat2
will skip the wrapper and call real renameat2, and no entry is inserted
in files.db. Then command ln, insert an entry for hello2.txt in
files.db, which with the same inode with hello.txt. During do_package
stage, when stat for hello.txt, it will find a path mismatch failure
like:
path mismatch [2 links]: ino 190860603 db 'hello2.txt' req 'hello.txt'

Fixed by:
For renameat2/renameat, change to only ignore wraper call when both old
and new path are not in PSEUDO_INCLUDE_PATHS. In guts/renameat.c, when
oldpath is not in PSEUDO_INCLUDE_PATHS and has no existing db entry,
OP_LINK on oldpath is silently dropped by pseudo_client_op, making the
subsequent OP_RENAME a no-op in files.db, so change renameat to create
the entry directly at newpath via OP_LINK when oldpath is ignored,
skipping the pointless LINK+RENAME sequence for oldpath

Helped-by: Paul Barker <paul@pbarker.dev>
Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
 makewrappers               |  4 +++-
 ports/unix/guts/renameat.c | 32 +++++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/makewrappers b/makewrappers
index df405fc..83f5ca6 100755
--- a/makewrappers
+++ b/makewrappers
@@ -430,7 +430,9 @@  class Function:
             return "0"
 
         mainpath = None
-        if "oldpath" in self.paths_to_munge:
+        if "oldpath" in self.paths_to_munge and "newpath" in self.paths_to_munge:
+            return "(pseudo_client_ignore_path(oldpath) && pseudo_client_ignore_path(newpath))"
+        elif "oldpath" in self.paths_to_munge:
             mainpath = "oldpath"
         elif "newpath" in self.paths_to_munge:
             mainpath = "newpath"
diff --git a/ports/unix/guts/renameat.c b/ports/unix/guts/renameat.c
index 5ac63f9..69130c6 100644
--- a/ports/unix/guts/renameat.c
+++ b/ports/unix/guts/renameat.c
@@ -113,14 +113,32 @@ 
 				oldbuf.st_ino = newbuf.st_ino;
 			}
 		}
-		pseudo_debug(PDBGF_OP, "creating new '%s' [%llu] to rename\n",
-			oldpath, (unsigned long long) oldbuf.st_ino);
-		pseudo_client_op(OP_LINK, 0, -1, olddirfd, oldpath, &oldbuf);
+		if (pseudo_client_ignore_path(oldpath)) {
+			/* oldpath is ignored (not in INCLUDE_PATHS), so
+			 * OP_LINK on it would be silently dropped and the
+			 * subsequent OP_RENAME would be a no-op. Instead,
+			 * create the entry directly at newpath.
+			 * OP_LINK does not override uid/gid with pseudo_fuid/
+			 * pseudo_fgid (unlike OP_CREAT), so set them explicitly
+			 * to avoid recording the host user's real ids.
+			 */
+			oldbuf.st_uid = pseudo_fuid;
+			oldbuf.st_gid = pseudo_fgid;
+			pseudo_debug(PDBGF_OP, "creating new '%s' [%llu] directly at newpath (oldpath ignored)\n",
+				newpath, (unsigned long long) oldbuf.st_ino);
+			pseudo_client_op(OP_LINK, 0, -1, newdirfd, newpath, &oldbuf);
+		} else {
+			pseudo_debug(PDBGF_OP, "creating new '%s' [%llu] to rename\n",
+				oldpath, (unsigned long long) oldbuf.st_ino);
+			pseudo_client_op(OP_LINK, 0, -1, olddirfd, oldpath, &oldbuf);
+			pseudo_client_op(OP_RENAME, 0, olddirfd, newdirfd, newpath, &oldbuf, oldpath);
+		}
+	} else {
+		/* special case: use 'fd' for olddirfd, because
+		 * we know it has no other meaning for RENAME
+		 */
+		pseudo_client_op(OP_RENAME, 0, olddirfd, newdirfd, newpath, &oldbuf, oldpath);
 	}
-	/* special case: use 'fd' for olddirfd, because
-	 * we know it has no other meaning for RENAME
-	 */
-	pseudo_client_op(OP_RENAME, 0, olddirfd, newdirfd, newpath, &oldbuf, oldpath);
 
 	errno = save_errno;
 /*	return rc;