[drivers/usb/usbip] BUG: corrupted list in vep_queue

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

 



Dear Linux Developers for USB OVER IP DRIVER,

We encountered "BUG: corrupted list in vep_queue" when testing the
DVB driver with Syzkaller and our generated specifications.

Linux version: Linux 6.12-rc2 (8cf0b93919e13d1e8d4466eb4080a4c4d9d66d7b)
Configuration is attached.
Syz and C reproducers are as below:

```
Syzkaller hit 'BUG: corrupted list in vep_queue' bug.

list_add double add: new=ffff888045090868, prev=ffff888045090868,
next=ffff888045516068.
------------[ cut here ]------------
kernel BUG at lib/list_debug.c:37!
Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN NOPTI
CPU: 1 UID: 0 PID: 10405 Comm: syz-executor379 Not tainted
6.12.0-rc2-g8cf0b93919e1 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
RIP: 0010:__list_add_valid_or_report+0x9f/0xf0 lib/list_debug.c:35
Code: e7 74 11 4d 39 f7 74 0c b0 01 5b 41 5c 41 5d 41 5e 41 5f c3 48
c7 c7 40 d5 51 8d 4c 89 fe 4c 89 e2 4c 89 f1 e8 c2 30 cc 07 90 <0f> 0b
48 c7 c7 40 d3 51 8d e8 b3 30 cc 07 90 0f 0b 48 c7 c7 e0 d3
RSP: 0018:ffffc9000f7efaa0 EFLAGS: 00010046
RAX: 0000000000000058 RBX: ffff888045516070 RCX: 801939ce6b30cb00
RDX: 0000000000000000 RSI: 0000000080000001 RDI: 0000000000000000
RBP: ffff888045516068 R08: ffffffff81792ea1 R09: 1ffff92001efdef8
R10: dffffc0000000000 R11: fffff52001efdef9 R12: ffff888045090868
R13: dffffc0000000000 R14: ffff888045516068 R15: ffff888045090868
FS:  0000555560f373c0(0000) GS:ffff88807ee00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000048 CR3: 00000000500fc000 CR4: 0000000000752ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
 <TASK>
 __list_add_valid include/linux/list.h:88 [inline]
 __list_add include/linux/list.h:150 [inline]
 list_add_tail include/linux/list.h:183 [inline]
 vep_queue+0xde/0x1d0 drivers/usb/usbip/vudc_dev.c:327
 usb_ep_queue+0xa0/0x1c0 drivers/usb/gadget/udc/core.c:300
 uvc_send_response drivers/usb/gadget/function/uvc_v4l2.c:198 [inline]
 uvc_v4l2_ioctl_default+0x239/0x350 drivers/usb/gadget/function/uvc_v4l2.c:569
 __video_do_ioctl+0x850/0xde0 drivers/media/v4l2-core/v4l2-ioctl.c:3123
 video_usercopy+0x8ff/0x11d0 drivers/media/v4l2-core/v4l2-ioctl.c:3460
 v4l2_ioctl+0x18d/0x1e0 drivers/media/v4l2-core/v4l2-dev.c:364
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:907 [inline]
 __se_sys_ioctl+0xfa/0x170 fs/ioctl.c:893
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf9/0x280 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x67/0x6f
RIP: 0033:0x7f34cd76118d
Code: c3 e8 a7 1f 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:00007ffcc5cff928 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000007f91 RCX: 00007f34cd76118d
RDX: 0000000020000240 RSI: 0000000040405501 RDI: 0000000000000003
RBP: 0000000000000000 R08: 00236f656469762f R09: 0000000000000000
R10: 000000000000001f R11: 0000000000000246 R12: 00007ffcc5cff93c
R13: 431bde82d7b634db R14: 00007f34cd7de4f0 R15: 0000000000000001
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:__list_add_valid_or_report+0x9f/0xf0 lib/list_debug.c:35
Code: e7 74 11 4d 39 f7 74 0c b0 01 5b 41 5c 41 5d 41 5e 41 5f c3 48
c7 c7 40 d5 51 8d 4c 89 fe 4c 89 e2 4c 89 f1 e8 c2 30 cc 07 90 <0f> 0b
48 c7 c7 40 d3 51 8d e8 b3 30 cc 07 90 0f 0b 48 c7 c7 e0 d3
RSP: 0018:ffffc9000f7efaa0 EFLAGS: 00010046
RAX: 0000000000000058 RBX: ffff888045516070 RCX: 801939ce6b30cb00
RDX: 0000000000000000 RSI: 0000000080000001 RDI: 0000000000000000
RBP: ffff888045516068 R08: ffffffff81792ea1 R09: 1ffff92001efdef8
R10: dffffc0000000000 R11: fffff52001efdef9 R12: ffff888045090868
R13: dffffc0000000000 R14: ffff888045516068 R15: ffff888045090868
FS:  0000555560f373c0(0000) GS:ffff88807ee00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000048 CR3: 00000000500fc000 CR4: 0000000000752ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400
PKRU: 55555554


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 Repro:false Trace:false LegacyOptions:{Collide:false
Fault:false FaultCall:0 FaultNth:0}}
r0 = syz_open_dev$KGPT_video_syzkalm_dup(&(0x7f0000000040), 0x0, 0x0)
ioctl$KGPT_VIDIOC_OMAP3ISP_CCDC_CFG(r0, 0x40405501,
&(0x7f0000000240)={0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})


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 long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
  if (a0 == 0xc || a0 == 0xb) {
    char buf[128];
    sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
            (uint8_t)a2);
    return open(buf, O_RDWR, 0);
  } else {
    char buf[1024];
    char* hash;
    strncpy(buf, (char*)a0, sizeof(buf) - 1);
    buf[sizeof(buf) - 1] = 0;
    while ((hash = strchr(buf, '#'))) {
      *hash = '0' + (char)(a1 % 10);
      a1 /= 10;
    }
    return open(buf, a2, 0);
  }
}

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 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 (;;) {
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      sleep_ms(1);
      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;
  memcpy((void*)0x20000040, "/dev/video#\000", 12);
  res = -1;
  res = syz_open_dev(/*dev=*/0x20000040, /*id=*/0, /*flags=*/0);
  if (res != -1)
    r[0] = res;
  *(uint16_t*)0x20000240 = 0x11;
  *(uint16_t*)0x20000242 = 0;
  *(uint32_t*)0x20000244 = 0;
  *(uint64_t*)0x20000248 = 0;
  *(uint64_t*)0x20000250 = 0;
  *(uint64_t*)0x20000258 = 0;
  *(uint64_t*)0x20000260 = 0;
  *(uint64_t*)0x20000268 = 0;
  *(uint64_t*)0x20000270 = 0;
  syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40405501, /*arg=*/0x20000240ul);
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  loop();
  return 0;
}
```

The call trace to this issue is kind of complicated: `vfs_ioctl
fs/ioctl.c:51` --> `__video_do_ioctl
drivers/media/v4l2-core/v4l2-ioctl.c ` --> `usb_ep_queue
drivers/usb/gadget/udc/core.c`

It seems that the error stems from an invalid list_add operation where
an element is being added twice. The log shows:
```
list_add double add: new=ffff888045090868, prev=ffff888045090868,
next=ffff888045516068.
```
This implies that the new element (ffff888045090868) is already part
of the list, causing a "double add."

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]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux