Bug 14811

Summary: Incorrect path matching in pseudo cause package failure in yocto
Product: [Yocto Project Subprojects] Pseudo Reporter: Federico Giovanardi <fede.linux>
Component: pseudoAssignee: Richard Purdie <richard.purdie>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Medium+ CC: fede.linux, richard.purdie, yp.pseudo.watcher, yp.watcher
Version: unspecified   
Target Milestone: 6.2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Attachments:
Description Flags
Possible patch none

Description Federico Giovanardi 2022-05-23 07:57:21 UTC
Created attachment 4868 [details]
Possible patch

Preconditions/Environment
-------------------------
Building a recipe which create files in a path that's a string prefix of one
of the build / packaging  directories.

Here is the offending recipe:
------
SUMMARY = "Powerboard support module"
LICENSE = "CLOSED"

inherit module

SRC_URI = "file://linux_module_4.1.0.tar.gz "
S = "${WORKDIR}/pkg"
----

where `linux_module_4.1.0.tar.gz` is a tarball
with the following structure:

pkg/Makefile
pkg/source1.c
pkg/source2.c
pkg/..

Triggering Action/Cause
-----------------------
bitbake kernel-module-powerboard

Expectation
-----------
The recipe should build correctly

Actual Result
-------------
We alternate between one of the following results:

-------------------
     0565:
File: '/home/fede/yocto/sources/poky/meta/lib/oe/sstatesig.py', lineno: 555, function: process
     0551:                    add_perm(stat.S_IXOTH, 'x')
     0552:
     0553:                if include_owners:
     0554:                    try:
 *** 0555:                        update_hash(" %10s" % pwd.getpwuid(s.st_uid).pw_name)
     0556:                        update_hash(" %10s" % grp.getgrgid(s.st_gid).gr_name)
     0557:                    except KeyError as e:
     0558:                        bb.warn("KeyError in %s" % path)
     0559:                        msg = ("KeyError: %s\nPath %s is owned by uid %d, gid %d, which doesn't match "
Exception: Exception: KeyError: 'getpwuid(): uid not found: 1000'
Path ./pkgdata/kernel-module-powerboard is owned by uid 1000, gid 1000, which doesn't match any user/group on target. This may be due to host contamination.
-------------------
or 
-------------------
File: '/usr/lib/python3.6/subprocess.py', lineno: 311, function: check_call
     0307:    if retcode:
     0308:        cmd = kwargs.get("args")
     0309:        if cmd is None:
     0310:            cmd = popenargs[0]
 *** 0311:        raise CalledProcessError(retcode, cmd)
     0312:    return 0
     0313:
     0314:
     0315:def check_output(*popenargs, timeout=None, **kwargs):
Exception: subprocess.CalledProcessError: Command '['rm', '-rf', '/home/fede/yocto/build-delta80t/tmp/work/delta80_vt-poky-linux-gnueabi/kernel-module-powerboard/1.0-r0/sstate-build-package/']' died with <Signals.SIGABRT: 6>.
-------------------

Reproducibility
---------------
always


Explanation
---------------
I've found that the code that process the ignore list in pseudo is incorrect. In this example
yocto run the packaging phase with PSEUDO_PATH_IGNORE=`pwd`/pkg plus other paths, `pkg` is inserted because it's the value of "${S}", but this way pseudo also ignore pkgdata causing the packaging process to run out of fakeroot and the errors above.

the culprit is the following function in pseudo:

int pseudo_client_ignore_path_chroot(const char *path, int ignore_chroot) {
 26         char *next = strchr(p, ',');
 27         if (next)
 28             *next++ = '\0';
 29 -       if (*p && !strncmp(path, p, strlen(p))) {
 30 -           pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "ignoring path: '%s'\n", path);
 31 -           ret = 1;
 32 -           break;

the strcmp() matches both /pkg and /pkgdata

I've attacched a possible fix as a patch.
Comment 1 Richard Purdie 2022-09-09 15:47:42 UTC
The trouble is that code was specifically designed to allow partial prefix matching and we do rely on that behaviour to simplify other areas of code. Whilst this patch will fix a specific corner case, I suspect it will break other usage.
Comment 2 Federico Giovanardi 2022-09-26 08:38:34 UTC
If you have some concrete example it might be possible to tune the check to allow the required usecase without allowing for a wildcard match, or fix the other parts adding a * to explicitly allow a wider matching. The issue it's not blocking since I've avoided the problem simply renaming the folder inside the tar.gz but it has been pretty tricky and time consuming to find; maybe we could just detect the case during unpacking and generate a build error.
Comment 3 Richard Purdie 2023-03-07 13:03:36 UTC
Id support spotting problematic patterns and erroring if found.