From 0c8b5b9614c5b1c2b2d98713621db0560c923b11 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 9 Dec 2025 11:34:44 +0800 Subject: [PATCH] Rewrite kdump_get_conf_val Resolves: RHEL-117011 Upstream: kdump-utils Conflict: None Signed-off-by: Lichen Liu --- ...rounding-quotes-from-configuration-v.patch | 63 +++++++++ ...initramfs-rewrite-kdump_get_conf_val.patch | 123 ++++++++++++++++++ kdump-utils.spec | 2 + 3 files changed, 188 insertions(+) create mode 100644 0006-Revert-Strip-surrounding-quotes-from-configuration-v.patch create mode 100644 0007-kdump-lib-initramfs-rewrite-kdump_get_conf_val.patch diff --git a/0006-Revert-Strip-surrounding-quotes-from-configuration-v.patch b/0006-Revert-Strip-surrounding-quotes-from-configuration-v.patch new file mode 100644 index 0000000..e25f999 --- /dev/null +++ b/0006-Revert-Strip-surrounding-quotes-from-configuration-v.patch @@ -0,0 +1,63 @@ +From 8062d687ef56d61d2b9a581e0fd6f291466d5dfa Mon Sep 17 00:00:00 2001 +From: Lichen Liu +Date: Tue, 25 Nov 2025 12:08:00 +0800 +Subject: [PATCH 6/7] Revert "Strip surrounding quotes from configuration + values" + +This reverts commit 1a733872aeab1d1dcc0b063cd05afe61bbeb1c33. + +kdump_get_conf_val() will be rewritten so this commit is not +needed at all. + +Signed-off-by: Lichen Liu +--- + dracut/99kdumpbase/module-setup.sh | 2 +- + kdump-lib-initramfs.sh | 5 ++--- + kdumpctl | 1 - + 3 files changed, 3 insertions(+), 5 deletions(-) + +diff --git a/dracut/99kdumpbase/module-setup.sh b/dracut/99kdumpbase/module-setup.sh +index 32819ab..313d74e 100755 +--- a/dracut/99kdumpbase/module-setup.sh ++++ b/dracut/99kdumpbase/module-setup.sh +@@ -724,7 +724,7 @@ kdump_install_conf() { + kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" + + while read -r _opt _val; do +- [[ $_val == \"*\" ]] && _val=${_val:1:-1} ++ # remove inline comments after the end of a directive. + case "$_opt" in + raw) + _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") +diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh +index 39e52a6..97760bf 100755 +--- a/kdump-lib-initramfs.sh ++++ b/kdump-lib-initramfs.sh +@@ -29,10 +29,9 @@ kdump_read_conf() + kdump_get_conf_val() + { + # For lines matching "^\s*$1\s+", remove matched part (config name including space), +- # remove tailing comment, space and the surrounding quotes, then store in hold space. +- # Print out the hold buffer on last line. ++ # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && +- sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;s/^\"\(.*\)\"$/\1/;h};\${x;p}" $KDUMP_CONFIG_FILE ++ sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE + } + + is_mounted() +diff --git a/kdumpctl b/kdumpctl +index d630820..e47396e 100755 +--- a/kdumpctl ++++ b/kdumpctl +@@ -324,7 +324,6 @@ _set_config() + fi + return 1 + fi +- [[ $_val == \"*\" ]] && _val=${_val:1:-1} + OPT[$opt]="$val" + } + +-- +2.51.1 + diff --git a/0007-kdump-lib-initramfs-rewrite-kdump_get_conf_val.patch b/0007-kdump-lib-initramfs-rewrite-kdump_get_conf_val.patch new file mode 100644 index 0000000..53c54f6 --- /dev/null +++ b/0007-kdump-lib-initramfs-rewrite-kdump_get_conf_val.patch @@ -0,0 +1,123 @@ +From d81109cf9291250b42434fc51798c93b613c4ee2 Mon Sep 17 00:00:00 2001 +From: Philipp Rudo +Date: Thu, 6 Nov 2025 15:07:42 +0100 +Subject: [PATCH 7/7] kdump-lib-initramfs: rewrite kdump_get_conf_val + +Previously, kdump_get_conf_val() relied on a "magic" regular +expression to parse kdump.conf, making maintenance and +extension difficult. This patch rewrites the parsing logic +to be more human-readable. + +The '\|' needs to be changed to a single '|' because after +the rewrite we will use another tool to parse the options to +find. + +Furthermore, kdump_read_conf() has been refactored to invoke +kdump_get_conf_val(), as their logic is functionally identical. + +Signed-off-by: Philipp Rudo +Signed-off-by: Lichen Liu +--- + kdump-lib-initramfs.sh | 49 +++++++++++++++++++++++++++++++++++------- + kdump-lib.sh | 6 +++--- + 2 files changed, 44 insertions(+), 11 deletions(-) + +diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh +index 97760bf..6f5d6db 100755 +--- a/kdump-lib-initramfs.sh ++++ b/kdump-lib-initramfs.sh +@@ -19,19 +19,52 @@ LUKS_KEY_PRFIX="kdump-cryptsetup:vk-" + # Read kdump config in well formated style + kdump_read_conf() + { +- # Following steps are applied in order: strip trailing comment, strip trailing space, +- # strip heading space, match non-empty line, remove duplicated spaces between conf name and value +- [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE ++ kdump_get_conf_val "" + } + + # Retrieves config value defined in kdump.conf +-# $1: config name, sed regexp compatible ++# $1: config name, if empty print full config + kdump_get_conf_val() + { +- # For lines matching "^\s*$1\s+", remove matched part (config name including space), +- # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. +- [ -f "$KDUMP_CONFIG_FILE" ] && +- sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE ++ _to_find="$1" ++ _found="" ++ ++ [ -f "$KDUMP_CONFIG_FILE" ] || return ++ while read -r _line; do ++ _line="$(echo "$_line" | tr -s "[:blank:]" " ")" ++ case "$_line" in ++ "" | \#*) ++ continue ++ ;; ++ *\#*) ++ _line="${_line%%\#*}" ++ _line="${_line% }" ++ ;; ++ esac ++ ++ _opt=${_line%% *} ++ _val=${_line#* } ++ ++ case "$_val" in ++ \"*\") ++ # Remove quotes ++ _val="${_val#\"}" ++ _val="${_val%\"}" ++ ;; ++ esac ++ ++ if [ -z "$_to_find" ]; then ++ echo "$_opt $_val" ++ elif echo "$_opt" | grep -q -E "^($_to_find)$"; then ++ # make sure to only return the last match to mirror the ++ # old behavior ++ _found="$_val" ++ fi ++ done < "$KDUMP_CONFIG_FILE" ++ [ -n "$_found" ] && echo "$_found" ++ ++ # make sure we return 0 even when a option isn't set ++ return 0 + } + + is_mounted() +diff --git a/kdump-lib.sh b/kdump-lib.sh +index 4196b0e..61da1f7 100755 +--- a/kdump-lib.sh ++++ b/kdump-lib.sh +@@ -87,7 +87,7 @@ to_dev_name() + + is_user_configured_dump_target() + { +- [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh\|virtiofs") ]] || is_mount_in_dracut_args ++ [[ $(kdump_get_conf_val "ext[234]|xfs|btrfs|minix|raw|nfs|ssh|virtiofs") ]] || is_mount_in_dracut_args + } + + get_block_dump_target() +@@ -98,7 +98,7 @@ get_block_dump_target() + return + fi + +- _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|virtiofs") ++ _target=$(kdump_get_conf_val "ext[234]|xfs|btrfs|minix|raw|virtiofs") + [[ -n $_target ]] && to_dev_name "$_target" && return + + _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") +@@ -116,7 +116,7 @@ get_block_dump_target() + + is_dump_to_rootfs() + { +- [[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]] ++ [[ $(kdump_get_conf_val 'failure_action|default') == dump_to_rootfs ]] + } + + is_lvm2_thinp_dump_target() +-- +2.51.1 + diff --git a/kdump-utils.spec b/kdump-utils.spec index ed2f732..98dc310 100644 --- a/kdump-utils.spec +++ b/kdump-utils.spec @@ -13,6 +13,8 @@ Patch02: 0002-unit-tests-Add-case-for-quoted-configuration-values.patch Patch03: 0003-Allow-kdump.service-to-access-LUKS-volume-keys.patch Patch04: 0004-Restore-SELinux-label-of-crypttab-file.patch Patch05: 0005-Allow-sudo-kdumpctl-for-LUKS-dump-target.patch +Patch06: 0006-Revert-Strip-surrounding-quotes-from-configuration-v.patch +Patch07: 0007-kdump-lib-initramfs-rewrite-kdump_get_conf_val.patch %ifarch ppc64 ppc64le Requires(post): servicelog