tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common
On Wed, May 23, 2018 at 11:14:50AM +0000, Kamil Rytarowski wrote:
> Module Name: src
> Committed By: kamil
> Date: Wed May 23 11:14:49 UTC 2018
>
> Modified Files:
> src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common:
> sanitizer_linux.cc
>
> Log Message:
> Cherry-pick upstream patch for internal_mmap() in GCC sanitizers
>
> Fix internal_mmap() on 32-bit NetBSD platforms
>
> There is need to use internal_syscall64() instead of internal_syscall_ptr().
> The offset argument of type off_t is always 64-bit.
>
> http://llvm.org/viewvc/llvm-project?view=revision&revision=333075
Sorry to be such a bother, but this change is broken.
It breaks sanitizers completely on sparc, for one the return value
handling is missing, but also the argument handling is broken (need to
investigate that more closely).
It breaks santizer on sparc (or every 32bit big endian architecture that uses
register pairs to return 64bit values).
On sparc you have to convert the 64bit value specially for this case.
Maybe we should provide MD macros to help with that?
Like:
#define __SYSCALL_TO_UINPTRT(V) ((uintptr_t)(V))
and on sparc it would be:
#define __SYSCALL_TO_UINPTRT(V) ((uintptr_t)((V)>>32))
But testint this with a simple program makes mmap fail when invoked via
__syscall still:
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
#define __SYSCALL_TO_UINPTRT(V) ((uintptr_t)((V)>>32))
int main() {
FILE *f = tmpfile();
int *m = (int*)__SYSCALL_TO_UINPTRT(__syscall(SYS_mmap, 0, 4, PROT_WRITE, MAP_PRIVATE, fileno(f), 0));
int *m1 = mmap(0, 4, PROT_WRITE, MAP_PRIVATE, fileno(f), 0);
printf("pointer return by __syscall: %p\n", m);
printf("pointer return by mmap: %p\n", m1);
*m = 0;
return 0;
}
output is:
> ./a.out
pointer return by __syscall: 0xffffffff
pointer return by mmap: 0xedc00000
Bus error (core dumped)
and ktrace shows thes two mmap calls:
10271 1 a.out CALL mmap(0,4,PROT_WRITE,0x2<PRIVATE,,,>,3,0,0xedef2f98,0xedef2dc8)
10271 1 a.out RET mmap -1 errno 22 Invalid argument
10271 1 a.out CALL mmap(0,4,PROT_WRITE,0x2<PRIVATE,,,>,3,0,0,0)
10271 1 a.out RET mmap -306184192/0xedc00000
so there are even more bugs :-/
Martin
Martin
Home |
Main Index |
Thread Index |
Old Index