Skip to contentSkip to conversation

src/sg/syzkaller1.c: fix portability problem for syscall(__NR_mmap, ...)

PATCH Superseded Theodore Ts'o 2 participants 2 messages Jan 7, 2019 – Jan 9, 2019 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src/sg/syzkaller1.c: fix portability problem for syscall(__NR_mmap, ...)

How mmap is mapped to a raw system call varies across different archiecture. On some architectures (such as 32-bit ARM), __NR_mmap may not exist at all; glibc will use __NR_mmap2 to implement mmap(2). Syzkaller is using mmap() as a non-portable version of malloc(3), so it should be safe to use the glibc's mmap wrapper instead of trying to directly call the system call.

---
 src/sg/syzkaller1.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/sg/syzkaller1.c +4 -2
index 743859a..e254d4a 100644
@@ -401,8 +401,10 @@ long r[15];
 void test()
 {
   memset(r, -1, sizeof(r));
-  r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x5000ul, 0x3ul,
-                         0x32ul, (uintptr_t)(-1ul), 0x0ul, 0, 0, 0);
+//r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x5000ul, 0x3ul,
+//                       0x32ul, (uintptr_t)(-1ul), 0x0ul, 0, 0, 0);
+  r[0] = (long) mmap((void *) 0x20000000, (size_t) 0x5000,
+                     PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS, -1, 0);
   NONFAILING(memcpy((void*)0x20000000,
                     dev_sg, strlen(dev_sg)));
   r[2] = execute_syscall(__NR_syz_open_dev, 0x20000000ul, 0x0ul, 0x2ul,
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Theodore Ts'o

How mmap is mapped to a raw system call varies across different archiecture. On some architectures (such as 32-bit ARM), __NR_mmap

^^^^^^^^^^^
architectures?

Quoted 17 lines

may not exist at all; glibc will use __NR_mmap2 to implement mmap(2). Syzkaller is using mmap() as a non-portable version of malloc(3), so it should be safe to use the glibc's mmap wrapper instead of trying to directly call the system call.

---
  src/sg/syzkaller1.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
src/sg/syzkaller1.c +0 -0
index 743859a..e254d4a 100644
@@ -401,8 +401,10 @@ long r[15];
  void test()
  {

src/sg/syzkaller1.c long r[15]; · line 410

Quoted 10 lines
src/sg/syzkaller1.c +4 -2
    memset(r, -1, sizeof(r));
-  r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x5000ul, 0x3ul,
-                         0x32ul, (uintptr_t)(-1ul), 0x0ul, 0, 0, 0);
+//r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0x5000ul, 0x3ul,
+//                       0x32ul, (uintptr_t)(-1ul), 0x0ul, 0, 0, 0);
+  r[0] = (long) mmap((void *) 0x20000000, (size_t) 0x5000,
+                     PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS, -1, 0);
    NONFAILING(memcpy((void*)0x20000000,
                      dev_sg, strlen(dev_sg)));
    r[2] = execute_syscall(__NR_syz_open_dev, 0x20000000ul, 0x0ul, 0x2ul,

Anyway: