mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* WARNING in free_event
@ 2024-08-05  2:18 Ubisectech Sirius
  2024-08-06  8:04 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Ubisectech Sirius @ 2024-08-05  2:18 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel; +Cc: peterz, mingo, acme, namhyung

[-- Attachment #1: Type: text/plain, Size: 2885 bytes --]


Hello.
We are Ubisectech Sirius Team, the vulnerability lab of China ValiantSec. Recently, our team has discovered a issue in Linux kernel 6.8. Attached to the email were a PoC file of the issue.

Stack dump:

------------[ cut here ]------------
unexpected event refcount: 2; ptr=ffff888019589820
WARNING: CPU: 0 PID: 13593 at kernel/events/core.c:5254 free_event+0xa3/0xc0 kernel/events/core.c:5254
Modules linked in:
CPU: 0 PID: 13593 Comm: syz.3.346 Not tainted 6.8.0 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
RIP: 0010:free_event+0xa3/0xc0 kernel/events/core.c:5254
Code: b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 75 25 48 8b b5 38 02 00 00 48 89 ea 48 c7 c7 00 03 d7 8a e8 3e a9 9a ff 90 <0f> 0b 90 90 5d 41 5c 41 5d e9 bf ed d5 ff 4c 89 ef e8 77 b1 2d 00
RSP: 0018:ffffc90001b379c8 EFLAGS: 00010286
RAX: 0000000000000000 RBX: dffffc0000000000 RCX: ffffffff814f699a
RDX: ffff88801e7b4980 RSI: ffffffff814f69a7 RDI: 0000000000000001
RBP: ffff888019589820 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000002
R13: ffff888019589a58 R14: ffff888019589b00 R15: ffff888019589820
FS:  0000000000000000(0000) GS:ffff88802c600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f507464c360 CR3: 0000000053fa4000 CR4: 0000000000750ef0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
PKRU: 55555554
Call Trace:
 <TASK>
 perf_event_release_kernel+0x5d4/0x8f0 kernel/events/core.c:5421
 perf_release+0x37/0x50 kernel/events/core.c:5442
 __fput+0x282/0xbc0 fs/file_table.c:376
 task_work_run+0x16a/0x260 kernel/task_work.c:180
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xaf0/0x2a40 kernel/exit.c:871
 do_group_exit+0xd4/0x2a0 kernel/exit.c:1020
 get_signal+0x2440/0x2630 kernel/signal.c:2893
 arch_do_signal_or_restart+0x81/0x7e0 arch/x86/kernel/signal.c:310
 exit_to_user_mode_loop kernel/entry/common.c:105 [inline]
 exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
 irqentry_exit_to_user_mode+0x13c/0x280 kernel/entry/common.c:225
 exc_page_fault+0xc6/0x180 arch/x86/mm/fault.c:1557
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570
RIP: 0033:0x7fd5ec9958d5
Code: Unable to access opcode bytes at 0x7fd5ec9958ab.
RSP: 002b:0000000000000050 EFLAGS: 00010217
RAX: 0000000000000000 RBX: 00007fd5ecb33f60 RCX: 00007fd5ec9958cd
RDX: 0000000000000000 RSI: 0000000000000050 RDI: 0000000000000280
RBP: 00007fd5eca1bb06 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 000000000000000b R14: 00007fd5ecb33f60 R15: 00007fd5ed77a000
 </TASK>


Thank you for taking the time to read this email and we look forward to working with you further.






[-- Attachment #2: poc.c --]
[-- Type: application/octet-stream, Size: 7468 bytes --]

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

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.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;
}

#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len)               \
  *(type*)(addr) =                                                             \
      htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) |           \
            (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))

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 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");
}

#define USLEEP_FORKED_CHILD (3 * 50 * 1000)

static long handle_clone_ret(long ret)
{
  if (ret != 0) {
    return ret;
  }
  usleep(USLEEP_FORKED_CHILD);
  syscall(__NR_exit, 0);
  while (1) {
  }
}

static long syz_clone(volatile long flags, volatile long stack,
                      volatile long stack_len, volatile long ptid,
                      volatile long ctid, volatile long tls)
{
  long sp = (stack + stack_len) & ~15;
  long ret = (long)syscall(__NR_clone, flags & ~CLONE_VM, sp, ptid, ctid, tls);
  return handle_clone_ret(ret);
}

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;
    }
  }
}

