linux-stable/include
Eric Biggers a36e1978c6 wait: add wake_up_pollfree()
commit 42288cb44c upstream.

Several ->poll() implementations are special in that they use a
waitqueue whose lifetime is the current task, rather than the struct
file as is normally the case.  This is okay for blocking polls, since a
blocking poll occurs within one task; however, non-blocking polls
require another solution.  This solution is for the queue to be cleared
before it is freed, using 'wake_up_poll(wq, EPOLLHUP | POLLFREE);'.

However, that has a bug: wake_up_poll() calls __wake_up() with
nr_exclusive=1.  Therefore, if there are multiple "exclusive" waiters,
and the wakeup function for the first one returns a positive value, only
that one will be called.  That's *not* what's needed for POLLFREE;
POLLFREE is special in that it really needs to wake up everyone.

Considering the three non-blocking poll systems:

- io_uring poll doesn't handle POLLFREE at all, so it is broken anyway.

- aio poll is unaffected, since it doesn't support exclusive waits.
  However, that's fragile, as someone could add this feature later.

- epoll doesn't appear to be broken by this, since its wakeup function
  returns 0 when it sees POLLFREE.  But this is fragile.

Although there is a workaround (see epoll), it's better to define a
function which always sends POLLFREE to all waiters.  Add such a
function.  Also make it verify that the queue really becomes empty after
all waiters have been woken up.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20211209010455.42744-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-12-14 10:16:55 +01:00
..
acpi ACPI: scan: Use unique number for instance_no 2021-03-30 14:40:12 +02:00
asm-generic hugetlbfs: flush TLBs correctly after huge_pmd_unshare 2021-12-08 08:46:52 +01:00
clocksource
crypto crypto: public_key: fix overflow during implicit conversion 2021-09-22 11:45:24 +02:00
drm drm: Return -ENOTTY for non-drm ioctls 2021-07-28 11:12:20 +02:00
dt-bindings dt-bindings: reset: meson8b: fix duplicate reset IDs 2020-01-23 08:20:29 +01:00
keys KEYS: Don't write out to userspace while holding key semaphore 2020-04-24 08:01:25 +02:00
kvm
linux wait: add wake_up_pollfree() 2021-12-14 10:16:55 +01:00
math-emu
media media: v4l2-device.h: Explicitly compare grp{id,mask} to zero in v4l2_device macros 2020-02-28 16:36:00 +01:00
memory
misc
net NFC: add NCI_UNREG flag to eliminate the race 2021-12-08 08:46:52 +01:00
pcmcia
ras
rdma RDMA/netlink: Add __maybe_unused to static inline in C file 2021-11-26 11:40:41 +01:00
scsi scsi: iscsi: Add iscsi_cls_conn refcount helpers 2021-07-20 16:17:49 +02:00
soc irqchip/eznps: Fix build error for !ARC700 builds 2020-09-23 10:46:27 +02:00
sound ALSA: compress: fix partial_drain completion state 2020-07-22 09:22:17 +02:00
target scsi: target: Fix ordered tag handling 2021-11-26 11:40:38 +01:00
trace memcg: fix a crash in wb_workfn when a device disappears 2021-02-23 14:00:30 +01:00
uapi PCI: Add PCI_EXP_LNKCTL2_TLS* macros 2021-12-08 08:46:51 +01:00
video
xen xen: sync include/xen/interface/io/ring.h with Xen's newest version 2021-12-08 08:46:52 +01:00