Reposting due to popular demand. Several other people are running
into the same problem with all kinds of software.
Only change is rebase against current master.
-Andi
--
I ran into a couple of programs which broke with the new Linux 3.0 version.
Some of those were binary only. I tried to use LD_PRELOAD to work
around it, but it was quite difficult and in one case impossible
because of a mix of 32bit and 64bit executables.
This patch adds a UNAME26 personality that makes the kernel
report a 2.6.40+x version number instead. The x is the x in 3.x.
I know this is somewhat ugly, but I didn't find a better workaround,
and compatibility to existing programs is important.
Some programs also read /proc/sys/kernel/osrelease. This can be worked
around in user space with mount --bind (and a mount namespace)
To use:
wget ftp://ftp.kernel.org/pub/linux/kernel/people/ak/uname26/uname26.c
gcc -o uname26 uname26.c
./uname26 program
Signed-off-by: Andi Kleen <a...@linux.intel.com>
---
include/linux/personality.h | 1 +
kernel/sys.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/include/linux/personality.h b/include/linux/personality.h
index eec3bae..8fc7dd1a 100644
--- a/include/linux/personality.h
+++ b/include/linux/personality.h
@@ -22,6 +22,7 @@ extern int __set_personality(unsigned int);
* These occupy the top three bytes.
*/
enum {
+ UNAME26 = 0x0020000,
ADDR_NO_RANDOMIZE = 0x0040000, /* disable randomization of VA space */
FDPIC_FUNCPTRS = 0x0080000, /* userspace function ptrs point to descriptors
* (signal handling)
diff --git a/kernel/sys.c b/kernel/sys.c
index a101ba3..bd6d142 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -37,6 +37,8 @@
#include <linux/fs_struct.h>
#include <linux/gfp.h>
#include <linux/syscore_ops.h>
+#include <linux/version.h>
+#include <linux/ctype.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
@@ -44,6 +46,8 @@
#include <linux/user_namespace.h>
#include <linux/kmsg_dump.h>
+/* Move somewhere else to avoid recompiling? */
+#include <generated/utsrelease.h>
#include <asm/uaccess.h>
#include <asm/io.h>
@@ -1154,6 +1158,34 @@ DECLARE_RWSEM(uts_sem);
#define override_architecture(name) 0
#endif
+/*
+ * Work around broken programs that cannot handle "Linux 3.0".
+ * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
+ */
+static int override_release(char __user *release, int len)
+{
+ int ret = 0;
+ char buf[len];
+
+ if (current->personality & UNAME26) {
+ char *rest = UTS_RELEASE;
+ int ndots = 0;
+ unsigned v;
+
+ while (*rest) {
+ if (*rest == '.' && ++ndots >= 3)
+ break;
+ if (!isdigit(*rest) && *rest != '.')
+ break;
+ rest++;
+ }
+ v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
+ snprintf(buf, len, "2.6.%u%s", v, rest);
+ ret = copy_to_user(release, buf, len);
+ }
+ return ret;
+}
+
SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
{
int errno = 0;
@@ -1163,6 +1195,8 @@ SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
errno = -EFAULT;
up_read(&uts_sem);
+ if (!errno && override_release(name->release, sizeof(name->release)))
+ errno = -EFAULT;
if (!errno && override_architecture(name))
errno = -EFAULT;
return errno;
@@ -1184,6 +1218,8 @@ SYSCALL_DEFINE1(uname, struct old_utsname __user *, name)
error = -EFAULT;
up_read(&uts_sem);
+ if (!error && override_release(name->release, sizeof(name->release)))
+ error = -EFAULT;
if (!error && override_architecture(name))
error = -EFAULT;
return error;
@@ -1218,6 +1254,8 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
if (!error && override_architecture(name))
error = -EFAULT;
+ if (!error && override_release(name->release, sizeof(name->release)))
+ error = -EFAULT;
return error ? -EFAULT : 0;
}
#endif
--
1.7.4.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
On Fri, Aug 19, 2011 at 7:15 PM, Andi Kleen <an...@firstfloor.org> wrote:
> From: Andi Kleen <a...@linux.intel.com>
>
> Reposting due to popular demand. Several other people are running
> into the same problem with all kinds of software.
>
> Only change is rebase against current master.
>
FWIW, couldn't this be made a boot option ?
That might help some distros, say Fedora, who actually ships
2.6.40+x-branded kernels, or allow people to use no longer supported
distros with recent kernels.
About this last point, once functional, I intend to upgrade my trixbox
install (based on 2.6.18) to a 3.x-ish kernel, that might be fun...
Thanks,
- Arnaud
> Hi,
>
> On Fri, Aug 19, 2011 at 7:15 PM, Andi Kleen <an...@firstfloor.org> wrote:
> > From: Andi Kleen <a...@linux.intel.com>
> >
> > Reposting due to popular demand. Several other people are running
> > into the same problem with all kinds of software.
> >
> > Only change is rebase against current master.
> >
> FWIW, couldn't this be made a boot option ?
>
> That might help some distros, say Fedora, who actually ships
> 2.6.40+x-branded kernels, or allow people to use no longer supported
> distros with recent kernels.
>
> About this last point, once functional, I intend to upgrade my trixbox
> install (based on 2.6.18) to a 3.x-ish kernel, that might be fun...
>
Just a random thought.
Since this is purely to be backwards compatible with binary only software
that makes bad assumptions about the kernel version (as far as I can
tell at least), shouldn't we make it explicit from the beginning that this
will have a limited life time by adding it to
Documentation/feature-removal-schedule.txt with a removal date at
somewhere soon(ish) like 3.6 (or something) at day one?
I can't imaging we'd want to support something like this forever going
forward... or..?
--
Jesper Juhl <j...@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
Believe it or not, even users of programs with source do not necessarily
want or are able to to patch the program and recompile.
Also binary compatibility is important. It's one of the things
that made Linux successfull.
> tell at least), shouldn't we make it explicit from the beginning that this
> will have a limited life time by adding it to
No.
-Andi
--
a...@linux.intel.com -- Speaking for myself only.
init=/script/that/runs/uname26/sbin/init
-Andi
On Sun, Aug 21, 2011 at 7:13 PM, Andi Kleen <an...@firstfloor.org> wrote:
> On Sun, Aug 21, 2011 at 06:28:28PM -0400, Arnaud Lacombe wrote:
>> Hi,
>>
>> On Fri, Aug 19, 2011 at 7:15 PM, Andi Kleen <an...@firstfloor.org> wrote:
>> > From: Andi Kleen <a...@linux.intel.com>
>> >
>> > Reposting due to popular demand. Several other people are running
>> > into the same problem with all kinds of software.
>> >
>> > Only change is rebase against current master.
>> >
>> FWIW, couldn't this be made a boot option ?
>
> init=/script/that/runs/uname26/sbin/init
>
It does not work if / on a ROM, unless you start using trampoline
partition, but this is starting to become really convoluted...
- Arnaud
On a ROM you never change the kernel.
Besides who uses ROMs now when there is flash?
-Andi
On Sun, Aug 21, 2011 at 8:11 PM, Andi Kleen <an...@firstfloor.org> wrote:
>> It does not work if / on a ROM, unless you start using trampoline
>> partition, but this is starting to become really convoluted...
>
> On a ROM you never change the kernel.
>
For this particular board, the kernel is on a small read-write NOR
flash, and the userland on write-protected NAND chip.
> Besides who uses ROMs now when there is flash?
>
this is totally irrelevant to the problem...
- Arnaud
You can use a initrd
And hopefully it's not connected to any network, because you can't
fix any security holes.
-Andi
--
a...@linux.intel.com -- Speaking for myself only.
A boot parameter to change kernel version sounds odd.
>
> That might help some distros, say Fedora, who actually ships
> 2.6.40+x-branded kernels, or allow people to use no longer supported
> distros with recent kernels.
>
> About this last point, once functional, I intend to upgrade my trixbox
> install (based on 2.6.18) to a 3.x-ish kernel, that might be fun...
>
Then a Kconfig option would help.
I have heard this several times now, but nobody actually ever says
*what* is broken.
The Fedora people seem to have done the 2.6.40 thing without any
actual reason, for example (the two programs they claim were broken
were things that they had already fixed in rawhide, afaik).
I'm not at all interested in these kinds of "all kinds of software" reports.
Details. Examples. Name the f&*cking names already. Shame them publicly.
Linus
For example, all kind of management software from HP doesnt work, unless
we pretend to run a 2.6 kernel.
$ uname -a
Linux svivoipvnx001 3.0.0-08107-g97cd98f #1062 SMP Fri Aug 12 18:11:45
CEST 2011 i686 i686 i386 GNU/Linux
$ hpacucli ctrl all show
Error: No controllers detected.
$ rpm -qf /usr/sbin/hpacucli
hpacucli-8.75-12.0
Perhaps the 3.x version change patch should be reverted on the
never-ever-break-userspace grounds. :-) It would appear that the 2.6
version information has become a de facto part of the kernel's ABI.
David Daney
My original motivation for this was pin (http://www.pintool.org/)
However that got fixed in pin after I posted v1.
Then people kept emailing me that they had their own applications with
similar problems. I don't have a lot of details on those, but I hope others
will chime in on this thread.
e.g. Dirk claimed he had a bunch. Dirk?
-Andi
--
a...@linux.intel.com -- Speaking for myself only.
I would suggest adding this to setarch, as that handles all the other
personality flags. The following patch to util-linux seems to do the
trick.
Ben.
configure.ac | 1 +
sys-utils/setarch.8 | 3 +++
sys-utils/setarch.c | 12 +++++++++++-
3 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0d3b889..51d06fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -792,6 +792,7 @@ AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec],,,
[#include <sys/stat.h>])
AC_CHECK_DECLS([
+ UNAME26,
ADDR_NO_RANDOMIZE,
FDPIC_FUNCPTRS,
MMAP_PAGE_ZERO,
diff --git a/sys-utils/setarch.8 b/sys-utils/setarch.8
index 0764a45..b6f5b77 100644
--- a/sys-utils/setarch.8
+++ b/sys-utils/setarch.8
@@ -29,6 +29,9 @@ Be verbose.
.I "\-h," "\-\-help"
Display help (it is also displayed when setarch takes no arguments).
.TP
+.I "\-\-uname\-2.6"
+Causes the program to see a kernel version number beginning with 2.6.
+.TP
.I "\-3," "\-\-3gb"
Specifies that processes should use a maximum of 3GB of address space on systems where it is supported (ADDR_LIMIT_3GB).
.TP
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index 35efca4..b53bf36 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -41,6 +41,8 @@
/* Option --4gb has no equivalent short option, use a non-character as a
pseudo short option. */
#define OPT_4GB (CHAR_MAX+1)
+/* Similarly for --uname-2.6 */
+#define OPT_UNAME26 (OPT_4GB+1)
#define turn_on(_flag, _opts) \
do { \
@@ -50,6 +52,9 @@
} while(0)
+#if !HAVE_DECL_UNAME26
+# define UNAME26 0x0020000
+#endif
#if !HAVE_DECL_ADDR_NO_RANDOMIZE
# define ADDR_NO_RANDOMIZE 0x0040000
#endif
@@ -98,6 +103,7 @@ static const struct option longopts[] =
{ "sticky-timeouts", 0, 0, 'T' },
{ "3gb", 0, 0, '3' },
{ "4gb", 0, 0, OPT_4GB },
+ { "uname-2.6", 0, 0, OPT_UNAME26 },
{ NULL, 0, 0, 0 }
};
@@ -125,7 +131,8 @@ show_help(void)
" -S, --whole-seconds turns on WHOLE_SECONDS\n"
" -T, --sticky-timeouts turns on STICKY_TIMEOUTS\n"
" -3, --3gb limits the used address space to a maximum of 3 GB\n"
- " --4gb ignored (for backward compatibility only)\n"));
+ " --4gb ignored (for backward compatibility only)\n"
+ " --uname-2.6 turns on UNAME26\n"));
printf(_("\nFor more information see setarch(8).\n"));
exit(EXIT_SUCCESS);
@@ -306,6 +313,9 @@ int main(int argc, char *argv[])
break;
case OPT_4GB: /* just ignore this one */
break;
+ case OPT_UNAME26:
+ turn_on(UNAME26, options);
+ break;
}
}
--
1.7.5.4
I have one simple rule: "Linus' tree first", and I don't see UNAME26
in include/linux/personality.h ...
Karel
--
Karel Zak <kz...@redhat.com>
http://karelzak.blogspot.com
Sure, I don't expect this to be applied until and unless Linus takes the
kernel patch.
Ben.
I guess another option would be to add a new sys_newnewuname syscall
and change glibc. You could use symbol versioning so that
old applications continue to see the 2.6.x version numbers, while
anything that is built against a new glibc would see the true
version.
> This patch adds a UNAME26 personality that makes the kernel
> report a 2.6.40+x version number instead. The x is the x in 3.x.
Why not just always return 3.6.39 or 2.6.40 hardcoded? If an application
does not understand the concept of future kernel versions, it won't need
to know which future version it's running on.
Arnd
> Details. Examples. Name the f&*cking names already. Shame them publicly.
A notable one is that Python now reports "linux3" from sys.platform();
which in turn can break things that were checking sys.platform() ==
"linux2".
https://bugzilla.mozilla.org/show_bug.cgi?id=664564
Seems pretty clear to me though it's a bug in the apps that are using
'==' instead of .startswith().
That's a good point. I googled for this pattern in google codesearch
and there are 10+ in the first two pages.
http://www.google.com/codesearch#search/&q=lang:^python$%20sys.platform%20linux2&p=1&type=cs
-andi
Yes, though I should note I wasn't trying to defend having a
compatibility sysctl or whatever - I think it's clear these apps are
broken. The python docs explicitly say that the returned string is
just a straightforward transformation of uname, and if the apps read
that carefully they'd realize they only want the first part.
The reportlab example will break for FreeBSD 5 too:
elif sys.platform in ("freebsd4", "darwin", "mac", "linux2"):
I just happen to watch Mozilla bugzilla so I saw that one go by and
wanted to provide data for the discussion.
On Tue, Aug 23, 2011 at 12:20 PM, Colin Walters <wal...@verbum.org> wrote:
> [...]
> I just happen to watch Mozilla bugzilla so I saw that one go by and
> wanted to provide data for the discussion.
>
Just to provide fuel, you can also just do a regular google search for
"strncmp release 2.6". Lots of exploits, but not only.
- Arnaud
This doesn't count under "no userspace breakage" doctrine.
Or rather, it shouldn't.
valgrind _compilation_ was broken by 3.0:
11 *valgrind-3.6.1-r1 (09 Jun 2011)
12
13 09 Jun 2011; Anthony G. Basile <blue...@gentoo.org>
14 +valgrind-3.6.1-r1.ebuild, +files/valgrind-3.6.1-linux-3.patch:
15 Fixed to build against linux-3.x, bug #370857
Was this fixed? Yes.
Will this break one more time? Of course!
case "${kernel}" in
- 2.6.*)
+ 2.6.*|3.*)
AC_MSG_RESULT([2.6 family (${kernel})])
What you need is an exaustive list of past versions plus
a catch-all for future versions:
case "${kernel}" in
1.*|2.0.*|2.1.*|2.2.*|2.3.*)
echo "too old"
;;
2.4.*)
echo "Linux-2.4 style"
;;
2.5.*)
echo "unstable and not supported"
;;
*)
echo "2.6 or newer"
;;
esac
We don't break ABIs as a rule, so you should always assume
that a newer version will keep working.
Arnd
I hate to ask, but can you put a proper copyright and license on this
file so that distros can distribute it?
thanks,
greg k-h
It's in Linus's tree now, and will be in the next 3.0.y stable release.
thanks,
greg k-h
I assumed it's too trivial for that.
Anyways I put a GPL license on it now.
-Andi
Lawyers never assume that :)
> Anyways I put a GPL license on it now.
Thanks, much appreciated.
greg k-h
> > > wget ftp://ftp.kernel.org/pub/linux/kernel/people/ak/uname26/uname26.c
> > > gcc -o uname26 uname26.c
> > > ./uname26 program
> >
> > I hate to ask, but can you put a proper copyright and license on this
> > file so that distros can distribute it?
>
> I assumed it's too trivial for that.
>
> Anyways I put a GPL license on it now.
>
Hi Andi
I assume the mention of "mcelog" is a cut'n'paste error and that it really
should have been "uname26", so here's a trivial patch to correct that.
I also deleted all trailing whitespace and used EXIT_FAILURE rather than 1
for exit().
Take it or leave it :)
Signed-off-by: Jesper Juhl <j...@chaosbits.net>
---
--- uname26.c.orig 2011-08-27 18:26:46.538017670 +0200
+++ uname26.c 2011-08-27 18:32:21.032163525 +0200
@@ -1,19 +1,19 @@
-/* Copyright (C) 2011 Intel Corporation
+/* Copyright (C) 2011 Intel Corporation
Author: Andi Kleen
Set 2.6.x personality
- mcelog is free software; you can redistribute it and/or
+ uname26 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; version
2.
- mcelog is distributed in the hope that it will be useful,
+ uname26 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should find a copy of v2 of the GNU General Public License somewhere
- on your Linux system; if not, write to the Free Software Foundation,
+ on your Linux system; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <sys/personality.h>
#include <stdio.h>
@@ -26,15 +26,15 @@
int main(int ac, char **av)
{
- if (!av[1]) {
+ if (!av[1]) {
fprintf(stderr, "Usage: uname26 program ...\n"
"Run program with the uname 2.6 personality\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
if (personality(PER_LINUX | UNAME26) < 0)
perror("personality"), exit(1);
-
+
execvp(av[1], av + 1);
fprintf(stderr, "Cannot execute %s: %s\n", av[1], strerror(errno));
- exit(1);
+ exit(EXIT_FAILURE);
}
--
Jesper Juhl <j...@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
Applied, thanks.
Karel
--
Karel Zak <kz...@redhat.com>
http://karelzak.blogspot.com
ketchup :-(. And no, it is probably not what you wanted, and no, it is
not easy to fix.
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Well, I think it doesn't really matter at all, if ketchup broke with 3.x
kernels, but there is a (semi-)working version of ketchup (I'm not very
proud of the code I wrote), which works with 3.x kernels (and
fortunately with 4.x and later).
[1] https://github.com/psomas/ketchup
Thanks,
--
Stratos Psomadakis
<pso...@gentoo.org>
--
Stratos Psomadakis
<s.psom...@gmail.com>
Anyway, I think that this discussion is a bit 'offtopic', since I didn't
think you had ketchup (or similar scripts) in mind for this patch.
I just replied to Pavel, just to let him (and anyone else interested)
know, that ketchup has in fact been updated to handle the newer kernel
versions.
Thanks,
--
Stratos Psomadakis
<s.psom...@gmail.com>