qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] linux-user/syscall: Silence warning from the undefined behav


From: Thomas Huth
Subject: Re: [PATCH] linux-user/syscall: Silence warning from the undefined behavior sanitizer
Date: Fri, 12 Feb 2021 08:56:35 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

On 12/02/2021 01.35, Laurent Vivier wrote:
Le 11/02/2021 à 22:28, Laurent Vivier a écrit :
Le 11/02/2021 à 14:29, Thomas Huth a écrit :
When compiling QEMU with -fsanitize=undefined, there is a warning when
running "make check-tcg":

   TEST    linux-test on m68k
../linux-user/syscall.c:10499:34: runtime error: member access within
  misaligned address 0x00008006df3c for type 'struct linux_dirent64',
  which requires 8 byte alignment
0x00008006df3c: note: pointer points here
   00 00 00 00 68 03 28 00  00 00 00 00 5b 96 3e e4  61 4b 05 26 18 00 04 2e  
00 00 00 00 da 3f 18 00
               ^

It's likely not an issue in reality, since I assume that on hosts where
the alignment really matters (like sparc64), the Linux kernel likely
adds the right padding. Anyway, let's use the stw_p() / stq_p() accessor
helpers here to silence the warning and thus to allow to compile the code
with -fsanitize=undefined, too.

Wait... if the alignment differs between m68k and the host, I guess the size of 
the structure differs?

No, as far as I understand, the size and layout of the structure are the same on all architecture. The problem is that the "dirp = lock_user(VERIFY_WRITE, arg2, count, 0)" already ends up in a pointer that is only aligned to a 4-byte boundary. Since the m68k code is only restricted to a 4-byte alignment, arg2 is only aligned to 4 bytes. But if the host needs 8-byte alignment for the struct, we've certainly lost here.

Having said that, I think my patch is still wrong. It silences the ubsan warnings, but it won't fix the problem when the code is e.g. running on a sparc64 host. There we likely need to make sure that the buffer on the host is already aligned to an 8-byte boundary when doing the sys_getdents64() call to the host kernel.
So I guess we need a bounce buffer here anyway?

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]