• Bug#1104405: mmdebstrap: readdir() attempted on invalid dirhandle

    From J.P.Malhado@21:1/5 to All on Tue Apr 29 17:40:02 2025
    Package: mmdebstrap
    Version: 1.5.6-4~bpo12+1
    Severity: normal
    Tags: upstream
    X-Debbugs-Cc: phlogiston@sapo.pt

    Dear Maintainer,

    When running with the following command prompt

    mmdebstrap --mode=chrootless --format=directory --arch=hurd-i386 \
    --include=sysvinit-core,sysv-rc,debian-ports-archive-keyring,gnumach-image-1-486
    --customize-hook="passwd --root=\"\$1\" --delete root" \
    --variant=apt unstable /hurd \
    "deb http://deb.debian.org/debian-ports/ unstale main" \
    "deb http://deb.debian.org/debian-ports/ unreleased main"

    where /hurd is the mountpoint for a partition with a filesystem
    generated with "mk2efs -o hurd" with write permissions to non-root
    users, and the command is being run by a normal user account,
    I'm getting the following output:

    I: skipping emulation check in chrootless mode
    I: finding correct signed-by value...
    done
    readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6889. readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6890. readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6893. closedir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6897.
    I: running apt-get update...
    downloading: 0.00 [>

    And seems to get stuck.

    Thank you for considering this issue,
    Joao


    -- System Information:
    Debian Release: 12.10
    APT prefers stable-updates
    APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
    Architecture: i386 (i686)

    Kernel: Linux 6.1.0-34-686-pae (SMP w/1 CPU thread; PREEMPT)
    Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
    Shell: /bin/sh linked to /usr/bin/dash
    Init: runit (via /run/runit.stopit)

    Versions of packages mmdebstrap depends on:
    ii apt 2.6.1
    ii perl 5.36.0-7+deb12u2
    ii python3 3.11.2-1+b1

    Versions of packages mmdebstrap recommends:
    ii arch-test 0.20-1
    ii gpg 2.2.40-1.1
    ii libdistro-info-perl 1.5+deb12u1
    ii libdpkg-perl 1.21.22
    ii mount 2.38.1-5+deb12u3
    ii uidmap 1:4.13+dfsg1-1+b1

    Versions of packages mmdebstrap suggests:
    pn apt-transport-tor <none>
    ii apt-utils 2.6.1
    pn binfmt-support | systemd <none>
    ii bzip2 1.0.8-5+b1
    ii ca-certificates 20230311
    pn debootstrap <none>
    ii distro-info-data 0.58+deb12u3
    ii dpkg-dev 1.21.22
    ii e2fsprogs 1.47.0-2
    pn fakechroot <none>
    pn fakeroot <none>
    pn genext2fs <none>
    pn libarchive13 <none>
    pn lz4 <none>
    pn lzop <none>
    pn ncompress <none>
    pn perl-doc <none>
    pn qemu-user <none>
    pn qemu-user-static <none>
    pn squashfs-tools-ng <none>
    ii xz-utils 5.4.1-1
    ii zstd 1.5.4+dfsg2-5

    -- no debconf information

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johannes Schauer Marin Rodrigues@21:1/5 to All on Tue Apr 29 23:20:01 2025
    XPost: linux.debian.ports.hurd

    Hi,

    I'm putting Debian Hurd maintainers in CC.

    Quoting J.P.Malhado (2025-04-29 17:26:34)
    When running with the following command prompt

    mmdebstrap --mode=chrootless --format=directory --arch=hurd-i386 \
    --include=sysvinit-core,sysv-rc,debian-ports-archive-keyring,gnumach-image-1-486
    --customize-hook="passwd --root=\"\$1\" --delete root" \
    --variant=apt unstable /hurd \
    "deb http://deb.debian.org/debian-ports/ unstale main" \
    "deb http://deb.debian.org/debian-ports/ unreleased main"

    where /hurd is the mountpoint for a partition with a filesystem
    generated with "mk2efs -o hurd" with write permissions to non-root
    users, and the command is being run by a normal user account,
    I'm getting the following output:

    I: skipping emulation check in chrootless mode
    I: finding correct signed-by value...
    done
    readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6889.
    readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6890.
    readdir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6893.
    closedir() attempted on invalid dirhandle $dh2 at /usr/bin/mmdebstrap line 6897.
    I: running apt-get update...
    downloading: 0.00 [>

    And seems to get stuck.

    you title your bug "readdir() attempted on invalid dirhandle". That problem is easily "fixed" with the following patch:

    --- a/mmdebstrap
    +++ b/mmdebstrap
    @@ -6914,7 +6914,9 @@ sub main() {
    # it, if it's empty
    if ($entry eq "lost+found"
    and -d "$options->{root}/$entry") {
    - opendir(my $dh2, "$options->{root}/$entry");
    + opendir(my $dh2, "$options->{root}/$entry")
    + or error
    + "Can't opendir($options->{root}/$entry): $!";
    # Attempt reading the directory thrice. If the third
    # time succeeds, then it has more entries than just "."
    # and ".." and must thus not be empty.


    The problem is, that you are running mmdebstrap as the normal user and that user does not have the required privileges to look into the lost+found directory to check whether it's really empty. With above patch, mmdebstrap will just fail with an appropriate error message. This will avoid the "readdir() attempted
  • From =?utf-8?B?Sm/Do28=?= Pedro Malhado@21:1/5 to Johannes Schauer Marin Rodrigues on Wed Apr 30 19:30:01 2025
    XPost: linux.debian.ports.hurd

    Hello josch,

    Thank you for looking into this.

    On Tue, Apr 29, 2025 at 11:09:21PM +0200, Johannes Schauer Marin Rodrigues wrote:
    The problem is, that you are running mmdebstrap as the normal user and that user does not have the required privileges to look into the lost+found directory to check whether it's really empty. With above patch, mmdebstrap will
    just fail with an appropriate error message. This will avoid the "readdir() attempted on invalid dirhandle" errors from the subject of this bug.

    But I guess this is not quite why you opened this bug and your actual problem is that mmdebstrap gets stuck?

    Thank you for your explanation and patch.

    mmdebstrap might not have been stuck at the download phase, my network was just irresponsive and I was killing the process as I saw the errors showing up. However, I am seeing errors further down. With the same prompt, I'm now seeing

    I: skipping emulation check in chrootless mode
    I: finding correct signed-by values...
    done
    I: running apt-get update...
    done
    I: downloading packages with apt...
    done
    I: extracting archives...
    tar: .: Cannot utime: Operation not permitted
    tar: .: Cannot change mode to rwxr-xr-x: Operation not permitted
    tar: Exiting with failure status due to previous errors
    E: tar --extract failed: 512
    W: hooklistener errored out: E: received eof on socket

    I: main() received signal PIPE: waiting for setup...
    E: mmdebstrap failed to run


    If yes, please read on. Otherwise, consider the bug as fixed with the next upload of mmdebstrap via above patch.

    Firstly, please be *very* careful with chrootless mode. You are running maintainer scripts outside the chroot and this mode is barely tested and many packages are not made to work with it at all. So anything can happen including
    a complete wipe of your $HOME. For that reason and because nothing is checking
    whether the versions of programs run by maintainer scripts are of the version that your packages inside the chroot expect, it is always a good idea to wrap a
    chrootless mmdebstrap call in some sort of containerization. This includes running mmdebstrap in chrootless mode as a customize hooks inside mmdebstrap in
    unshare mode, for example.

    Secondly, have you tried creating a hurd chroot on linux the "normal" way? That
    is by creating a filesystem from a tarball?

    Here is my latest set of runes on the topic:

    https://salsa.debian.org/helmutg/dpkg-root-demo/-/merge_requests/3/diffs#57c00b22e45b81dde62199ab610d05ce70f829bf_0_17

    What do you ultimately want to do?

    What I am trying to do is to use mmdebstrap to setup a hurd + linux dual boot setup, in a similar way to what is achieved with crosshurd (https://packages.debian.org/sid/crosshurd).

    I see what you mean about creating a tarball and copying this over to a new partition, but since mmdebstrap can use a directory as a target, I thought it would be possible to shortcut that step.

    I hear all the warnings you make about chrootless mode, and that is why I was running as a normal user instead of root, but you seem to advise even against that. The problem in running mmdebstrap --mode=chrootless --arch=hurd-i396 inside another mmdebstrap chroot is that the target mountpoint for the hurd partition would not be accessible.

    Do you see a way to install a hurd image to a partition without creating and copying a tarball explicitly?

    Many thanks,
    João

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)