]> git.ipfire.org Git - people/arne_f/kernel.git/commit
dm crypt: limit the number of allocated pages
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 14 Aug 2017 02:45:08 +0000 (22:45 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Apr 2018 07:42:59 +0000 (09:42 +0200)
commit002c9842c8132c3c3af4f69b5a17a1b31302340d
tree2bdea58fbc1d4e39eff3f931f12f897a93e72f08
parentaa2a38b37f524a6256e3deb665a3e0045f8d968e
dm crypt: limit the number of allocated pages

commit 5059353df86e2573ccd9d43fd9d9396dcec47ca2 upstream.

dm-crypt consumes an excessive amount memory when the user attempts to
zero a dm-crypt device with "blkdiscard -z". The command "blkdiscard -z"
calls the BLKZEROOUT ioctl, it goes to the function __blkdev_issue_zeroout,
__blkdev_issue_zeroout sends a large amount of write bios that contain
the zero page as their payload.

For each incoming page, dm-crypt allocates another page that holds the
encrypted data, so when processing "blkdiscard -z", dm-crypt tries to
allocate the amount of memory that is equal to the size of the device.
This can trigger OOM killer or cause system crash.

Fix this by limiting the amount of memory that dm-crypt allocates to 2%
of total system memory. This limit is system-wide and is divided by the
number of active dm-crypt devices and each device receives an equal
share.

Cc: stable@vger.kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-crypt.c