Skip to content

Commit

Permalink
Add uname26 personality patches from balena-generic @ cff3eed
Browse files Browse the repository at this point in the history
This allows to use this kernel in our ARM builder that require armv7l
and armv6l machine strings to build.

Change-type: patch
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Dec 14, 2023
1 parent 3ac2a08 commit 9b428b5
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
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;
}

0 comments on commit 9b428b5

Please sign in to comment.