[drivers/md/dm.c] general protection fault in cleanup_mapped_device

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

 



Dear Linux Developers for Device Mapper,

We encountered "general protection fault in cleanup_mapped_device"
when testing the
device mapper driver with Syzkaller and our generated specifications.

Linux version: Linux 6.11-rc7 (da3ea35007d0af457a0afc87e84fddaebc4e0b63)
Configuration is attached.
Syz and C reproducers are as below:

```
Syzkaller hit 'general protection fault in cleanup_mapped_device' bug.

RBP: 00007ffdd7f7e1b0 R08: 0000000000000000 R09: 00007fe4862ebd75
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000004
R13: 431bde82d7b634db R14: 00007fe486313470 R15: 0000000000000001
 </TASK>
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000011: 0000 [#1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000088-0x000000000000008f]
CPU: 0 UID: 0 PID: 8387 Comm: syz-executor123 Not tainted
6.11.0-rc7-gda3ea35007d0 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
RIP: 0010:cleanup_mapped_device+0x202/0x580 drivers/md/dm.c:2198
Code: 03 80 3c 02 00 0f 85 28 03 00 00 48 8b 9d 08 02 00 00 48 b8 00
00 00 00 00 fc ff df 48 8d bb 98 00 00 00 48 89 fa 48 c1 ea 03 <80> 3c
02 00 0f 85 19 03 00 00 48 c7 c7 00 57 39 8f 48 c7 83 98 00
RSP: 0018:ffffc9000e5f7b80 EFLAGS: 00010217
RAX: dffffc0000000000 RBX: fffffffffffffff4 RCX: ffffffff8169176c
RDX: 0000000000000011 RSI: 0000000000000004 RDI: 000000000000008c
RBP: ffff888047717000 R08: 0000000000000001 R09: fffff52001cbef62
R10: 0000000000000003 R11: 0000000000000000 R12: ffff888047717208
R13: ffff888047717090 R14: ffff888047717208 R15: ffff88802ba3d9e8
FS:  00005555642a83c0(0000) GS:ffff88802ba00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe48631f1f8 CR3: 0000000000c22000 CR4: 0000000000750ef0
PKRU: 55555554
Call Trace:
 <TASK>
 alloc_dev drivers/md/dm.c:2347 [inline]
 dm_create+0xf35/0x15b0 drivers/md/dm.c:2489
 dev_create+0x11f/0x2a0 drivers/md/dm-ioctl.c:891
 ctl_ioctl+0x6cd/0xab0 drivers/md/dm-ioctl.c:2100
 dm_ctl_ioctl+0x25/0x40 drivers/md/dm-ioctl.c:2122
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:907 [inline]
 __se_sys_ioctl fs/ioctl.c:893 [inline]
 __x64_sys_ioctl+0x1a4/0x210 fs/ioctl.c:893
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcb/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe48629574d
Code: c3 e8 97 21 00 00 0f 1f 80 00 00 00 00 f3 0f 1e fa 48 89 f8 48
89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d
01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffdd7f7e178 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fe48629574d
RDX: 0000000020000080 RSI: 00000000c138fd03 RDI: 0000000000000003
RBP: 00007ffdd7f7e1b0 R08: 0000000000000000 R09: 00007fe4862ebd75
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000004
R13: 431bde82d7b634db R14: 00007fe486313470 R15: 0000000000000001
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:cleanup_mapped_device+0x202/0x580 drivers/md/dm.c:2198
Code: 03 80 3c 02 00 0f 85 28 03 00 00 48 8b 9d 08 02 00 00 48 b8 00
00 00 00 00 fc ff df 48 8d bb 98 00 00 00 48 89 fa 48 c1 ea 03 <80> 3c
02 00 0f 85 19 03 00 00 48 c7 c7 00 57 39 8f 48 c7 83 98 00
RSP: 0018:ffffc9000e5f7b80 EFLAGS: 00010217
RAX: dffffc0000000000 RBX: fffffffffffffff4 RCX: ffffffff8169176c
RDX: 0000000000000011 RSI: 0000000000000004 RDI: 000000000000008c
RBP: ffff888047717000 R08: 0000000000000001 R09: fffff52001cbef62
R10: 0000000000000003 R11: 0000000000000000 R12: ffff888047717208
R13: ffff888047717090 R14: ffff888047717208 R15: ffff88802ba3d9e8
FS:  00005555642a83c0(0000) GS:ffff88802ba00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe48631f1f8 CR3: 0000000000c22000 CR4: 0000000000750ef0
PKRU: 55555554
----------------
Code disassembly (best guess):
   0: 03 80 3c 02 00 0f     add    0xf00023c(%rax),%eax
   6: 85 28                 test   %ebp,(%rax)
   8: 03 00                 add    (%rax),%eax
   a: 00 48 8b             add    %cl,-0x75(%rax)
   d: 9d                   popf
   e: 08 02                 or     %al,(%rdx)
  10: 00 00                 add    %al,(%rax)
  12: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax
  19: fc ff df
  1c: 48 8d bb 98 00 00 00 lea    0x98(%rbx),%rdi
  23: 48 89 fa             mov    %rdi,%rdx
  26: 48 c1 ea 03           shr    $0x3,%rdx
* 2a: 80 3c 02 00           cmpb   $0x0,(%rdx,%rax,1) <-- trapping instruction
  2e: 0f 85 19 03 00 00     jne    0x34d
  34: 48 c7 c7 00 57 39 8f mov    $0xffffffff8f395700,%rdi
  3b: 48                   rex.W
  3c: c7                   .byte 0xc7
  3d: 83                   .byte 0x83
  3e: 98                   cwtl


Syzkaller reproducer:
# {Threaded:false Repeat:true RepeatTimes:0 Procs:1 Slowdown:1
Sandbox: SandboxArg:0 Leak:false NetInjection:false NetDevices:false
NetReset:false Cgroups:false BinfmtMisc:false CloseFDs:false
KCSAN:false DevlinkPCI:false NicVF:false USB:false VhciInjection:false
Wifi:false IEEE802154:false Sysctl:false Swap:false UseTmpDir:false
HandleSegv:false Trace:false LegacyOptions:{Collide:false Fault:false
FaultCall:0 FaultNth:0}}
ioctl$KGPT_CEC_ADAP_S_LOG_ADDRS(0xffffffffffffffff, 0xc05c6104,
&(0x7f0000000080)={"8072609d", 0x4, 0x6, 0x8, 0xffff, 0x6,
"000780427bee50eb00", '\x00\a\x00', "8529b501", "3bf5c9d5",
["f1c758509a071a2ded4470ab", "fe1285a1e9c9879d543c15d2",
"d6de4e2d5ae55cebb6bac1e1", "dd8866305b4f75e67daa6d8b"]})
r0 = openat$KGPT_SYZKALM_dm_ctl(0xffffffffffffff9c, &(0x7f0000000040), 0x2, 0x0)
ioctl$KGPT_DM_DEV_STATUS(r0, 0xc138fd07,
&(0x7f0000000080)="58c18237165e55872d5dacbed6a0")
ioctl$KGPT_DM_DEV_CREATE(r0, 0xc138fd03, &(0x7f0000000080)) (fail_nth: 8)


C reproducer:
// autogenerated by syzkaller (https://github.com/google/syzkaller)

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

static void sleep_ms(uint64_t ms)
{
  usleep(ms * 1000);
}

static uint64_t current_time_ms(void)
{
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts))
    exit(1);
  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}

static bool write_file(const char* file, const char* what, ...)
{
  char buf[1024];
  va_list args;
  va_start(args, what);
  vsnprintf(buf, sizeof(buf), what, args);
  va_end(args);
  buf[sizeof(buf) - 1] = 0;
  int len = strlen(buf);
  int fd = open(file, O_WRONLY | O_CLOEXEC);
  if (fd == -1)
    return false;
  if (write(fd, buf, len) != len) {
    int err = errno;
    close(fd);
    errno = err;
    return false;
  }
  close(fd);
  return true;
}

static int inject_fault(int nth)
{
  int fd;
  fd = open("/proc/thread-self/fail-nth", O_RDWR);
  if (fd == -1)
    exit(1);
  char buf[16];
  sprintf(buf, "%d", nth);
  if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
    exit(1);
  return fd;
}

static void kill_and_wait(int pid, int* status)
{
  kill(-pid, SIGKILL);
  kill(pid, SIGKILL);
  for (int i = 0; i < 100; i++) {
    if (waitpid(-1, status, WNOHANG | __WALL) == pid)
      return;
    usleep(1000);
  }
  DIR* dir = opendir("/sys/fs/fuse/connections");
  if (dir) {
    for (;;) {
      struct dirent* ent = readdir(dir);
      if (!ent)
        break;
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        continue;
      char abort[300];
      snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
               ent->d_name);
      int fd = open(abort, O_WRONLY);
      if (fd == -1) {
        continue;
      }
      if (write(fd, abort, 1) < 0) {
      }
      close(fd);
    }
    closedir(dir);
  } else {
  }
  while (waitpid(-1, status, __WALL) != pid) {
  }
}

static void setup_test()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setpgrp();
  write_file("/proc/self/oom_score_adj", "1000");
}

static const char* setup_fault()
{
  int fd = open("/proc/self/make-it-fail", O_WRONLY);
  if (fd == -1)
    return "CONFIG_FAULT_INJECTION is not enabled";
  close(fd);
  fd = open("/proc/thread-self/fail-nth", O_WRONLY);
  if (fd == -1)
    return "kernel does not have systematic fault injection support";
  close(fd);
  static struct {
    const char* file;
    const char* val;
    bool fatal;
  } files[] = {
      {"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true},
      {"/sys/kernel/debug/fail_futex/ignore-private", "N", false},
      {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false},
      {"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false},
      {"/sys/kernel/debug/fail_page_alloc/min-order", "0", false},
  };
  unsigned i;
  for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
    if (!write_file(files[i].file, files[i].val)) {
      if (files[i].fatal)
        return "failed to write fault injection file";
    }
  }
  return NULL;
}

static void execute_one(void);

#define WAIT_FLAGS __WALL

static void loop(void)
{
  int iter = 0;
  for (;; iter++) {
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      setup_test();
      execute_one();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      sleep_ms(10);
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      if (current_time_ms() - start < 5000)
        continue;
      kill_and_wait(pid, &status);
      break;
    }
  }
}

uint64_t r[1] = {0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  }
  memcpy((void*)0x20000080, "\x80\x72\x60\x9d", 4);
  *(uint16_t*)0x20000084 = 4;
  *(uint8_t*)0x20000086 = 6;
  *(uint8_t*)0x20000087 = 8;
  *(uint32_t*)0x20000088 = 0xffff;
  *(uint32_t*)0x2000008c = 6;
  memcpy((void*)0x20000090,
         "\x00\x07\x80\x42\x7b\xee\x50\xeb\x00\x00\x00\x00\x00\x00\x00", 15);
  memcpy((void*)0x2000009f, "\000\a\000\000", 4);
  memcpy((void*)0x200000a3, "\x85\x29\xb5\x01", 4);
  memcpy((void*)0x200000a7, "\x3b\xf5\xc9\xd5", 4);
  memcpy((void*)0x200000ab, "\xf1\xc7\x58\x50\x9a\x07\x1a\x2d\xed\x44\x70\xab",
         12);
  memcpy((void*)0x200000b7, "\xfe\x12\x85\xa1\xe9\xc9\x87\x9d\x54\x3c\x15\xd2",
         12);
  memcpy((void*)0x200000c3, "\xd6\xde\x4e\x2d\x5a\xe5\x5c\xeb\xb6\xba\xc1\xe1",
         12);
  memcpy((void*)0x200000cf, "\xdd\x88\x66\x30\x5b\x4f\x75\xe6\x7d\xaa\x6d\x8b",
         12);
  syscall(__NR_ioctl, /*fd=*/-1, /*cmd=*/0xc05c6104, /*arg=*/0x20000080ul);
  memcpy((void*)0x20000040, "/dev/mapper/control\000", 20);
  res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x20000040ul,
                /*flags=*/2ul, /*mode=*/0ul);
  if (res != -1)
    r[0] = res;
  memcpy((void*)0x20000080,
         "\x58\xc1\x82\x37\x16\x5e\x55\x87\x2d\x5d\xac\xbe\xd6\xa0", 14);
  syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd07, /*arg=*/0x20000080ul);
  inject_fault(8);
  syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc138fd03, /*arg=*/0x20000080ul);
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul,
          /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  const char* reason;
  (void)reason;
  if ((reason = setup_fault()))
    printf("the reproducer may not work as expected: fault injection setup "
           "failed: %s\n",
           reason);
  loop();
  return 0;
}
```

If you have any questions or require more information, please feel
free to contact us.

Reported-by: Chenyuan Yang <chenyuan0y@xxxxxxxxx>

Best,
Chenyuan

Attachment: config
Description: Binary data


[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux