Bug 1481047 - blkdev_issue_zeroout on dm-crypt container could cause OOM and kernel panic
blkdev_issue_zeroout on dm-crypt container could cause OOM and kernel panic
Status: ASSIGNED
Product: LVM and device-mapper
Classification: Community
Component: device-mapper (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Mikulas Patocka
cluster-qe@redhat.com
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-08-13 17:07 EDT by Tom Yan
Modified: 2017-08-22 09:39 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
rule-engine: lvm‑technical‑solution?


Attachments (Terms of Use)
Another test case that shows the problem (1/2) (8.33 KB, image/png)
2017-08-13 17:10 EDT, Tom Yan
no flags Details
Another test case that shows the problem (2/2) (21.00 KB, image/png)
2017-08-13 17:18 EDT, Tom Yan
no flags Details

  None (edit)
Description Tom Yan 2017-08-13 17:07:01 EDT
Description of problem:
When one attempts to zero out a dm-crypt container with blkdiscard -z, OOM and kernel panic could occur.

Apparently the reason is, when the bio chain of zero pages reaches the dm layer, dm-crypt does not know to split the chain but instead it try to allocate memory for the whole chain/request for encryption/conversion, so if the size of that is larger than the available memory, OOM, and in extreme cases, kernel panic could occur:
https://gitlab.com/cryptsetup/cryptsetup/uploads/207ffdada52f3172f54a014c67159625/DSC_0129.JPG

blkdev_issue_zeroout is the block layer function called:
http://elixir.free-electrons.com/linux/latest/source/block/ioctl.c#L257

This should be the method involved:
http://elixir.free-electrons.com/linux/latest/source/block/blk-lib.c#L308

Version-Release number of selected component (if applicable):
kernel 4.12.3 (Arch Linux core/linux)

Steps to Reproduce:
1. cryptsetup open /dev/(disk/partition) rand --type plain --key-file /dev/random
2. blkdiscard -z /dev/(disk/partition)
Comment 1 Tom Yan 2017-08-13 17:10 EDT
Created attachment 1312799 [details]
Another test case that shows the problem (1/2)

You can see that there are 2713M available and I am making a zero out request of 2560M.
Comment 2 Tom Yan 2017-08-13 17:18 EDT
Created attachment 1312800 [details]
Another test case that shows the problem (2/2)

You can see the available memory can at least go down to as low as 273M (while 2713 - 2560 = 153M). Memory are released bit by bit as the zero pages get converted/encrypted and written to the disk, apparently.
Comment 3 Milan Broz 2017-08-14 02:44:28 EDT
There is a dm-crypt patch by Mikulas that should fix the issue
https://www.redhat.com/archives/dm-devel/2017-August/msg00164.html

Note You need to log in before you can comment on or make changes to this bug.