linux-stable/include/uapi/asm-generic
Eric Biggers 50252e4b5e aio: fix use-after-free due to missing POLLFREE handling
signalfd_poll() and binder_poll() 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, by sending a POLLFREE notification to all waiters.

Unfortunately, only eventpoll handles POLLFREE.  A second type of
non-blocking poll, aio poll, was added in kernel v4.18, and it doesn't
handle POLLFREE.  This allows a use-after-free to occur if a signalfd or
binder fd is polled with aio poll, and the waitqueue gets freed.

Fix this by making aio poll handle POLLFREE.

A patch by Ramji Jiyani <ramjiyani@google.com>
(https://lore.kernel.org/r/20211027011834.2497484-1-ramjiyani@google.com)
tried to do this by making aio_poll_wake() always complete the request
inline if POLLFREE is seen.  However, that solution had two bugs.
First, it introduced a deadlock, as it unconditionally locked the aio
context while holding the waitqueue lock, which inverts the normal
locking order.  Second, it didn't consider that POLLFREE notifications
are missed while the request has been temporarily de-queued.

The second problem was solved by my previous patch.  This patch then
properly fixes the use-after-free by handling POLLFREE in a
deadlock-free way.  It does this by taking advantage of the fact that
freeing of the waitqueue is RCU-delayed, similar to what eventpoll does.

Fixes: 2c14fa838c ("aio: implement IOCB_CMD_POLL")
Cc: <stable@vger.kernel.org> # v4.18+
Link: https://lore.kernel.org/r/20211209010455.42744-6-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
2021-12-09 10:49:56 -08:00
..
auxvec.h
bitsperlong.h
bpf_perf_event.h
errno-base.h
errno.h
fcntl.h locks: remove LOCK_MAND flock lock support 2021-09-10 16:21:44 -04:00
hugetlb_encode.h powerpc/8xx: Support 16k hugepages with 4k pages 2020-09-15 22:13:31 +10:00
int-l64.h
int-ll64.h
ioctl.h
ioctls.h
ipcbuf.h arch: ipcbuf.h: make uapi asm/ipcbuf.h self-contained 2019-12-04 19:44:14 -08:00
Kbuild kbuild: force all architectures except um to include mandatory-y 2019-03-17 12:56:32 +09:00
kvm_para.h
mman-common.h mm/madvise: introduce MADV_POPULATE_(READ|WRITE) to prefault page tables 2021-06-30 20:47:30 -07:00
mman.h mm/mmap: move common defines to mman-common.h 2019-07-16 19:23:25 -07:00
msgbuf.h arch: msgbuf.h: make uapi asm/msgbuf.h self-contained 2019-12-04 19:44:14 -08:00
param.h
poll.h aio: fix use-after-free due to missing POLLFREE handling 2021-12-09 10:49:56 -08:00
posix_types.h y2038: hide timeval/timespec/itimerval/itimerspec types 2020-02-21 11:22:15 -08:00
resource.h
sembuf.h asm-generic/sembuf: Update architecture related information in comment 2020-10-26 16:48:22 +01:00
setup.h
shmbuf.h y2038: ipc: remove __kernel_time_t reference from headers 2019-11-15 14:38:28 +01:00
siginfo.h signal: Verify the alignment and size of siginfo_t 2021-07-23 13:15:31 -05:00
signal-defs.h signal: Add SA_IMMUTABLE to ensure forced siganls do not get changed 2021-11-03 14:09:26 -05:00
signal.h arch: move SA_* definitions to generic headers 2020-11-23 10:31:05 -06:00
socket.h net: add new socket option SO_RESERVE_MEM 2021-09-30 13:36:46 +01:00
sockios.h net: socket: implement 64-bit timestamps 2019-04-19 14:07:40 -07:00
stat.h
statfs.h
swab.h
termbits.h
termios.h
types.h
ucontext.h
unistd.h futex: Implement sys_futex_waitv() 2021-10-07 13:51:11 +02:00