internal/task: protect the leaking GC free stack list from stack overflow

Đang mở
#6,124 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, wasm
Lĩnh vực
operating-systems

Hướng nghiên cứu

Start in src/internal/task/task_asyncify_stack_leaking.go, where the free list stores next and size in the first two words of each freed stack, and read allocStack, which pops from that list. Decide between the two fixes the issue lists; the magic-value check is the smaller change, and it needs a runtimeFatal("stack overflow") call on mismatch. Done means a corrupted list entry is caught in allocStack with a fatal error, and the existing task tests still pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

With #5981, the leaking GC with the asyncify scheduler keeps the stacks of exited goroutines on a free list for reuse. The list entry (next and size) is stored in the first two words of each free stack, in src/internal/task/task_asyncify_stack_leaking.go.

If a stack overflow goes past the canary of a running goroutine, it writes into the heap memory below that stack. Before #5981, that memory was other heap objects or dead stacks. Now it can be the list entry of a free stack. The next allocStack then follows a bad next pointer and gives that address to a new goroutine as its stack. The memory corruption then occurs far from the overflow, and it is difficult to find the cause.

The risk is small. Stacks grow down to the canary at the base, so the overflow must go past its own canary and then through the full free stack below it (64 KiB on wasip1) before it reaches the list entry. An overflow of that size also corrupts other heap objects without the free list. But with the free list, the corruption occurs silently in the allocator, and not in user data.

Possible fixes:

  • Store a magic value in each free list entry and check it in allocStack. Call runtimeFatal("stack overflow") if it changed. This is cheap and keeps the current design.
  • Keep the free list outside the stack memory, for example in a separate array of stack bases.
Ngôn ngữ chính
Go
Star
17.8k
Fork
1.1k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
380

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tinygo-org/tinygo

Tất cả issue của tinygo-org/tinygo

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.