Skip to content

Fails to build on mips64le #4962

@tianon

Description

@tianon

As of the latest releases, we're now failing to build for mips64le:

$ GOARCH=mips64le go build ./libcontainer
# github.com/opencontainers/runc/libcontainer
libcontainer/console_linux.go:36:60: invalid operation: stat.Rdev != unix.Mkdev(PTMX_MAJOR, PTMX_MINOR) (mismatched types uint32 and uint64)
libcontainer/console_linux.go:38:39: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Major
libcontainer/console_linux.go:38:62: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Minor
libcontainer/console_linux.go:82:60: invalid operation: stat.Rdev != wantPeerDev (mismatched types uint32 and uint64)
libcontainer/console_linux.go:84:48: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Major
libcontainer/console_linux.go:84:71: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Minor
libcontainer/rootfs_linux.go:1047:19: invalid operation: stat.Rdev != dev (mismatched types uint32 and uint64)
libcontainer/rootfs_linux.go:1050:16: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Major
libcontainer/rootfs_linux.go:1050:39: cannot use stat.Rdev (variable of type uint32) as uint64 value in argument to unix.Minor
libcontainer/rootfs_linux.go:1321:59: invalid operation: st.Rdev == unix.Mkdev(1, 3) (mismatched types uint32 and uint64)

This was on latest main - the same command completes successfully on v1.4.0-rc.2, and whatever broke this was backported all the way back to the 1.2 branch as part of today's security releases.

This is a similar issue to moby/buildkit#5129, where the root cause is technically a stdlib (or at least x/unix) bug because unix.Mkdev's return type is not platform-specific like the types it's intended to be used with/for.

I was pretty sure it was caused by 8476df8 (just looking through the commits), but did an explicit git bisect just to be Extra and confirmed:

8476df83b534a2522b878c0507b3491def48db9f is the first bad commit
commit 8476df83b534a2522b878c0507b3491def48db9f
Author: Kir Kolyshkin <kolyshkin@gmail.com>
Date:   Thu Mar 6 08:19:45 2025 -0800

    libct: add/use isDevNull, verifyDevNull
    
    The /dev/null in a container should not be trusted, because when /dev
    is a bind mount, /dev/null is not created by runc itself.
    
    1. Add isDevNull which checks the fd minor/major and device type,
       and verifyDevNull which does the stat and the check.
    
    2. Rewrite maskPath to open and check /dev/null, and use its fd to
       perform mounts. Move the loop over the MaskPaths into the function,
       and rename it to maskPaths.
    
    3. reOpenDevNull: use verifyDevNull and isDevNull.
    
    4. fixStdioPermissions: use isDevNull instead of stat.
    
    Fixes: GHSA-9493-h29p-rfm2 CVE-2025-31133
    Co-authored-by: Rodrigo Campos <rodrigoca@microsoft.com>
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>

 libcontainer/init_linux.go          | 11 +++-----
 libcontainer/rootfs_linux.go        | 53 +++++++++++++++++++++++++++++--------
 libcontainer/standard_init_linux.go |  7 +++--
 3 files changed, 49 insertions(+), 22 deletions(-)
bisect found first bad commit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions