From 50a8461fc7cc70b57387baa58ff4db864ba36632 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 5 Sep 2022 17:49:18 +0800 Subject: [PATCH] Choosing the most memory-consuming key slot when estimating the memory requirement for LUKS-encrypted target When there are multiple key slots, "kdumpctl estimate" uses the least memory-consuming key slot. For example, when there are two memory slots created with --pbkdf-memory=1048576 (1G) and --pbkdf-memory=524288 (512M), "kdumpctl estimate" thinks the extra memory requirement is only 512M. This will of course lead to OOM if the user uses the more memory-consuming key slot. Fix it by sorting in reverse order. Fixes: e9e6a2c ("kdumpctl: Add kdumpctl estimate") Signed-off-by: Coiby Xu Reviewed-by: Lichen Liu Signed-off-by: Coiby Xu --- kdumpctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8ff4cb0..90d84f3 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1242,12 +1242,12 @@ do_estimate() for _dev in $(get_all_kdump_crypt_dev); do _crypt_info=$(cryptsetup luksDump "/dev/block/$_dev") [[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p") == "2" ]] || continue - for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n); do + for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n -r); do crypt_size=$((crypt_size + _mem * 1024)) break done done - [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement\n" + [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with maximum memory requirement\n" estimated_size=$((kernel_size + mod_size + initrd_size + runtime_size + crypt_size)) if [[ $baseline_size -gt $estimated_size ]]; then