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:55 +0000 (17:23 -0400)
commit60f9ca274a6227337f13d8f5379468f6258a645e
tree4e0265f2e16234bcc59dd55c400f85b2cf38a4db
parentcba6ec2e260f592e2591b5a03decedc077edf91f
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.025008 seconds and 4 git commands to generate.