steleman / address-sanitizer

Automatically exported from code.google.com/p/address-sanitizer
0 stars 0 forks source link

Kernel compilation error when using KSAN #370

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Step 1:
To instrument the kernel we need to use a custom GCC, which I have download 
https://address-sanitizer.googlecode.com/files/gcc-r203101-snapshot.tar.gz
Step2:
download ksan patched kernel https://github.com/google/kasan
Step3:
Untar the gcc downloaded in step 1 and kernel in step 2
export GCC_KASAN=<path_to_gcc_base_directory>
Step4.
cd <kernel_base_directory>
make CC='$GCC_KASAN/bin/gcc' olddefconfig
make CC='$GCC_KASAN/bin/gcc' menuconfig
Enable ( Generalsetup -> CONFIG_SLAB ) and ( Kernel hacking -> Memory Debugging 
-> CONFIG_ASAN )
Step5:
make CC='$GCC_KASAN/bin/gcc' -j<no.jobs>

by following above procedure after Step5 I have encountered below Error:
-----------------------------------------------------------------------
0 :) prasanna.k ~/Ksan/work/linux-kasan $ make CC=${GCC_KASAN}/gcc -j20
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_64.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_x32.h
  CHK     include/config/kernel.release
  WRAP    arch/x86/include/generated/asm/clkdev.h
  WRAP    arch/x86/include/generated/asm/cputime.h
  WRAP    arch/x86/include/generated/asm/early_ioremap.h
  WRAP    arch/x86/include/generated/asm/mcs_spinlock.h
  WRAP    arch/x86/include/generated/asm/scatterlist.h
  UPD     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler
  CC      scripts/mod/empty.o
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/lex.lex.c
  HOSTCC  scripts/mod/mk_elfconfig
  CC      scripts/mod/devicetable-offsets.s
  SHIPPED scripts/genksyms/keywords.hash.c
  SHIPPED scripts/genksyms/parse.tab.h
  HOSTCC  scripts/selinux/mdp/mdp
cc1: error: invalid parameter ‘asan-use-after-return’
cc1: error: invalid parameter ‘asan-globals’
cc1: error: invalid parameter ‘asan-memintrin’
cc1: error: invalid parameter ‘asan-instrumentation-with-call-threshold’
cc1: error: invalid parameter ‘asan-fixed-shadow-offset’
  SHIPPED scripts/genksyms/parse.tab.c
cc1: error: invalid parameter ‘asan-use-after-return’
cc1: error: invalid parameter ‘asan-globals’
cc1: error: invalid parameter ‘asan-memintrin’
cc1: error: invalid parameter ‘asan-instrumentation-with-call-threshold’
cc1: error: invalid parameter ‘asan-fixed-shadow-offset’
  HOSTCC  scripts/genksyms/lex.lex.o
make[2]: *** [scripts/mod/empty.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/mod/devicetable-offsets.s] Error 1
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/genksyms/parse.tab.o
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
  HOSTLD  scripts/genksyms/genksyms
make: *** [scripts] Error 2
make: *** Waiting for unfinished jobs....
make: *** wait: No child processes.  Stop.
-----------------------------------------------------------------------

What is the expected output? What do you see instead?
I expect compiled kernel Image but I have received error in compile time

What version of the product are you using? On what operating system?
I am trying on X64
$ uname -a
Linux ls3 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 
2014 x86_64 x86_64 x86_64 GNU/Linux

Please provide any additional information below.

I have tried compiling a small C program with the compiler downloaded form 
https://address-sanitizer.googlecode.com/files/gcc-r203101-snapshot.tar.gz

$ gcc --param asan-globals=0 global.c -o global
cc1: error: invalid parameter ‘asan-globals’

I will provide any additional information if required, please give me a hint to 
solve this error.

Thanks in advance

Original issue reported on code.google.com by prasanna...@gmail.com on 12 Jan 2015 at 2:51

GoogleCodeExporter commented 9 years ago
I think ASan wiki are outdated - you can simply use official GCC 4.9.2+, it has 
all the necessary patches.

@Dima: should we update the instructions on obtaining the toolchain on Kasan 
wiki?

Original comment by tetra20...@gmail.com on 12 Jan 2015 at 2:02

GoogleCodeExporter commented 9 years ago
Thanks @tetra20, for quick reply, but it doesn't work :(

$ prasanna.k ~/Ksan/work/linux-kasan-git/kasan $ git pull
Already up-to-date

$ prasanna.k ~/Ksan/work/linux-kasan-git/kasan $ git branch
* asan

prasanna.k ~/gcc-git/gcc/install/bin $ ./gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/prasanna.k/gcc-git/gcc/install/libexec/gcc/x86_64-unkn
own-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++ --disable-bootstrap 
--enable-checking=no --with-gnu-as --with-gnu-ld --with-ld=/usr/bin/ld.bfd 
--prefix=/home/prasanna.k/gcc-git/gcc/install
Thread model: posix
gcc version 5.0.0 20150113 (experimental) (GCC)

$ prasanna.k ~/Ksan/work/linux-kasan-git/kasan $ make 
CC=/home/prasanna.k/gcc-git/gcc/install/bin/gcc -j20
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      scripts/mod/empty.o
  CC      scripts/mod/devicetable-offsets.s
cc1: error: invalid parameter ‘asan-fixed-shadow-offset’
cc1: error: invalid parameter ‘asan-fixed-shadow-offset’
make[2]: *** [scripts/mod/devicetable-offsets.s] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [scripts] Error 2

My Observation:

$ vi Makefile + 386
 386 CFLAGS_KASAN    = -fsanitize=address \
 387             --param asan-use-after-return=0 \
 388             --param asan-globals=0 \
 389             --param asan-memintrin=0 \
 390             --param asan-instrumentation-with-call-threshold=0 \
 391             --param asan-fixed-shadow-offset=0 \
 392             -DKASAN_HOOKS

all the --param options mentioned above in Makefile are added in GCC-5.0 except 
`asan-fixed-shadow-offset`

Additional information:
$ gcc --param asan-use-after-return=0 global.c -o global
compilation successful

$ gcc --param asan-globals=0 global.c -o global
compilation successful

$ gcc --param asan-memintrin=0 global.c -o global
compilation successful

$ gcc --param asan-instrumentation-with-call-threshold=0 global.c -o global 
compilation successful

$ gcc --param asan-fixed-shadow-offset=0 global.c -o global
cc1: error: invalid parameter ‘asan-fixed-shadow-offset’

Sources:
Kernel: https://github.com/google/kasan.git
GCC: https://github.com/gcc-mirror/gcc.git

I'm I missing something??
Any hint will be highly appreciated.
Thanks in advance. 

Original comment by prasanna...@gmail.com on 13 Jan 2015 at 6:16

GoogleCodeExporter commented 9 years ago
'asan' branch is outdated and not supported anymore.

Use the 'kasan' branch. That branch has uptodate documentation which could be 
usefull
https://github.com/google/kasan/blob/kasan/Documentation/kasan.txt

Original comment by Ryabinin...@gmail.com on 13 Jan 2015 at 7:10

GoogleCodeExporter commented 9 years ago
I haven't  noticed this, please update it in wiki.
Many starting users like me are facing problems in setting-up KASAN environment.

Thank you @Ryabinin.. your valuable comment helped and reduced my pain in setup.
Finally the compilation is successful :).

Original comment by prasanna...@gmail.com on 14 Jan 2015 at 6:02

GoogleCodeExporter commented 9 years ago
> I haven't  noticed this, please update it in wiki.

Absolutely, wiki has totally rotten.

Original comment by tetra20...@gmail.com on 14 Jan 2015 at 8:08

GoogleCodeExporter commented 9 years ago
I can update in the evening if noone outpaces me.

Original comment by tetra20...@gmail.com on 14 Jan 2015 at 8:09

GoogleCodeExporter commented 9 years ago
> I can update in the evening if noone outpaces me.

It took me 4 days to do this work with all yours help.
updating wiki will really helpful to many like me :)

Thank you @tetra20 please go ahead..

Original comment by prasanna...@gmail.com on 14 Jan 2015 at 9:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@tetra20 you have done a good job.

But please update everything...

1. write regarding changing the branch 
$ git checkout kasan
2. It is written current KASN supports only SLAB, please change it to SLUB

the below line is outdated
>"You will also need to enable SLAB allocator (General setup > Choose SLAB
>allocator) and AddressSanitizer (Kernel hacking > Memory Debugging) during
>kernel configuration"

can be updated with: 
You will also need to enable SLUB allocator (General setup > Choose SLAB 
allocator (SLUB (Unqueued Allocator)) and AddressSanitizer (Kernel hacking > 
Memory Debugging > AddressSanitizer: runtime memory debugger ) during kernel 
configuration

please update the procedure 
1. CONFIG_KASAN = y
2. choose b/w CONFIG_KASAN_OUTLINE or CONFIG_KASAN_INLINE
3. mention regarding advantages of enabling CONFIG_STACKTRACE and
4. finally testing 'lib/test_kasan.ko'

I think that way is very essential as mentioned in 
https://github.com/google/kasan/blob/kasan/Documentation/kasan.txt

Looking forward for you help and support..
Best regards :)

Original comment by prasanna...@gmail.com on 19 Jan 2015 at 7:24

GoogleCodeExporter commented 9 years ago
Done! Does this look saner?

Original comment by tetra2...@gmail.com on 21 Jan 2015 at 3:24

GoogleCodeExporter commented 9 years ago
Hmmm,

this is much better @tetra20.. :)
Now any one can easily catch-up and use the KASAN.

thanks for your effort in updating this page.

Thanks & Best regards.

Original comment by prasanna...@gmail.com on 21 Jan 2015 at 3:37