Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uname26 personality patches from balena-generic #43

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ ARG KERNEL_BRANCH=5.10
RUN git clone --depth 1 -c advice.detachedHead=false \
--branch "v${KERNEL_BRANCH}" https://github.com/torvalds/linux.git .

COPY vmlinux/*.patch ./

RUN git apply -v ./*.patch

###############################################

FROM linux.git AS vmlinux
Expand Down
9 changes: 0 additions & 9 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ services:
cache_from:
- sut:latest
hostname: alpine-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}

debian-test:
extends:
Expand All @@ -75,9 +72,6 @@ services:
cache_from:
- sut:latest
hostname: debian-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}

ubuntu-test:
extends:
Expand All @@ -90,6 +84,3 @@ services:
cache_from:
- sut:latest
hostname: ubuntu-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}
2 changes: 1 addition & 1 deletion overlay/sbin/init
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if [ ! -d /sys/fs/cgroup/systemd ]; then
mount -v -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
fi

if ! grep -q localhost /etc/hosts; then
if ! grep -q localhost /etc/hosts 2>/dev/null; then
echo "127.0.0.1 localhost" >>/etc/hosts
fi

Expand Down
4 changes: 4 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ if [ -z "${KERNEL_BOOT_ARGS:-}" ]; then
fi
fi

if [ -n "${EXTRA_KERNEL_BOOT_ARGS:-}" ]; then
KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ${EXTRA_KERNEL_BOOT_ARGS}"
fi

KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} $(network_config "${GUEST_IP}" "${TAP_IP}" "$(hostname)" eth0)"

echo "Virtual CPUs: ${VCPU_COUNT}"
Expand Down
31 changes: 25 additions & 6 deletions test/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ id

date

uname -a
userspace_arch="$(dpkg --print-architecture 2>/dev/null || apk --print-arch)"
case ${userspace_arch} in
x86_64|amd64)
uname -a | grep x86_64
;;
aarch64|arm64)
uname -a | grep aarch64
setarch linux32 uname -m | tee /dev/stderr | grep armv7l
setarch linux32 --uname-2.6 uname -m | tee /dev/stderr | grep armv6l
;;
*)
echo "Unsupported architecture: ${userspace_arch}"
exit 1
;;
esac

df -h

Expand Down Expand Up @@ -51,15 +65,20 @@ if command -v ip >/dev/null 2>&1; then
ip route
fi

# nested virtualization is not available on aarch64
if [ -r /dev/kvm ]; then
case $(uname -m) in
x86_64)
ls -l /dev/kvm
test -w /dev/kvm

test -w /dev/kvm || test "$(id -u)" != 0
if which kvm-ok >/dev/null; then
kvm-ok
fi
fi
;;
*)
# https://github.com/balena-io-experimental/container-jail/issues/44
# https://github.com/firecracker-microvm/firecracker/issues/1721
echo "Nested KVM unavailable on this architecture!"
;;
esac

if command -v npm >/dev/null 2>&1; then
npm ping
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From: Andy Whitcroft <[email protected]>
Date: Fri, 27 Nov 2015 17:38:30 +0000
Subject: [PATCH] UBUNTU: SAUCE: (no-up) add compat_uts_machine= kernel command
line override

We wish to use the arm64 buildds to build armhf binaries in 32bit chroots.
To make this work we need uname to return armv7l machine type. To achieve
this add a kernel command line override for the 32bit machine type.
Add compat_uts_machine=<type> to allow the LINUX32 personality to return
that type for uname.

Signed-off-by: Andy Whitcroft <[email protected]>
---
kernel/sys.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/kernel/sys.c b/kernel/sys.c
index 83ffd7dccf23..5b030fbaf199 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1138,6 +1138,21 @@ SYSCALL_DEFINE0(setsid)

DECLARE_RWSEM(uts_sem);

+#ifdef COMPAT_UTS_MACHINE
+static char compat_uts_machine[__OLD_UTS_LEN+1] = COMPAT_UTS_MACHINE;
+
+static int __init parse_compat_uts_machine(char *arg)
+{
+ strncpy(compat_uts_machine, arg, __OLD_UTS_LEN);
+ compat_uts_machine[__OLD_UTS_LEN] = 0;
+ return 0;
+}
+early_param("compat_uts_machine", parse_compat_uts_machine);
+
+#undef COMPAT_UTS_MACHINE
+#define COMPAT_UTS_MACHINE compat_uts_machine
+#endif
+
#ifdef COMPAT_UTS_MACHINE
#define override_architecture(name) \
(personality(current->personality) == PER_LINUX32 && \
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From: Zubair Lutfullah Kakakhel <[email protected]>
Date: Mon, 11 Feb 2019 15:52:06 +0000
Subject: [PATCH] HACK: Use the UNAME26 personality to return armv6l instead of
v2.6.32+

We'd like to make our arm builders return two different machine strings
at runtime for different processes. armv7l and armv6l. This is so that
a docker daemon for armv6l/armv8l device builds thinks the docker build
is unning under the correct machine arch. Various package managers such
as pip rely on the output of uname -m to be correct.

The UNAME26 personality is used by old userspace programs to make the
kernel version string appear as 2.6+.

Add a hack in the kernel to modify the machine string for the uname26
personality and make it show armv6l. And don't change the kernel
version string to 2.6.+

The benefit of this hack instead of adding a new personality is
- we won't have to carry a custom version of the setarch userspace utility
- simpler to implement and keep lying around

Trade-off. I'm hoping no customer is pushing applications that depend
on the kernel version string being 2.6+ and the actual uname26
personality usage.

With this patch and compat_uts_machine=armv7l in the kernel cmdline
on our arm builder

root@arm02:~# linux32 --uname-2.6 uname -m
armv6l
root@arm02:~# linux32 uname -m
armv7l
root@arm02:~# uname -m
aarch64
root@arm02:~#

Signed-off-by: Zubair Lutfullah Kakakhel <[email protected]>
---
kernel/sys.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 4e0a24b0c14d..f8807b47740b 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1173,24 +1173,9 @@ static int override_release(char __user *release, size_t len)
{
int ret = 0;

+ strncpy(compat_uts_machine, "armv7l", __OLD_UTS_LEN);
if (current->personality & UNAME26) {
- const char *rest = UTS_RELEASE;
- char buf[65] = { 0 };
- int ndots = 0;
- unsigned v;
- size_t copy;
-
- while (*rest) {
- if (*rest == '.' && ++ndots >= 3)
- break;
- if (!isdigit(*rest) && *rest != '.')
- break;
- rest++;
- }
- v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 60;
- copy = clamp_t(size_t, len, 1, sizeof(buf));
- copy = scnprintf(buf, copy, "2.6.%u%s", v, rest);
- ret = copy_to_user(release, buf, copy + 1);
+ strncpy(compat_uts_machine, "armv6l", __OLD_UTS_LEN);
}
return ret;
}
Loading