Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: gcc 5.3 version of libasan is broken



On Jun 7, 10:49pm, rokuyama%rk.phys.keio.ac.jp@localhost (Rin Okuyama) wrote:
-- Subject: Re: gcc 5.3 version of libasan is broken

| On 2016/06/07 8:58, Christos Zoulas wrote:
| > This is what I was thinking. Perhaps it is easier to use syscall for ILP32
| > and __syscall for LP64. But then there is lseek...
| 
| Yes. And it fails for LP64BE. I made the revised patch, where 3 kinds of
| internal_syscall macros are provided for different types of retval:
| 
|    - internal_syscall     for 32-bit length (int, pid_t)
|    - internal_syscall64   for 64-bit length (off_t)
|    - internal_syscall_ptr for pointer and (s)size_t
| 
| This seems a little messy, but it is a reliable and simple solution for
| sharing codes between ILP32 and LP64 / LE and BE. I tested that libasan
| works just fine for amd64, i386, and earmv7hf-eb; it detects a buffer
| overflow like this:
| 
|    #include <stdlib.h>
|    #include <string.h>
|    int main()
|    {
|      char *dest, *from = "123";
| 
|      dest = malloc(3);
|      strcpy(dest, from);
|      return 0;
|    }
| 
| I also checked libubsan on amd64, i386, and earmv7hf-eb. It can detect
| an undefined operation like this:
| 
|    int main()
|    {
|      int i = 1, j = 0;
|      return i / j;
|    }
| 
| I expect that it maybe works also for LP64BE though I could not test.
| 
| On 2016/06/07 8:57, Christos Zoulas wrote:
| > Are you sure this works for 64 bit? I am worried about the (long)0, padding.
| 
| Yes. I checked. The padding for mmap(2) is long:
| https://nxr.netbsd.org/source/xref/src/sys/sys/syscallargs.h#1215
| 
| I also checked and reorganized arguments for other syscalls in the
| attached patch.
| 
| I did not test on GCC 5.4. But I suppose that it should work because
| no syscall-related changes were made for libsanitizer.

I think it is better to do what linux does and write an internal_syscall()
macro that just DTRT's instead of special-casing each syscall.

christos


Home | Main Index | Thread Index | Old Index