void execute_one(void)
{
  if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  }
  *(uint32_t*)0x200000c0 = 0;
  *(uint32_t*)0x200000c4 = 0x80;
  *(uint8_t*)0x200000c8 = 1;
  *(uint8_t*)0x200000c9 = 0;
  *(uint8_t*)0x200000ca = 0;
  *(uint8_t*)0x200000cb = 0;
  *(uint32_t*)0x200000cc = 0;
  *(uint64_t*)0x200000d0 = 0xffff;
  *(uint64_t*)0x200000d8 = 0x8004;
  *(uint64_t*)0x200000e0 = 2;
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 0, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 1, 1, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 2, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 3, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 4, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 5, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 6, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 7, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 8, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 9, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 10, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 11, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 12, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 13, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 14, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 15, 2);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 17, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 18, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 19, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 20, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 21, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 22, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 23, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 24, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 25, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 26, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 27, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 28, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 29, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 30, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 31, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 32, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 33, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 34, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 35, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 1, 36, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 1, 37, 1);
  STORE_BY_BITMASK(uint64_t, , 0x200000e8, 0, 38, 26);
  *(uint32_t*)0x200000f0 = 0;
  *(uint32_t*)0x200000f4 = 0;
  *(uint64_t*)0x200000f8 = 0;
  *(uint64_t*)0x20000100 = 0;
  *(uint64_t*)0x20000108 = 0;
  *(uint64_t*)0x20000110 = 0;
  *(uint32_t*)0x20000118 = 0;
  *(uint32_t*)0x2000011c = 0;
  *(uint64_t*)0x20000120 = 0;
  *(uint32_t*)0x20000128 = 0;
  *(uint16_t*)0x2000012c = 0;
  *(uint16_t*)0x2000012e = 0;
  *(uint32_t*)0x20000130 = 0;
  *(uint32_t*)0x20000134 = 0;
  *(uint64_t*)0x20000138 = 0;
  syscall(__NR_perf_event_open, /*attr=*/0x200000c0ul, /*pid=*/0, /*cpu=*/0ul,
          /*group=*/-1, /*flags=*/0ul);
  syz_clone(/*flags=CLONE_NEWTIME|CLONE_FS*/ 0x280, /*stack=*/0,
            /*stack_len=*/0x54, /*parentid=*/0, /*childtid=*/0, /*tls=*/0);
}
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;
  loop();
  return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: WARNING in free_event
  2024-08-05  2:18 WARNING in free_event Ubisectech Sirius
