From 4757b08830f275b9713d1e84c7d8296e0663d763 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Nov 01 2022 02:38:40 +0000 Subject: Choosing the most memory-consuming key slot when estimating the memory requirement for LUKS-encrypted target Related: bz2076206 Upstream: Fedora Conflict: None commit 50a8461fc7cc70b57387baa58ff4db864ba36632 Author: Coiby Xu Date: Mon Sep 5 17:49:18 2022 +0800 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 Signed-off-by: Coiby Xu --- diff --git a/kdumpctl b/kdumpctl index 66d63db..1a0bd6d 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1269,12 +1269,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