<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/114641>114641</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            MSAN: Memory initialization from `syscall` is not supported
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          pkillarjun
      </td>
    </tr>
</table>

<pre>
    ### Built environment

```bash
$ clang -v
clang version 18.1.8 (Fedora 18.1.8-1.fc40)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg
System configuration file directory: /etc/clang/
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/14
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/14
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

$ ldd --version
ldd (GNU libc) 2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

$ uname -a
Linux fedora 6.11.4-201.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 20 15:04:22 UTC 2024 x86_64 GNU/Linux
```

### test code

```c
/* msan_syscall.c */

#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>

int main(void)
{
    int ret;
    char seed[16];

    ret = syscall(SYS_getrandom, seed, sizeof(seed), 0);
    if (ret == -1)
        return 1;

    /* Why this crash? */
    for (int i = 0; i < 16; i++) {
        printf("%02x ", seed[i]);
    }
    printf("\n");

    return 0;
}
```

### compile and run

```bash
$ clang -fsanitize=memory msan_syscall.c -o msan_syscall

$ ./msan_syscall 
==34754==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4c85fb in main (/home/down/Desktop/msan_syscall+0x4c85fb) (BuildId: 1c5b4d60c70579fa8bf0feecc8b63432c00c4e68)
    #1 0x7f1cddafe087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
    #2 0x7f1cddafe14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
    #3 0x430304 in _start (/home/down/Desktop/msan_syscall+0x430304) (BuildId: 1c5b4d60c70579fa8bf0feecc8b63432c00c4e68)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/down/Desktop/msan_syscall+0x4c85fb) (BuildId: 1c5b4d60c70579fa8bf0feecc8b63432c00c4e68) in main
```

### gdb

```c
Breakpoint 1, main () at msan_syscall.c:9
9           int ret;
(gdb) c
Continuing.

Breakpoint 2, main () at msan_syscall.c:12
12          ret = syscall(SYS_getrandom, seed, sizeof(seed), 0);
(gdb) p seed
$5 = '\000' <repeats 15 times>
(gdb) c
Continuing.

Breakpoint 3, main () at msan_syscall.c:17
17          for (int i = 0; i < 16; i++) {
(gdb) p seed
$6 = "\225\245\357\234\361\035\020|\271\217q\246Ò\245", <incomplete sequence \351>
```

Ping @vitalybuka

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV19v27oO_zTKCxFDfxzbechD4tS9AdauaFoMewpkmU505sg5stw1-_QXsp2mzbqd7WIXJwhshaTIHymKZGTT6K1BnJHJgkyWI9m6XW1nhy-6qqT9qzWjvC6OM8JF_4VFqysHaJ60rc0ejSN0Seh8eEa0_-ay2Q0kHoKqpNnC-Kmn9L-e0Da6NsCSgAUJEJ5kWNRWDoQxC0oVUsKn_aYHabfoiJjDcxJtonBssdhJN660aZ_HW9MOYjuLsoB9XWDlhQ91o5971so0TlYVFkttPYvwrG0s4VmuTS-R1qbU29ZK54GVusJBDp0iPOtwE579AMC44weq3Pba1sfG4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