FS#15498 - [gcc] can't compile grsecurity kernel

Attached to Project: Arch Linux
Opened by Jonathan Liu (net147) - Monday, 13 July 2009, 11:59 GMT
Last edited by Allan McRae (Allan) - Tuesday, 14 July 2009, 03:30 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To No-one
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
CC [M] drivers/staging/meilhaus/memain.o
/home/user/abs/kernel26-grsecurity/src/linux-2.6.29/arch/x86/include/asm/uaccess_64.h: Assembler messages:
/home/user/abs/kernel26-grsecurity/src/linux-2.6.29/arch/x86/include/asm/uaccess_64.h:92: Error: suffix or operands invalid for `movq'
make[3]: *** [drivers/staging/meilhaus/memain.o] Error 1
make[2]: *** [drivers/staging/meilhaus] Error 2
make[1]: *** [drivers/staging] Error 2
make: *** [drivers] Error 2

Additional info:
* gcc 4.4.0-5
* Compiling with gcc 4.4.0-2 doesn't work
* Compiling with gcc 4.4.0 20090707 snapshot doesn't work either
* Compiling with gcc 4.3.3 works

Steps to reproduce:
* wget http://aur.archlinux.org/packages/kernel26-grsecurity/kernel26-grsecurity.tar.gz
* tar -zxvf kernel26-grsecurity.tar.gz
* cd kernel26-grsecurity
* makepkg

The code that fails to compile is in linux-2.6.29/arch/x86/include/asm/uaccess_64.h in the function __copy_to_user and fails when the size argument is 8.

Removing the __always_inline macro (which expands to the inline keyword) makes it compile successfully.
Compiling with -O0 instead of -O2 also works.

It seems to be a compiler bug of some sort ...
This task depends upon

Closed by  Allan McRae (Allan)
Tuesday, 14 July 2009, 03:30 GMT
Reason for closing:  Upstream
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 12:03 GMT
The code that is failing is being called from src/linux-2.6.29/drivers/staging/meilhaus/memain.c in the me_query_version_main_driver function:
err = copy_to_user(arg, &karg, sizeof(me_query_version_main_driver_t));

sizeof(me_query_version_main_driver_t) is 8.
Comment by Allan McRae (Allan) - Monday, 13 July 2009, 12:07 GMT
Try with updated kernel headers
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 12:08 GMT
I'm using kernel-headers 2.6.30.1-1.
Comment by Allan McRae (Allan) - Monday, 13 July 2009, 12:15 GMT
Yeah, but that PKGBUILD is not...
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 12:19 GMT
I don't see how it could be the kernel headers if it works with GCC 4.3.3... otherwise how do you suggest I try with updated kernel headers?
It seems like some sort of GCC optimisation error introduced in 4.4.
Comment by Allan McRae (Allan) - Monday, 13 July 2009, 12:26 GMT
Maybe the newer kernel headers have fixes for gcc-4.4... You probably just need to update the kernel version in the PKGBUILD to 2.6.30.
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 12:29 GMT
There isn't a grsecurity patch for 2.6.30. The latest is for 2.6.29.6 and i've tried with that as well with no luck (same error, same place).
Comment by Allan McRae (Allan) - Monday, 13 July 2009, 12:49 GMT
what arch are you using?
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 12:51 GMT
x86_64 as mentioned in the task details.
Running Arch Linux 64-bit with Intel(R) Pentium(R) Dual CPU E2220 @ 2.40GHz.
Comment by Gerardo Exequiel Pozzi (djgera) - Monday, 13 July 2009, 18:55 GMT
Disable "staging drivers", these drivers are in the mainline, but not ensure that can compile or work fine.

I am sure that you don't use the "meilhaus" :)
Comment by Jonathan Liu (net147) - Monday, 13 July 2009, 22:01 GMT
Disabling them would only work around the compiler issue and not fix it.
I could add a dependency on GCC 4.3.3 from AUR and get it to use that in the meantime I suppose...

Anyone know GCC options for printing out the assembly code with the compiler warnings?
Comment by Allan McRae (Allan) - Monday, 13 July 2009, 22:55 GMT
Hmm... looking at this, is that a 32bit piece of assembly attempting to be compiled on a 64bit machine?

Anyway, almost everything I have seen not compile at -02 but do compile at lower optimisation in gcc-4.4 can be "fixed" by adding the "-fno-strict-aliasing". If that works, it is a code bug and if not, it is a compiler or code bug... Either way, a bug report needs to go upstream. Not much we can do here.
Comment by Gerardo Exequiel Pozzi (djgera) - Tuesday, 14 July 2009, 00:22 GMT
Step to reproduce don't work, patch not exist anymore:

Anyway: Yes, for some reason the compiler generates this instruction: movq $4294967295,(%rbp)

Using http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.6.tar.bz2 + http://www.grsecurity.net/test/grsecurity-2.1.14-2.6.29.6-200907122214.patch

[djgera@exequiel linux-2.6.29]$ gcc -Wp,-MD,drivers/staging/meilhaus/.memain.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include -Iinclude -I/tmp/kernel26-grsecurity/linux-2.6.29/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iarch/x86/include/asm/mach-default -Wframe-larger-than=2048 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(memain)" -D"KBUILD_MODNAME=KBUILD_STR(memain)" -c drivers/staging/meilhaus/memain.c -S -o - | grep movq
Comment by Gerardo Exequiel Pozzi (djgera) - Tuesday, 14 July 2009, 02:08 GMT
Please report to grsecurity, I am not sure if this is a gcc bug because, seems that is strict related with grsecurity patch, because the assembler generated is hardcoded in arch/x86/include/asm/uaccess.h. If the patch is not applied, mnemonics here does not appears in the output .s file.

For example in arch/x86/include/asm/uaccess.h in the macro __put_user_asm add a comment

asm volatile("1: mov"itype" %"rtype"1,%2 /* HOLA */ \n" \

but if grsecurity patch is present , will be in the output.

Comment by Allan McRae (Allan) - Tuesday, 14 July 2009, 03:30 GMT
Agreed. Report to grsecurity, and if they say compiler bug, report to gcc.

Closing as upstream. Request reopen if it is a gcc bug and upstream provides a patch.

Loading...