@@ -134,8 +134,22 @@ core_loaded () {
134134 [[ -d " /sys/kernel/kpatch" ]] || [[ -d " /sys/kernel/livepatch" ]]
135135}
136136
137+ if command -v readelf > /dev/null 2>&1 ; then
138+ get_module_section_string () {
139+ readelf -p " $2 " " $1 " | awk ' NF>=3 && /^\s*\[/ {print $3; exit}'
140+ }
141+ elif command -v eu-readelf > /dev/null 2>&1 ; then
142+ get_module_section_string () {
143+ eu-readelf --string-dump=" $2 " " $1 " | awk ' NF>=3 && /^\s*\[/ {print $3; exit}'
144+ }
145+ else
146+ get_module_section_string () {
147+ return 1
148+ }
149+ fi
150+
137151get_module_name () {
138- readelf -p .gnu.linkonce.this_module " $1 " | grep ' \[.*\] ' | awk ' {print $3} '
152+ get_module_section_string " $1 " .gnu.linkonce.this_module
139153}
140154
141155init_sysfs_var () {
@@ -156,10 +170,10 @@ init_sysfs_var() {
156170}
157171
158172verify_module_checksum () {
159- modname=" $( get_module_name " $1 " ) "
173+ modname=" $( get_module_name " $1 " ) " || return 1
160174 [[ -z " $modname " ]] && return 1
161175
162- checksum=" $( readelf -p .kpatch.checksum " $1 " 2>&1 | grep ' \[.*\] ' | awk ' {print $3} ' ) "
176+ checksum=" $( get_module_section_string " $1 " .kpatch.checksum 2> /dev/null ) " || return 1
163177
164178 # Fail checksum match only if both exist and diverge
165179 if [[ -n " $checksum " ]] && [[ -e " $SYSFS /${modname} /checksum" ]] ; then
@@ -316,7 +330,8 @@ load_module () {
316330 fi
317331
318332 local modname
319- modname=" $( get_module_name " $module " ) "
333+ modname=" $( get_module_name " $module " ) " || die " failed to get module name from $module "
334+ [[ -z " $modname " ]] && die " failed to get module name from $module "
320335 local moddir=" $SYSFS /$modname "
321336 if [[ -d " $moddir " ]] ; then
322337 if [[ " $( cat " ${moddir} /enabled" ) " -eq 0 ]]; then
0 commit comments