Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 842027 - genkernel linuxrc relies on busybox undefined behaviour, leads to boot failure on sparc
Summary: genkernel linuxrc relies on busybox undefined behaviour, leads to boot failur...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords: PATCH
Depends on: 861110
Blocks:
  Show dependency tree
 
Reported: 2022-05-01 21:07 UTC by Andreas K. Hüttel
Modified: 2022-07-26 04:32 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas K. Hüttel archtester gentoo-dev 2022-05-01 21:07:14 UTC
When trying to install a new kernel on catbus.sparc.dev.gentoo.org, the newly built initrd consistently claimed that it could not find init, and dropped to the rescue shell.

However, init was there just fine in /newroot (as before).

I dug out the command that is actually run inside linuxrc, 

        elif ! chroot "${CHROOT}" test -x /${init#/} 1>/dev/null 2>&1

and tried to run that manually, which led to a rather strange error message (sorry I dont have it anymore, it was not very helpful, but also indicated a problem different from ! -x ).

Some more research led me to the busybox manpage (where here chroot comes from):
https://busybox.net/downloads/BusyBox.html#chroot

chroot
    chroot NEWROOT [PROG [ARGS]]
    Run PROG with root directory set to NEWROOT

Note, the third argument is *not* a command (as with usual chroot, see the manpage from coreutils chroot) but a program!

The following small patch led to a successful boot:

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 6ede740..fbe82d1 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -1358,7 +1358,7 @@ do
        if  ! mountpoint "${CHROOT}" 1>/dev/null 2>&1
        then
                bad_msg "${CHROOT} is not a mountpoint; Was root device (${REAL_ROOT}) not mounted?"
-       elif ! chroot "${CHROOT}" test -x /${init#/} 1>/dev/null 2>&1
+       elif ! chroot "${CHROOT}" /usr/bin/test -x /${init#/} 1>/dev/null 2>&1
        then
                mounted_root_device=$(mountpoint -n /newroot 2>/dev/null | awk '{ print $1 }')
                bad_msg "init (${init}) not found in mounted root device (${mounted_root_device})!"


(i.e., adding the full path to the test binary). 

TIA for fixing
Comment 1 dwfreed 2022-05-02 02:41:43 UTC
This was the error:

rescueshell / # chroot /newroot test -x /lib/systemd/systemd
chroot: can't execute 'test': File name too long

Very unhelpful error.
Comment 2 Larry the Git Cow gentoo-dev 2022-05-16 19:33:52 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=33394fef9f712ca0854eca248fe85863771ca04a

commit 33394fef9f712ca0854eca248fe85863771ca04a
Author:     Andreas K. Hüttel <dilfridge@gentoo.org>
AuthorDate: 2022-05-16 19:31:34 +0000
Commit:     Andreas K. Hüttel <dilfridge@gentoo.org>
CommitDate: 2022-05-16 19:33:25 +0000

    linuxrc: do not rely on chroot evaluating PATH
    
    When trying to install a new kernel on catbus.sparc.dev.gentoo.org, the
    newly built initrd consistently claimed that it could not find init, and
    dropped to the rescue shell.
    
    However, init was there just fine in /newroot (as before).
    
    I dug out the command that is actually run inside linuxrc,
    
            elif ! chroot "${CHROOT}" test -x /${init#/} 1>/dev/null 2>&1
    
    and tried to run that manually, which led to a rather strange error message
    
    rescueshell / # chroot /newroot test -x /lib/systemd/systemd
    chroot: can't execute 'test': File name too long
    
    Some more research led me to the busybox manpage (where here chroot comes
    from):
    https://busybox.net/downloads/BusyBox.html#chroot
    
    chroot
        chroot NEWROOT [PROG [ARGS]]
        Run PROG with root directory set to NEWROOT
    
    Note, the third argument is *not* a command (as with usual chroot, see the
    manpage from coreutils chroot) but a program!
    
    Bug: https://bugs.gentoo.org/842027
    Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>

 defaults/linuxrc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 3 Larry the Git Cow gentoo-dev 2022-07-24 23:19:47 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c5764a9d99e1f84eef38ee09cb80491cb24ac905

commit c5764a9d99e1f84eef38ee09cb80491cb24ac905
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-07-24 23:19:17 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-07-24 23:19:40 +0000

    sys-kernel/genkernel: backport chroot/busybox fix, s390x config
    
    Needed to fix sparc livecds at least.
    
    Bug: https://bugs.gentoo.org/842027
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-kernel/genkernel/Manifest                      |   1 +
 .../files/genkernel-4.2.6-chroot-path.patch        |  49 ++++
 sys-kernel/genkernel/genkernel-4.2.6-r5.ebuild     | 323 +++++++++++++++++++++
 3 files changed, 373 insertions(+)