unix: some bugs found by audit
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ó
- 4/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 15/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ệ
- c, linux, macos
- Lĩnh vực
- networking, operating-systems
Hướng nghiên cứu
This is a tracker for 24 separate bugs across src/unix, so pick one self-contained item rather than the whole list, such as the one-line fd2 fix in src/unix/process.c:725-733 or the EOF check in src/unix/fs.c:1376-1392. Read the cited lines and the listed trigger, then reproduce it with a small test program. Done means the trigger no longer reproduces and the existing unix tests still pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bugs found in src/unix
Audit of the Unix backend on branch v1.x (as of f08538cc).
Line numbers refer to that revision.
Legend:
- Severity: High (memory corruption, hang, wrong data, crash), Medium (leak,
wrong error code, wrong result in a specific setup), Low (minor, performance). - Status: Reproduced = triggered with a test program; Confirmed = verified
by reading the code and its callers.
High severity
1. uv_udp_try_send2: sendmmsg batching loop skips messages and misreports what was sent
- File:
src/unix/udp.c:1433-1449(uv__udp_sendmsgv) - Status: Confirmed
- The inner loop already advances
ibynwhile fillingm[], and then
i += radvances it again aftersendmmsg().for (n = 0; i < count && n < ARRAY_SIZE(m); i++, n++) ... r = sendmmsg(fd, m, n, 0); nsent += r; i += r; - Trigger:
count = 30, the socket buffer is nearly full, andsendmmsgsends
only 5 of the first 20 messages.ibecomes 25, so messages 5–24 are never
tried and 25–29 are sent. The function returnsnsent = 10, so the caller
thinks messages 0–9 went out. With full batches it also stops early
(r = 20makesi = 40). - Fix: set
i = i - n + rinstead ofi += r.
2. uv_spawn (posix_spawn path): scratch-fd search can pick an fd that is still in use
- File:
src/unix/process.c:725-733 - Status: Confirmed
- After a collision the loop sets
fd2 = 0, and the loop'sfd2++turns it into 1,
sochild_fds[0]is never checked against the newuse_fd. - Trigger:
child_fds = {4, 3, 1}(stderr inherited from fd 1, i.e.2>&1).
For target fd 2 the search tries 3 (taken bychild_fds[1]), then picks 4,
which ischild_fds[0].adddup2(1, 4)overwrites the child's fd 4 before
it is dup'd onto fd 0, so stdin silently ends up as the parent's fd 1. - Affects Linux and macOS, which use posix_spawn by default.
- Fix:
fd2 = -1.
3. uv_spawn: stdio pipe fds closed twice when opening a stream fails
- File:
src/unix/process.c:1232-1252 - Status: Confirmed
- On failure at index
i,uv__process_close_stream()closes the streams for
j < i, which closespipes[j][0]throughuv__stream_close.pipes[j][0]
is not reset to -1, so theerror:loop closes the same fd number again. - Trigger:
stdio[0]isUV_CREATE_PIPEwith a fresh pipe, andstdio[1]is
UV_CREATE_PIPEwith a pipe that is already open (uv__stream_openreturns
UV_EBUSY). In a multithreaded program, the second close can close an fd
another thread just opened, such as a threadpool file operation.
4. uv_fs_copyfile: infinite loop if the source is shorter than its st_size
- File:
src/unix/fs.c:1376-1392 - Status: Confirmed
- The loop runs until
bytes_to_send(taken fromfstat) reaches 0, but
uv_fs_sendfilereturns 0 at EOF, and that case is not handled. - Trigger: copying a file while another process truncates it, or copying a
sysfs file (st_size4096 but only a few bytes of content). The threadpool
thread, or a synchronous caller, spins forever. - Fix: break out of the loop when
bytes_written == 0.
5. uv_pipe_connect2: no guard against a connect that is already in progress
- File:
src/unix/pipe.c:269-358 - Status: Reproduced
- Unlike
uv__tcp_connect(which returnsUV_EALREADY), the pipe version
overwriteshandle->connect_reqand callsuv__req_initagain. - Trigger: call
uv_pipe_connect2(&r1, ...)and thenuv_pipe_connect2(&r2, ...)
on the same handle. r1's callback never runs, and its active request is never
released, souv_run(UV_RUN_DEFAULT)never returns, even after the handle is
closed.
6. uv_pipe_connect2 on a handle that already has an fd leaves it unreadable and unwritable
- File:
src/unix/pipe.c:301-345 - Status: Reproduced
UV_HANDLE_READABLE | UV_HANDLE_WRITABLEare set only when the call creates
the socket (new_sock).- Trigger 1: connect fails with ENOENT, then a retry to a valid path succeeds.
The handle reportsreadable=0 writable=0,uv_read_startreturns
UV_ENOTCONN, anduv_writereturnsUV_EPIPE. - Trigger 2:
uv_pipe_bindfollowed byuv_pipe_connectfails the same way.
7. uv_signal_start after uv_signal_start_oneshot: the handle stays one-shot
- File:
src/unix/signal.c:424-425,src/unix/signal.c:540-577 - Status: Confirmed
UV_SIGNAL_ONE_SHOTis set on start but never cleared, not even in
uv__signal_stop.- Trigger:
uv_signal_start_oneshot(h, cb, SIGUSR1), let it fire (or call
stop), thenuv_signal_start(h, cb, SIGUSR1). The handle still stops itself
after the first signal. - Related: the short-circuit at line 396 (
signum == handle->signum) ignores a
switch between one-shot and regular mode on a running handle.
8. macOS fsevents: uv__fsevents_init error path leaves freed memory reachable
- File:
src/unix/fsevents.c:822-858 - Status: Confirmed
- When
uv__cf_loop_signalfails (ENOMEM),cf_cbhas already gone through
uv_async_init(so it is in the loop's handle and async queues), and the
handle is already instate->fsevent_handles. The error path only frees
cf_cband destroyscf_mutex. The loop queues and the CF thread then
point at freed memory. fail_cf_mutex_inithas the same problem: it frees an async handle that has
already been initialized.
9. macOS uv_set_process_title: NULL function-pointer call after a failed lookup
- File:
src/unix/darwin-proctitle.c:104,:173-180,:209-213 - Status: Confirmed
ls.CFReleaseis set before the LaunchServices symbol lookups that can still
fail. On failure,ls.CFReleasestays non-NULL, so the next
uv__set_process_titleskips the lookup and calls
ls.LSSetApplicationLaunchServicesServerConnectionStatus, which is NULL.- Trigger: a macOS version that lacks one of the private symbols. The first
call fails silently, becauseproctitle.cignores the return value, and the
second call crashes.
10. Linux uv_cpu_info (arm64): every CPU gets the first model name
- File:
src/unix/linux.c:1906-1907 - Status: Reproduced
model++runs afterfoundis set, somodelpoints one past the slot that
matched. Slot 1 stays empty and matches every name (strlen("") == 0), so
every later model resolves to slot 2, which holds the first model's name.- Trigger: big.LITTLE systems (for example Cortex-A55 + A76) report all cores
as Cortex-A55. Thestrncmpprefix match also confuses names like
"Cortex-A78" and "Cortex-A78AE".
Medium severity
11. uv_fs_sendfile to an O_APPEND fd fails with EBADF instead of falling back
- File:
src/unix/fs.c:1050-1051 - Status: Reproduced
copy_file_rangereturnsEBADFfor anO_APPENDoutput fd, but onlyEINVAL
andENOSYStrigger thesendfileand read/write fallbacks, both of which
would work.
12. cgroup v2 CPU quota: the tightest ancestor limit is computed but never returned
- File:
src/unix/linux.c:2426-2442 - Status: Confirmed
min_quotais computed but never written back, so*quotaends up as the
limit of the highest ancestor that has one.- Trigger:
/a/cpu.maxallows 4 CPUs,/a/b/cpu.maxallows 2, and the
process is in/a/b.uv_available_parallelism()returns 4.
13. cgroup v1 CPU controller path is parsed incorrectly
- File:
src/unix/linux.c:2449-2457 - Status: Confirmed
- For a line like
4:cpu,cpuacct:/docker/abc, skipping":cpu,"leaves
cpuacct:/docker/abcas the path. The file is never found, and the code
returnsUV_EIO. - A plain
N:cpu:/pathline is not matched at all. As a result, CPU quotas
never apply on cgroup v1 hosts (for exampledocker --cpus=2).
14. cgroup path buffers are 256 bytes and silently truncate
- File:
src/unix/linux.c:2367,:2462 - Status: Confirmed
char path[256]is too short for deep Kubernetes/systemd cgroup paths.
snprintftruncates the path, the open fails, and the CPU limit is ignored.
The memory-limit code uses 4097-byte buffers.
15. uv_socketpair checks the wrong flag (BSDs)
- File:
src/unix/tcp.c:647 - Status: Confirmed
- The check is
flags & UV_FS_O_NONBLOCKbut should beflags & SOCK_NONBLOCK.
On FreeBSD, NetBSD and OpenBSDO_NONBLOCK == 4, so forSOCK_SEQPACKET (5)
orSOCK_RDM (4)the early return skipsuv__nonblock, and the fds come
back blocking.
16. uv__stream_open sets handle flags before steps that can still fail
- File:
src/unix/stream.c:411-421 - Status: Confirmed
- If
nodelay,keepaliveorSO_OOBINLINEfails, the handle keeps
READABLE|WRITABLEwithio_watcher.fd == -1. A lateruv_read_start
reachesuv__io_start(fd=-1), which asserts in debug builds and writes
loop->watchers[-1]in release builds. - Trigger: on macOS,
uv_tcp_nodelay(client, 1)beforeuv_accept, and the
peer sends RST before the accept is processed.
17. uv_spawn can return a positive value
- File:
src/unix/process.c:841,:889-892 - Status: Confirmed
errstarts at -1. If everyPATHentry is at leastPATH_MAXlong, no
spawn is attempted, -1 is returned, and the caller returns
UV__ERR(-1) == 1. Callers that checkr < 0treat this as success.- Fix: start with
err = ENOENT.
18. uv__fsevents_close returns a positive errno and leaks on failure
- File:
src/unix/fsevents.c:880-882 - Status: Confirmed
erris already a negative UV code, soUV__ERR(err)makes it positive, and
uv_fs_event_stopreturns that positive value. The handle has also already
been removed from the list, butcf_cb,cf_mutexandrealpathare not
cleaned up.
19. illumos/Solaris: a failed first uv_fs_event_start disables fs events for the loop
- File:
src/unix/sunos.c:507-539 - Status: Confirmed
loop->fs_fdis set beforeuv__fs_event_rearm. If that fails, for example
with ENOENT, the port watcher is never started, and later starts see
first_run == 0, so they never start it either. No events are delivered
on that loop again.
20. macOS tty (select fallback): uv__tty_close compares the wrong fd
- File:
src/unix/tty.c:357-366vs:303/:319 - Status: Confirmed (code reading)
orig_termios_fdis set fromuv__stream_fd(), which is the real tty fd, but
close compares it withio_watcher.fd, which is the socketpairfake_fd. The
terminal is not restored, anduv_tty_reset_mode()later runstcsetattr
on a closed or reused fd.
21. AIX AHAFS: memory leak on every directory event, plus a possible NULL dereference
- File:
src/unix/aix.c:672,:682-683,:739-749 - Status: Confirmed
dir_filename = uv__strdup(...)runs on every event without freeing the
previous value.- After
AHAFS_MODDIR_UNMOUNTsets it to NULL,uv__strscpy(fname, NULL, ...)
dereferences NULL.
22. AIX uv_fs_event_start: leaks, and no check for an already-active handle
- File:
src/unix/aix.c:451-484,:601-603,:770-802 - Status: Confirmed
uv__is_ahafs_mountedleakspon every error path.uv__setup_ahafsleaks the fd whenwrite()fails.- A second start on an active handle overwrites the watcher and the path
without cleaning up the old ones.
23. z/OS: closing an fd whose number equals the message-queue slot disables fs events
- File:
src/unix/os390-syscalls.c:363,:243 - Status: Confirmed
- The slot
items[size-1]is reserved for the message queue, but
epoll_file_closeandEPOLL_CTL_DELonly checkfd < size. Closing an
unrelated fd numberedsize-1clears the message-queue entry.
24. QNX uv_resident_set_memory checks for failure the wrong way
- File:
src/unix/qnx.c:134-143 - Status: Confirmed
uv__open_cloexecreturns-errno, not -1. The code then callsdevctland
uv__closeon a negative fd, which trips an assert in debug builds and
returns the wrong error in release builds.
25. QNX uv_exepath ignores a realpath failure
- File:
src/unix/qnx.c:71-73 - Status: Confirmed
- If
realpathfails,pathis uninitialized.strlcpycopies stack garbage,
possibly reading past the buffer, and the function still returns 0.
26. kqueue uv_fs_event_start leaks the fd and path when uv__io_init_start fails
- File:
src/unix/kqueue.c:620-629 - Status: Confirmed (needs OOM)
27. kqueue EVFILT_USER async: placeholder fd leaks when kevent registration fails
- File:
src/unix/async.c:249-265 - Status: Confirmed
28. Linux uv_fs_event_start leaks the inotify watch when malloc fails
- File:
src/unix/linux.c:2772 - Status: Confirmed
inotify_rm_watchis not called, so the watch keeps counting against the
per-user inotify quota.
29. macOS uv_thread_setname / uv_thread_getname return the wrong error code
- File:
src/unix/thread.c:907-909,:954-955 - Status: Confirmed
pthread_setname_npandpthread_getname_npreturn the error number
directly, but the code returnsUV__ERR(errno), which can be stale or 0.
30. uv_pipe_bind2 with namelen == 0 on Linux reads *name and binds a bogus name
- File:
src/unix/pipe.c:126 - Status: Reproduced
uv_pipe_bind2(&p, "foo", 0, 0)takes the file-path branch and binds an
abstract name of 108 NUL bytes instead of autobinding. The bind is not
repeatable, and close callsunlink("").
Low severity
31. Wrong kernel-version constant disables io_uring close on 5.15.90+
- File:
src/unix/linux.c:901 - Status: Confirmed
0x050A00is 5.10.0, not 5.16.0, so the 5.15.90+ LTS range always falls back to
the threadpool for close. This costs performance only.
32. uv_cond_timedwait / uv_thread_create_ex integer overflow
- File:
src/unix/thread.c:858,:164 - Status: Confirmed
timeout += uv__hrtime()wraps for very large timeouts such asUINT64_MAX,
which causes an immediateUV_ETIMEDOUT.- Rounding the stack size wraps to 0 near
SIZE_MAX, which silently gives the
minimum stack size instead of an error.
33. EAI_SYSTEM with errno == 0 maps to success
- File:
src/unix/getaddrinfo.c:87 - Status: Plausible
- The callback can get
status == 0withres == NULL.
34. macOS uv_tty_init error path restores flags on a closed fd
- File:
src/unix/tty.c:219-229 - Status: Confirmed
- The caller's original fd is left
O_NONBLOCK.
35. IPC read: data is lost when control-message handling fails
- File:
src/unix/stream.c:1122-1127 - Status: Confirmed (needs ENOMEM)
- The
nreadpayload bytes already received are dropped,read_cbgets the
error, and the stream keeps reading, which corrupts framing.
36. vm_deallocate gets an element count instead of a byte size
- File:
src/unix/darwin.c:227,:245 - Status: Confirmed
- The size passed should be
msg_type * sizeof(integer_t). This only leaks on
machines with more than about 256 CPUs.
37. DragonFly uv_cpu_info reads uninitialized heap
- File:
src/unix/freebsd.c:201-202,:249-269 - Status: Confirmed
kern.cp_timereturns one aggregate row, but the code reads one row per CPU.
Minor and other notes
src/unix/aix.c:88-89:uv__platform_loop_initreturns a literal-1
instead ofUV__ERR(errno).src/unix/aix.c:1251:uv_interface_addressesalways returnsUV_ENOSYS
on a system error.src/unix/ibmi.c:234:uv_get_free_memoryreturns total memory.src/unix/fsevents.c:646-650: thefail_thread_createpath never
CFReleasessignal_source.src/unix/hurd.c:48-57:uv_exepathwith*size == 1reads an
uninitialized buffer.src/unix/sunos.c:869:uv_interface_addressesdereferences
ifa_netmaskwithout a NULL check.src/unix/linux.c:uv__inotify_forkreturns early on a restart error,
leaking the remaining path copies.src/unix/fs.c:uv__fs_readlinksilently truncates whenlen == maxlen.
- Ngôn ngữ chính
- C
- Star
- 27.4k
- Fork
- 4k
- Merge trung bình
- 4 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 23
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của libuv/libuv
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
windows: misleading comments in tty.cCó thể đã có người làm @LUX-ETVERITAS đã nhận 3 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
win,pipe: allow pipe name rebinding for server handoverCó thể đã có người làm @ntdiary đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
libuv/libuv#5470 · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
kqueue: write watcher lost after a full 1024-event poll (w->events keeps POLLOUT after EVFILT_WRITE is deleted)Có thể đã có người làm @yxshee đã nhận 6 ngày trước. Đang mởbug macos
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Make the HTTP server's keep-alive and headers timeouts configurableCó thể đã có người làm @mattgodbolt đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
compiler-explorer/compiler-explorer#9902 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
timescale/pg_vectorsearch#446 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] msetcfg accepts unsupported mcfg encodingsCó thể đã có người làm @BinaryBardY đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OpenXiangShan/NEMU#1319 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày