2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00
Files
xcat-core/xCAT-test/unit/genesis_deb_loader_executable.t
T
Daniel Hilst 09e277a6a1 fix(xcat-genesis-base): the deb ships a Genesis loader with no execute bit, so every node panics
An Ubuntu node that netboots legacy Genesis dies with

  Failed to execute /init (error -13)
  Kernel panic - not syncing: No working init found.

xCAT-genesis-base/debian/rules is a bare `dh $@`, so dh_fixperms applies its
*.so* rule to the whole package. That is right for a Debian shared library and
wrong for a netboot ROOT FILESYSTEM: the kernel execs the payload's dynamic
loader, and a loader with no execute bit makes open_exec() return EACCES, so
every ELF in the image fails to start. mknb copies the tree verbatim into
genesis.fs.<arch>.lzma, so the mode travels into the image. The pipeline's iPXE
command line carries `quiet`, which hid the reason.

Measured on xcat-master-ub from the installed package:
  644 .../netboot/genesis/x86_64/fs/usr/lib64/ld-linux-x86-64.so.2
  755 .../netboot/genesis/x86_64/fs/usr/bin/basename

and reproduced away from the lab: that management node's own kernel and image
under qemu panicked at 35 seconds, a repack with no change panicked again, and a
repack with only chmod 0755 on the loader reached /init and started dracut.

The EL rpm is unaffected, because it never runs dh_fixperms. This is why only
the Ubuntu genesis-legacy cell saw it, and why that cell has never had a
non-mock green. It is not a regression: the same recipe builds the published
xcat-genesis-base-amd64.

The bit is restored AFTER dh_fixperms rather than excluding the tree with -X,
which would also skip its chown 0:0 pass and ship the payload owned by the build
user.

genesis_deb_loader_executable.t asserts the override exists, still calls
dh_fixperms, is scoped to the netboot tree, names both the glibc and the ppc64le
loader, and runs the chmod AFTER dh_fixperms. Three of its ten assertions fail
without the override, and the ordering assertion fails if the chmod is moved
first -- which is the mistake that looks correct.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-23 12:16:02 -03:00

74 lines
3.6 KiB
Perl

#!/usr/bin/env perl
# THE GENESIS PAYLOAD'S DYNAMIC LOADER MUST KEEP ITS EXECUTE BIT IN THE DEB.
#
# xCAT-genesis-base/debian/rules was a bare `dh $@`, so dh_fixperms applied its *.so* rule to the
# whole package -- correct for a Debian shared library, wrong for a netboot ROOT FILESYSTEM. The
# kernel execs the payload's dynamic loader, and a loader with no execute bit makes open_exec()
# return EACCES, so every ELF in the Genesis image fails to start:
#
# Failed to execute /init (error -13)
# Kernel panic - not syncing: No working init found.
#
# mknb copies the tree verbatim into genesis.fs.<arch>.lzma, so the broken mode travels into the
# image. The pipeline's iPXE command line carries `quiet`, which hid the reason.
#
# Measured 2026-10-23 on xcat-master-ub, from the installed package:
# 644 .../netboot/genesis/x86_64/fs/usr/lib64/ld-linux-x86-64.so.2
# 755 .../netboot/genesis/x86_64/fs/usr/bin/basename
# and reproduced off the lab: the MN's own kernel and image under qemu panicked at 35s, repacked
# unchanged panicked again, and repacked with only chmod 0755 on the loader booted. The EL rpm is
# unaffected -- it never runs dh_fixperms -- which is why only xcat-test-ubuntu-24-x86_64
# -genesis-legacy saw it, and why that leaf has never had a non-mock green.
#
# debian/rules IS the artifact here: there is nothing to execute and the text is the contract, the
# same reason a test may assert a package name in a .spec. The live proof is the leaf.
use strict;
use warnings;
use Test::More;
use FindBin;
use File::Slurper qw(read_text);
my $rules = "$FindBin::Bin/../../xCAT-genesis-base/debian/rules";
ok(-f $rules, 'xCAT-genesis-base/debian/rules is present') or die "no rules file\n";
my $text = read_text($rules);
# The override must exist. Without it dh_fixperms runs with its defaults over the payload.
like($text, qr/^override_dh_fixperms:/m,
'debian/rules overrides dh_fixperms');
# It must still RUN dh_fixperms. Dropping it would leave the rest of the package unnormalised --
# the chown 0:0 pass and the 0644 on documentation are both wanted.
like($text, qr/^override_dh_fixperms:\n(?:.*\n)*?\tdh_fixperms\b/m,
'... and still calls dh_fixperms rather than replacing it');
# And it must restore the loader afterwards, under the netboot tree only.
my ($body) = $text =~ /^override_dh_fixperms:\n((?:[\t ].*\n|\n)*)/m;
ok(defined $body && length $body, 'the override has a body') or die "no override body\n";
like($body, qr/netboot\/genesis/,
'the restore is scoped to the netboot payload, not the whole package');
like($body, qr/chmod\s+0?755/,
'... and puts the execute bit back');
like($body, qr/ld-\*\.so/,
'... on the glibc loader (ld-*.so)');
like($body, qr/ld64\.so/,
'... and on the ppc64le loader (ld64.so.*)');
# ORDER: dh_fixperms strips the bit, so the chmod has to come after it. A chmod first would be
# undone by the very command this override exists to correct.
my @lines = split /\n/, $body;
my ($fix) = grep { $lines[$_] =~ /\bdh_fixperms\b/ } 0 .. $#lines;
my ($chm) = grep { $lines[$_] =~ /\bchmod\b/ } 0 .. $#lines;
if (defined $fix && defined $chm) {
cmp_ok($fix, '<', $chm, 'dh_fixperms runs BEFORE the chmod that corrects it');
}
# NOT with -X. Excluding the tree from dh_fixperms would also skip its chown 0:0 pass, so the
# payload would ship owned by the build user.
# Command lines only. A comment that merely MENTIONS -X is not an exclusion, and matching the
# whole file made this assertion fail on the comment that explains why -X was not used.
my @recipe = grep { /^\t/ } split /\n/, $text;
ok(!(grep { /dh_fixperms[^\n]*-X/ } @recipe),
'the tree is not excluded from dh_fixperms wholesale');
done_testing;