Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#77050 - [mkinitcpio] kernel-install unified kernel image escaping issue

Attached to Project: Arch Linux
Opened by Florian (nougad) - Sunday, 08 January 2023, 19:01 GMT
Last edited by Toolybird (Toolybird) - Sunday, 08 January 2023, 22:01 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

/usr/lib/kernel/install.d/50-mkinitcpio.install contains an encoding issue when building unified kernel image:

Current behavior:

```
$ kernel-install add 6.1.3-arch1-1 /usr/lib/modules/6.1.3-arch1-1/vmlinuz
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: /tmp/mkinitcpio.fatqlo
==> Image generation successful
==> Creating unified kernel image: /boot/EFI/Linux/aee901b403f349d492561b8addecc2a8-6.1.3-arch1-1.efi
-> Using UEFI stub: /usr/lib/systemd/boot/efi/linuxx64.efi.stub
==> ERROR: Kernel image '' not found
/boot/EFI/Linux/aee901b403f349d492561b8addecc2a8-6.1.3-arch1-1.efi does not exist
(6/7) Refreshing PackageKit...
```

This is because of the line:

```
mkinitcpio -k "$KERNEL_VERSION" $KERNEL_IMAGE_FLAGS $MICROCODE $IMAGE_GENERATION_FLAG "$IMAGE_PATH"
```

adding a `set -x` before it expands to

```
mkinitcpio -k 6.1.3-arch1-1 --kernelimage ''\''/usr/lib/modules/6.1.3-arch1-1/vmlinuz'\''' --microcode ''\''/boot/intel-ucode.img'\''' -U /boot/EFI/Linux/aee901b403f349d492561b8addecc2a8-6.1.3-arch1-1.efi
```

Because `MICROCODE` and `KERNEL_IMAGE_FLAGS` contain `'` which is taken literally:

```
$ shellcheck /usr/lib/kernel/install.d/50-mkinitcpio.install

In /usr/lib/kernel/install.d/50-mkinitcpio.install line 32:
MICROCODE="--microcode '$KERNEL_INSTALL_BOOT_ROOT/$ucode_name'"
^-----------^ SC2089 (warning): Quotes/backslashes will be treated literally. Rewrite using set/"$@" or functions.


In /usr/lib/kernel/install.d/50-mkinitcpio.install line 37:
KERNEL_IMAGE_FLAGS="--kernelimage '$KERNEL_IMAGE'"
^-------------^ SC2089 (warning): Quotes/backslashes will be treated literally. Rewrite using set/"$@" or functions.


In /usr/lib/kernel/install.d/50-mkinitcpio.install line 54:
mkinitcpio -k "$KERNEL_VERSION" $KERNEL_IMAGE_FLAGS $MICROCODE $IMAGE_GENERATION_FLAG "$IMAGE_PATH"
^-----------------^ SC2090 (warning): Quotes/backslashes in this variable will not be respected.
^-----------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
^--------^ SC2090 (warning): Quotes/backslashes in this variable will not be respected.

```


Additional info:
* package version(s)

```
$ kernel-install --version
kernel-install 252 (252.4-2-arch)
$ mkinitcpio --version
mkinitcpio 34

```

* config and/or log files etc.

```
$ cat /etc/kernel/install.conf
layout=uki
```

* link to upstream bug report, if any

Steps to reproduce:

* Follow configuration in https://wiki.archlinux.org/title/Unified_kernel_image#kernel-install
* Build kernel using `kernel-install`

Proposed patch:

```
:! diff -u /usr/lib/kernel/install.d/50-mkinitcpio.install /tmp/50-mkinitcpio.install
--- /usr/lib/kernel/install.d/50-mkinitcpio.install 2022-12-08 10:14:41.000000000 +0100
+++ /tmp/50-mkinitcpio.install 2023-01-08 20:00:38.969012186 +0100
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only

COMMAND="${1:?}"
@@ -25,16 +25,16 @@
for ucode_name in "intel-ucode.img" "amd-ucode.img" "intel-uc.img" "amd-uc.img" "early_ucode.cpio" "microcode.cpio"; do
if [ -e "/boot/$ucode_name" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Found microcode image /boot/$ucode_name"
- MICROCODE="--microcode '/boot/$ucode_name'"
+ MICROCODE=(--microcode "/boot/$ucode_name")
break
elif [ -e "$KERNEL_INSTALL_BOOT_ROOT/$ucode_name" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Found microcode image /boot/$ucode_name"
- MICROCODE="--microcode '$KERNEL_INSTALL_BOOT_ROOT/$ucode_name'"
+ MICROCODE=(--microcode "$KERNEL_INSTALL_BOOT_ROOT/$ucode_name")
break
fi
done

- KERNEL_IMAGE_FLAGS="--kernelimage '$KERNEL_IMAGE'"
+ KERNEL_IMAGE_FLAGS=(--kernelimage "$KERNEL_IMAGE")
;;
bls)
IMAGE_GENERATION_FLAG="-g"
@@ -47,9 +47,10 @@

case $COMMAND in
add)
- [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+ mkinitcpio -k $KERNEL_VERSION $KERNEL_IMAGE_FLAGS $MICROCODE $IMAGE_GENERATION_FLAG $IMAGE_PATH"
+ [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "+ mkinitcpio -k $KERNEL_VERSION ${KERNEL_IMAGE_FLAGS[*]} ${MICROCODE[*]} $IMAGE_GENERATION_FLAG $IMAGE_PATH"
#shellcheck disable=SC2046
- mkinitcpio -k "$KERNEL_VERSION" $KERNEL_IMAGE_FLAGS $MICROCODE $IMAGE_GENERATION_FLAG "$IMAGE_PATH"
+ set -x
+ mkinitcpio -k "$KERNEL_VERSION" "${KERNEL_IMAGE_FLAGS[@]}" "${MICROCODE[@]}" $IMAGE_GENERATION_FLAG "$IMAGE_PATH"
;;
remove)

```
This task depends upon

Closed by  Toolybird (Toolybird)
Sunday, 08 January 2023, 22:01 GMT
Reason for closing:  Upstream
Additional comments about closing:  Should be fixed in next release.
Comment by Toolybird (Toolybird) - Sunday, 08 January 2023, 20:44 GMT
All the mkinitcpio action is now over here [1]. Any chance you could file this issue there instead?

[1] https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio
Comment by Florian (nougad) - Sunday, 08 January 2023, 21:46 GMT
Thanks Toolybird for the link. Looks like the issue is already reported and fixed upstream: https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues/153 but not released yet.
Comment by Toolybird (Toolybird) - Sunday, 08 January 2023, 22:00 GMT
Ah, good to know. Thanks for looking into it.

Loading...