@ 2024-08-06  8:04 ` Peter Zijlstra
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2024-08-06  8:04 UTC (permalink / raw)
  To: Ubisectech Sirius; +Cc: linux-trace-kernel, linux-kernel, mingo, acme, namhyung

On Mon, Aug 05, 2024 at 10:18:00AM +0800, Ubisectech Sirius wrote:
> 
> Hello.
> We are Ubisectech Sirius Team, the vulnerability lab of China
> ValiantSec. Recently, our team has discovered a issue in Linux kernel
> 6.8. Attached to the email were a PoC file of the issue.
> 

I could not readily reproduce on a current kernel. Please double check
against the latest kernel.

> Stack dump:
> 
> ------------[ cut here ]------------
> unexpected event refcount: 2; ptr=ffff888019589820
> WARNING: CPU: 0 PID: 13593 at kernel/events/core.c:5254 free_event+0xa3/0xc0 kernel/events/core.c:5254
> Modules linked in:
> CPU: 0 PID: 13593 Comm: syz.3.346 Not tainted 6.8.0 #1
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
> RIP: 0010:free_event+0xa3/0xc0 kernel/events/core.c:5254
> Code: b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 75 25 48 8b b5 38 02 00 00 48 89 ea 48 c7 c7 00 03 d7 8a e8 3e a9 9a ff 90 <0f> 0b 90 90 5d 41 5c 41 5d e9 bf ed d5 ff 4c 89 ef e8 77 b1 2d 00
> RSP: 0018:ffffc90001b379c8 EFLAGS: 00010286
> RAX: 0000000000000000 RBX: dffffc0000000000 RCX: ffffffff814f699a
> RDX: ffff88801e7b4980 RSI: ffffffff814f69a7 RDI: 0000000000000001
> RBP: ffff888019589820 R08: 0000000000000001 R09: 0000000000000000
> R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000002
> R13: ffff888019589a58 R14: ffff888019589b00 R15: ffff888019589820
> FS:  0000000000000000(0000) GS:ffff88802c600000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f507464c360 CR3: 0000000053fa4000 CR4: 0000000000750ef0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> PKRU: 55555554
> Call Trace:
>  <TASK>
>  perf_event_release_kernel+0x5d4/0x8f0 kernel/events/core.c:5421
>  perf_release+0x37/0x50 kernel/events/core.c:5442
>  __fput+0x282/0xbc0 fs/file_table.c:376
>  task_work_run+0x16a/0x260 kernel/task_work.c:180
>  exit_task_work include/linux/task_work.h:38 [inline]
>  do_exit+0xaf0/0x2a40 kernel/exit.c:871
>  do_group_exit+0xd4/0x2a0 kernel/exit.c:1020
>  get_signal+0x2440/0x2630 kernel/signal.c:2893
>  arch_do_signal_or_restart+0x81/0x7e0 arch/x86/kernel/signal.c:310
>  exit_to_user_mode_loop kernel/entry/common.c:105 [inline]
>  exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
>  irqentry_exit_to_user_mode+0x13c/0x280 kernel/entry/common.c:225
>  exc_page_fault+0xc6/0x180 arch/x86/mm/fault.c:1557
>  asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:570
> RIP: 0033:0x7fd5ec9958d5
> Code: Unable to access opcode bytes at 0x7fd5ec9958ab.
> RSP: 002b:0000000000000050 EFLAGS: 00010217
> RAX: 0000000000000000 RBX: 00007fd5ecb33f60 RCX: 00007fd5ec9958cd
> RDX: 0000000000000000 RSI: 0000000000000050 RDI: 0000000000000280
> RBP: 00007fd5eca1bb06 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
> R13: 000000000000000b R14: 00007fd5ecb33f60 R15: 00007fd5ed77a000
>  </TASK>
> 
> 
> Thank you for taking the time to read this email and we look forward to working with you further.
> 
> 
> 
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: WARNING in free_event
       [not found] <CAKHoSAufhtBjD_CgSXY1SOxqkAcY9n1gEwixiK-bL=Ktf7dtDA@mail.gmail.com>
@ 2024-03-11 17:31 ` Ian Rogers
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2024-03-11 17:31 UTC (permalink / raw)
  To: cheung wall
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, linux-kernel, linux-perf-users, Mark Rutland,
	Alexander Shishkin, Adrian Hunter, Jiri Olsa

