select: Don't allow unwanted/leftover fds being returned.
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 28 Aug 2017 13:49:00 +0000 (21:49 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 28 Aug 2017 13:55:28 +0000 (21:55 +0800)
commitce4975442fa0524017fb3c1aef93bbe6880ae770
tree680c99b1002669ee3648d492bae14122399bcedc
parentb7adaf3bcda6cb9de6f9ea18386a76def74f86ef
select: Don't allow unwanted/leftover fds being returned.

The root cause is that the lwp_kqueue_serial will wrap pretty quickly,
6 seconds on my laptop, if the select(2) is polling, either due to heavy
workload or 0 timeout.  The POC test:
https://leaf.dragonflybsd.org/~sephe/select_wrap.c

Fixing this issue by saving the original fd_sets and do additional
kevent filtering before return the fd to userland.

poll(2) suffers the similar issue and will be fixed in later commit.

Reported-by: many
sys/kern/sys_generic.c