kernel - Fix long-standing bug in kqueue backend for *poll*()
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 23 Jan 2024 21:00:54 +0000 (13:00 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 24 Jan 2024 06:13:42 +0000 (22:13 -0800)
commit0d47c594fde0de2008b2f26db9ab7a6a22eaf64f
treee071c9449bb6f7c4da6c1154a51625cd556c5470
parent03517d4e1314f46a8bc390aa6bcb929361ee0569
kernel - Fix long-standing bug in kqueue backend for *poll*()

* The poll() family of system calls passes an fds[] array with a
  series of descriptors and event requests.  Our kernel implementation
  uses kqueue but a long standing bug breaks situations where
  more than one fds[] entry for the poll corresponds to the same
  { ident, filter } for kqueue, causing only the last such entry
  to be registered with kqueue and breaking poll().

* Added feature to kqueue to supply further distinctions between
  knotes beyond the nominal { kq, filter, ident } tuple, allowing
  us to fix poll().

* Added a FreeBSD feature where poll() implements an implied POLLHUP
  when events = 0.  This is used by X11 and (perhaps mistakenly) also
  by sshd.  Our poll previous ignored fds[] entries with events = 0.

* Note that sshd can generate poll fds[] arrays with both an events = 0
  and an events = POLLIN for the same descriptor, which broke sshd
  when I initially added the events = 0 support due to the first bug.

  Now with that fixed, sshd works properly.  However it is unclear whether
  the authors of sshd intended events = 0 to detect POLLHUP or not.

Reported-by: servik (missing events = 0 poll feature)
Testing: servik, dillon
sys/kern/kern_event.c
sys/kern/sys_generic.c
sys/sys/event.h