Prevent allocation of buffers if exceeding available memory
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 11 Oct 2018 21:37:00 +0000 (17:37 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 15 Oct 2018 21:23:58 +0000 (17:23 -0400)
commit1790d63f59538ba7b183c7d6e03470f5d51fe563
tree5bb54f85c70873be7e32c57a8e09bee672a91dff
parentae8ff4cd689556fb2b4ed3657415e8f8cae5bc0c
Prevent allocation of buffers if exceeding available memory

Issue
=====
The running system can be rendered unusable by creating a channel
buffers larger than the available memory of the system, resulting in
random processes being killed by the OOM-killer.

These simple commands trigger the crash on my 15G of RAM laptop:
  lttng create
  lttng enable-channel -k --subbuf-size=16G --num-subbuf=1 chan0

Note that the subbuf-size * num-subbuf is larger than the physical
memory.

Solution
========
Get an estimate of the number of available pages and return ENOMEM if
there are not enough pages to cover the needs of the caller. Also, mark
the calling user thread as the first target for the OOM killer in case
the estimate of available pages was wrong.

This greatly reduces the attack surface of this issue as well as reducing
its potential impact.

This approach is inspired by the one taken by the Linux kernel
trace ring buffer[1].

Drawback
========
This approach is imperfect because it's based on an estimate.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/trace/ring_buffer.c#n1172

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lib/ringbuffer/ring_buffer_backend.c
This page took 0.025862 seconds and 4 git commands to generate.