On Mon, Mar 11, 2024 at 9:38 AM cheung wall <zzqq0103.hey@gmail.com> wrote:
>
> Hello,
>
>
>
> when using Healer to fuzz the latest Linux Kernel, the following crash
>
> was triggered on:
>
>
>
> HEAD commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72  (tag: v6.8-rc7)
>
> git tree: upstream
>
> console output: https://drive.google.com/file/d/17rMhBgYu1sr1d8fiFPS2cPQ60VNJv8H_/view?usp=drive_link
>
> kernel config: https://drive.google.com/file/d/19VXB1YKwoBFpzjqTmm02jVi4-N9tNIvm/view?usp=drive_link
>
> C reproducer: https://drive.google.com/file/d/1fC55GmW0di5HgxQWhrf6Vj1EA2LXsaNJ/view?usp=drive_link
>
> Syzlang reproducer: https://drive.google.com/file/d/1uTbMUGRUK4kLiJHyK5dD2-_beUqx4V55/view?usp=drive_link
>
>
>
> If you fix this issue, please add the following tag to the commit:
>
> Reported-by: Qiang Zhang <zzqq0103.hey@gmail.com>
>
> ----------------------------------------------------------
>
>
> WARNING: CPU: 4 PID: 817954 at kernel/events/core.c:5254 free_event+0x8b/0xb0 kernel/events/core.c:5254
> Modules linked in:
> CPU: 4 PID: 817954 Comm: syz-executor.1 Not tainted 6.8.0-rc7 #1
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
> RIP: 0010:free_event+0x8b/0xb0 kernel/events/core.c:5254
> Code: b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 75 23 48 8b b5 38 02 00 00 48 89 ea 48 c7 c7 00 5d cd 8e e8 86 2e c3 ff 90 <0f> 0b 90 90 5d 41 5c e9 69 aa ef ff 4c 89 e7 e8 21 73 1c 00 eb d3
> RSP: 0018:ffff88811864fd78 EFLAGS: 00010282
> RAX: 0000000000000000 RBX: 1ffff110230c9fbd RCX: ffffffff8bd1ba08
> RDX: 0000000000000000 RSI: 0000000000000008 RDI: ffff88811864fb70
> RBP: ffff88810e94f2d8 R08: 0000000000000001 R09: ffffed10230c9f6f
> R10: ffffed10230c9f6e R11: ffff88811864fb77 R12: ffff88810e94f510
> R13: ffff8881046744e8 R14: ffff88812ee40768 R15: ffff88812ee40000
> FS:  00007fc2f7eb0700(0000) GS:ffff8881c0200000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007ffca566ae18 CR3: 0000000164ee6001 CR4: 0000000000770ef0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000600
> PKRU: 55555554
> Call Trace:
>  <TASK>
>  __do_sys_perf_event_open+0x4fd/0x1d50 kernel/events/core.c:12803
>  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>  do_syscall_64+0xb4/0x1b0 arch/x86/entry/common.c:83
>  entry_SYSCALL_64_after_hwframe+0x6f/0x77
> RIP: 0033:0x7fc2f8b62c8d
> Code: c3 e8 17 32 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:00007fc2f7eafbf8 EFLAGS: 00000246 ORIG_RAX: 000000000000012a
> RAX: ffffffffffffffda RBX: 00007fc2f8c9e050 RCX: 00007fc2f8b62c8d
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000200000c0
> RBP: 00007fc2f8bc04af R08: 0000000000000002 R09: 0000000000000000
> R10: 0000000000000004 R11: 0000000000000246 R12: 0000000000000000
> R13: 00007fff421d61cf R14: 00007fff421d6370 R15: 00007fc2f7eafd80
>  </TASK>

I find reading the reproducers hard work. Turn things like:
```
...
    *(uint32_t*)0x200000c0 = 0;
    *(uint32_t*)0x200000c4 = 0x80;
    *(uint8_t*)0x200000c8 = 0;
    *(uint8_t*)0x200000c9 = 0;
    *(uint8_t*)0x200000ca = 0;
    *(uint8_t*)0x200000cb = 0;
...
    res = syscall(__NR_perf_event_open, /*attr=*/0x200000c0ul, /*pid=*/0,
                  /*cpu=*/0ul, /*group=*/-1, /*flags=*/0ul);
```
into the corresponding type/config. Then work out what's going on with
the case statements, is the test running in a hypervisor, etc.

I've seen a similar failure to this reported, but in that case the
event was a software cpu-clock event. The warning is:
```
...
[ 2519.138665] unexpected event refcount: 2; ptr=000000009c56b097
...
[ 2518.913630]  ? free_event+0x8b/0xb0
[ 2518.914040]  ? report_bug+0x2cc/0x430
[ 2518.914467]  ? free_event+0x8b/0xb0
[ 2518.915380]  ? handle_bug+0x5e/0xc0
[ 2518.915965]  ? exc_invalid_op+0x25/0x70
[ 2518.916565]  ? asm_exc_invalid_op+0x1a/0x20
[ 2518.917635]  ? __warn_printk+0x158/0x200
[ 2518.918112]  ? free_event+0x8b/0xb0
[ 2518.918538]  ? free_event+0x8a/0xb0
[ 2518.918944] __do_sys_perf_event_open+0x4fd/0x1d50
...
```
That is free_event was called and we expected the reference count to
be 1, it wasn't and so the memory wasn't freed potentially causing a
memory leak (better than a potential use-after-free) - hopefully
whoever has the other reference count will free the memory. A suspect
for holding the reference count would be the interrupt handler, but
maybe it is another CPU. I think it is inherent in the nature of the
bug that there is a race condition. It'd be interesting to know if
this is 100% reproducible.

Thanks,
Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-06  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-05  2:18 WARNING in free_event Ubisectech Sirius
2024-08-06  8:04 ` Peter Zijlstra
     [not found] <CAKHoSAufhtBjD_CgSXY1SOxqkAcY9n1gEwixiK-bL=Ktf7dtDA@mail.gmail.com>
2024-03-11 17:31 ` Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®