Package: release.debian.org
Severity: normal
Tags: bookworm
X-Debbugs-Cc: initramfs-to...@packages.debian.org
Control: affects -1 + src:initramfs-tools
User: release.debian....@packages.debian.org
Usertags: pu

[ Reason ]
- Fix regressions to copy_file caused by the previous fixes.
- Fix missing reset drivers when using MODULES=dep to reduce the size
  of the initramfs.

[ Impact ]
- Some initramfs-tools hooks stopped working with the previous update
  (bugs #1082647, #1088959).
- Some systems may fail to boot with an initramfs built with
  MODULES=dep (bug #1027458).  The specific example there was a
  Raspberry Pi 4 using USB storage.

[ Tests ]
There are autopkgtest test cases for mkinitramfs.  A new test case has
been added to exercise all the corner cases of copy_file.  All of
these passed in Salsa CI.

[ Risks ]
There could be yet another corner case in copy_file that broke, but
this seems unlikely.

[ Checklist ]
  [X] *all* changes are documented in the d/changelog
  [X] I reviewed all changes and I approve them
  [X] attach debdiff against the package in (old)stable
  [X] the issue is verified as fixed in unstable

[ Changes ]

commit 37a6e9ecef1a1b6d00a7eeb70bf88e580ef6eb4e
Author: Ben Hutchings <b...@debian.org>
Date:   Thu Sep 26 18:01:04 2024 +0200

    hook-functions: Expand documentation of copy_exec and copy_file
    
    The documentation is currently a bit vague and doesn't mention
    creation of directories or symlinks at all.  Expand it to describe the
    current behaviour.
    
    Signed-off-by: Ben Hutchings <b...@debian.org>
    (cherry picked from commit 140c572128a09324f6f907ca8b3583c5f422e210)

commit 31c50bc71eb2a23c8713bb036d5492554b610dab
Author: Ben Hutchings <b...@debian.org>
Date:   Thu Sep 26 18:02:35 2024 +0200

    hook-functions: Restore copy_file's handling of target ending in slash
    
    Until recently, copy_file would treat a target ending in a slash as a
    target directory.  This was not intended behaviour, but had worked
    since at least v0.98.8.  It broke when I started using 'realpath' to
    canonicalise the target, which stripped the slash.
    
    Add a specific check for a trailing slash, and document that
    behaviour.
    
    Fixes: 984bdc7d727f ("hook-functions: copy_file: Canonicalise target 
filename")
    Closes: #1082647
    Signed-off-by: Ben Hutchings <b...@debian.org>
    (cherry picked from commit 765db0268082dfaf0110441894abf3dafeff258b)

commit d6d188335c0f24c836542179677e7bbf21f0a9b3
Author: Ben Hutchings <b...@debian.org>
Date:   Tue Oct 1 01:54:35 2024 +0200

    hook-functions: Exclude usr-merge symlinks in copy_file
    
    Currently if copy_file is invoked as:
    
        copy_file binary /lib/package/command /bin/command
    
    we will end up with:
    
        src=/lib/package/command
        target=/usr/bin/command
        link_target=/usr/lib/package/command
    
    and then we'll copy /lib/package/command to /usr/lib/package/command
    and make /usr/bin/command a symlink to it.  This is not what we used
    to do and not the most sensible behaviour.
    
    mkinitramfs already creates usr-merge symlinks in the initramfs so we
    don't need to worry about creating duplicates when source files are
    named via such symlinks on the host.  So if the host system is
    usr-merged, canonicalise source filenames that use the usr-merge
    symlinks before doing symlink detection.
    
    Fixes: b641a97705c1 ("hook_functions: Fix copy_file with source including a 
...")
    Signed-off-by: Ben Hutchings <b...@debian.org>
    (cherry picked from commit d5c24307ad032932ccb42929ca739c9d76745be7)
    Closes: #1088959

commit 38cf275d49b88ed84de6cd59a5bc94ec59f76555
Author: Ben Hutchings <b...@debian.org>
Date:   Tue Oct 1 02:14:29 2024 +0200

    autopkgtest: Add tests for copy_file function
    
    As the copy_file is quite complex and has had a number of bugs
    found (and introduced) recently, add an autopkgtest test case that
    exercises most of its functionality and the specific cases where
    bugs were reported.
    
    Signed-off-by: Ben Hutchings <b...@debian.org>
    (cherry picked from commit 6adf789818ca531d98e8709f7f6e9e27cc89a9ac)
    [For bookworm, also create ${CONFDIR}/hooks in test-common, which was
     done in upstream commit d75a58bab178.]

commit 065a03fc5fabdf3631b7e33e9ec737a0be4a2315
Author: Ben Hutchings <b...@debian.org>
Date:   Sun Mar 2 16:05:01 2025 +0100

    hook-functions: Add reset drivers when MODULES=dep
    
    Reset drivers are currently included when MODULES=most but not when
    MODULES=dep.  Since they are outside the device model, match them by
    module name not by driver class.
    
    Closes: #1027458
    Signed-off-by: Ben Hutchings <b...@debian.org>
    (cherry picked from commit 34f9acde87eab2ee645f48a98f886fa1f6f150eb)

commit adb54d6c3b4912c6f48d379dd826bc7b5dd14838
Author: Ben Hutchings <b...@debian.org>
Date:   Thu Apr 24 17:46:47 2025 +0200

    Releasing version 0.142+deb12u2.
    
    Signed-off-by: Ben Hutchings <b...@debian.org>

[ Other info ]

diff -Nru initramfs-tools-0.142+deb12u1/debian/changelog 
initramfs-tools-0.142+deb12u2/debian/changelog
--- initramfs-tools-0.142+deb12u1/debian/changelog      2024-08-25 
01:14:50.000000000 +0200
+++ initramfs-tools-0.142+deb12u2/debian/changelog      2025-04-24 
17:45:07.000000000 +0200
@@ -1,3 +1,16 @@
+initramfs-tools (0.142+deb12u2) bookworm; urgency=medium
+
+  * [37a6e9e] hook-functions: Expand documentation of copy_exec and copy_file
+  * [31c50bc] hook-functions: Restore copy_file's handling of target ending in
+    slash (Closes: #1082647)
+  * [d6d1883] hook-functions: Exclude usr-merge symlinks in copy_file
+    (Closes: #1088959)
+  * [38cf275] autopkgtest: Add tests for copy_file function
+  * [065a03f] hook-functions: Add reset drivers when MODULES=dep
+    (Closes: #1027458)
+
+ -- Ben Hutchings <b...@debian.org>  Thu, 24 Apr 2025 17:45:07 +0200
+
 initramfs-tools (0.142+deb12u1) bookworm; urgency=medium
 
   [ Ben Hutchings ]
diff -Nru 
initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/DEBIAN/control 
initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/control
--- initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/DEBIAN/control     
1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/control     
2025-04-07 02:35:46.000000000 +0200
@@ -0,0 +1,14 @@
+Package: initramfs-tools-bin
+Source: initramfs-tools
+Version: 0.147
+Architecture: amd64
+Maintainer: Debian kernel team <debian-ker...@lists.debian.org>
+Installed-Size: 44
+Depends: libc6 (>= 2.34)
+Replaces: initramfs-tools-core (<< 0.148~)
+Section: utils
+Priority: optional
+Multi-Arch: foreign
+Description: generic modular initramfs generator (binary tools)
+ This package contains the unmkinitramfs program that can be used to
+ unpack an initramfs image.
diff -Nru 
initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/DEBIAN/md5sums 
initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/md5sums
--- initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/DEBIAN/md5sums     
1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/DEBIAN/md5sums     
2025-04-07 02:35:46.000000000 +0200
@@ -0,0 +1,4 @@
+c05a01a454bb7161e6830f3607fabc5b  usr/bin/unmkinitramfs
+8d0a2bf581f6fd4edfa441540b7912b6  
usr/share/doc/initramfs-tools-bin/changelog.gz
+e55a2a32242cc00998ca3901aea7d09d  usr/share/doc/initramfs-tools-bin/copyright
+7803e085611c2fec57709f13feeb38f4  usr/share/man/man8/unmkinitramfs.8.gz
Binary files 
/var/tmp/P5777TpdAd/initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/usr/bin/unmkinitramfs
 and 
/var/tmp/PXQjr3JlcD/initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/bin/unmkinitramfs
 differ
Binary files 
/var/tmp/P5777TpdAd/initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/changelog.gz
 and 
/var/tmp/PXQjr3JlcD/initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/changelog.gz
 differ
diff -Nru 
initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/copyright
 
initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/copyright
--- 
initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/copyright
        1970-01-01 01:00:00.000000000 +0100
+++ 
initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/doc/initramfs-tools-bin/copyright
        2025-03-16 14:53:21.000000000 +0100
@@ -0,0 +1,28 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Source: https://salsa.debian.org/kernel-team/initramfs-tools
+
+Files: *
+Copyright: 2005 - 2011 maximilian attems <m...@debian.org>
+           2005 Jeff Bailey <jbai...@ubuntu.com>
+           2005 - 2007 David Härdeman <da...@hardeman.nu>
+           2008 - 2010 Martin Michlmayr <t...@cyrius.com>
+           2007 - 2011 Michael Prokop <m...@debian.org>
+           2005 - 2009 Scott James Remnant <sc...@ubuntu.com>
+           2009 - 2024 Ben Hutchings <b...@debian.org>
+           2018 - 2024 Benjamin Drung <bdr...@debian.org>
+License: GPL-2+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ .
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ .
+ You should have received a copy of the GNU General Public License
+ along with this package; if not, see 'https://www.gnu.org/licenses/'.
+Comment:
+ On Debian systems, the full text of the GNU General Public License
+ version 2 can be found in the file '/usr/share/common-licenses/GPL-2'.
Binary files 
/var/tmp/P5777TpdAd/initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin/usr/share/man/man8/unmkinitramfs.8.gz
 and 
/var/tmp/PXQjr3JlcD/initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin/usr/share/man/man8/unmkinitramfs.8.gz
 differ
diff -Nru initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin.substvars 
initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin.substvars
--- initramfs-tools-0.142+deb12u1/debian/initramfs-tools-bin.substvars  
1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-0.142+deb12u2/debian/initramfs-tools-bin.substvars  
2025-04-07 02:35:46.000000000 +0200
@@ -0,0 +1,3 @@
+shlibs:Depends=libc6 (>= 2.34)
+misc:Depends=
+misc:Pre-Depends=
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/control 
initramfs-tools-0.142+deb12u2/debian/tests/control
--- initramfs-tools-0.142+deb12u1/debian/tests/control  2024-08-22 
20:38:38.000000000 +0200
+++ initramfs-tools-0.142+deb12u2/debian/tests/control  2025-04-24 
17:40:53.000000000 +0200
@@ -21,3 +21,7 @@
 Tests: amd64-panic-shell
 Depends: @, qemu-system-x86, linux-image-amd64 | linux-image-generic:amd64, 
klibc-utils, genext2fs, zstd
 Restrictions: skip-not-installable
+
+Tests: copy-file
+Restrictions: needs-root, breaks-testbed, skip-not-installable, superficial, 
allow-stderr
+Depends: linux-image-generic, zstd, @
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/copy-file 
initramfs-tools-0.142+deb12u2/debian/tests/copy-file
--- initramfs-tools-0.142+deb12u1/debian/tests/copy-file        1970-01-01 
01:00:00.000000000 +0100
+++ initramfs-tools-0.142+deb12u2/debian/tests/copy-file        2025-04-24 
17:40:53.000000000 +0200
@@ -0,0 +1,95 @@
+#!/bin/sh -e
+
+SUPPORTED_FLAVOURS='alpha-smp amd64 arm64 armmp parisc loong64 m68k powerpc64 
powerpc64le riscv64 s390x sparc64-smp generic'
+. debian/tests/test-common
+
+SOURCEDIR=/usr/lib/initramfs-test-copy-file
+
+mkdir -p "${SOURCEDIR}/dir1"
+echo -n 1 >"${SOURCEDIR}/dir1/file1"
+ln -s dir1 "${SOURCEDIR}/dir2"
+echo -n 22 >"${SOURCEDIR}/file2"
+echo -n 333 >"${SOURCEDIR}/file3"
+
+cat >>"${CONFDIR}/initramfs.conf" <<EOF
+MODULES=list
+BUSYBOX=n
+EOF
+
+cat >"${CONFDIR}/hooks/initramfs-test-copy-file" <<EOF
+#!/bin/sh -e
+
+test "\$1" = prereqs && exit
+
+. /usr/share/initramfs-tools/hook-functions
+
+set -x
+
+# Source named via directory symlink should be symlinked (#1076539)
+copy_file test "${SOURCEDIR}/dir1/file1"
+copy_file test "${SOURCEDIR}/dir2/file1"
+
+# Usr-merged target must be recognised with or without leading slash
+# (#1079276)
+copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/file3"
+
+# Target that exists as directory must be treated as directory
+mkdir "\${DESTDIR}/${SOURCEDIR}/dir3"
+copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir3"
+
+# Target with trailing slash must be treated as directory (#1082647)
+copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir4/"
+
+# Check combination of #1079276 and #1082647 cases
+copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/dir5/"
+EOF
+chmod +x "${CONFDIR}/hooks/initramfs-test-copy-file"
+
+build_initramfs
+lsinitramfs -l "${INITRAMFS}" >"${AUTOPKGTEST_TMP}/listing"
+
+rc=0
+
+check_file() {
+       local ftype="$1"
+       local name="$2"
+       local extra="$3"
+       local size_re='[0-9]*'
+       local tail_re=''
+
+       case "$ftype" in
+       -)
+               # Regular file: extra is size
+               size_re="${extra}"
+               ;;
+       l)
+               # Symbolic link: extra is link text
+               size_re="${#extra}"
+               tail_re=" -> $(printf %s "$extra" | sed 's/\./\\./g')"
+               ;;
+       esac
+
+       if ! grep -q "^${ftype}......... *[0-9]* root *root *${size_re} 
............ ${name#/}${tail_re}$" "${AUTOPKGTEST_TMP}/listing"; then
+               echo >&2 "E: $name did not get copied correctly"
+               rc=1
+       fi
+}
+
+# Check that files, directories, and symlinks were created as expected
+check_file d ${SOURCEDIR}/dir1       -
+check_file - ${SOURCEDIR}/dir1/file1 1
+check_file d ${SOURCEDIR}/dir2       -
+check_file l ${SOURCEDIR}/dir2/file1 ../dir1/file1
+check_file - ${SOURCEDIR}/file3      3
+check_file d ${SOURCEDIR}/dir3       -
+check_file - ${SOURCEDIR}/dir3/file2 2
+check_file d ${SOURCEDIR}/dir4       -
+check_file - ${SOURCEDIR}/dir4/file2 2
+check_file - ${SOURCEDIR}/dir5/file3 3
+
+if [ $rc -ne 0 ]; then
+       echo "I: Initramfs contents:"
+       cat "$AUTOPKGTEST_TMP/listing"
+fi
+
+exit $rc
diff -Nru initramfs-tools-0.142+deb12u1/debian/tests/test-common 
initramfs-tools-0.142+deb12u2/debian/tests/test-common
--- initramfs-tools-0.142+deb12u1/debian/tests/test-common      2024-08-22 
21:30:14.000000000 +0200
+++ initramfs-tools-0.142+deb12u2/debian/tests/test-common      2025-04-24 
17:40:53.000000000 +0200
@@ -21,6 +21,7 @@
 CONFDIR="$(mktemp -d)"
 cp conf/initramfs.conf "${CONFDIR}/initramfs.conf"
 echo "RESUME=none" >>"${CONFDIR}/initramfs.conf"
+mkdir "${CONFDIR}/hooks"
 touch "${CONFDIR}/modules"
 mkdir "${CONFDIR}/scripts"
 
diff -Nru initramfs-tools-0.142+deb12u1/hook-functions 
initramfs-tools-0.142+deb12u2/hook-functions
--- initramfs-tools-0.142+deb12u1/hook-functions        2024-08-22 
21:30:14.000000000 +0200
+++ initramfs-tools-0.142+deb12u2/hook-functions        2025-04-24 
17:40:56.000000000 +0200
@@ -153,12 +153,28 @@
        done
 }
 
-# $1 = file type (for logging)
-# $2 = file to copy to initramfs
-# $3 (optional) Name for the file on the initramfs
-# Location of the image dir is assumed to be $DESTDIR
-# If the target exists, we leave it and return 1.
-# On any other error, we return >1.
+# Copy a file to the initramfs:
+# $1 = file type, for debug logging
+# $2 = source file name
+# $3 (optional) = target file or directory name in the initramfs
+#
+# * If the target is not specified, it defaults to the source file
+#   name.
+# * If the target is specified and exists as a directory under
+#   $DESTDIR or ends in a slash, the basename of the source is
+#   appended to it.
+#
+# The target file's containing directories are created if necessary.
+#
+# If the source file name includes a symlink, other than usr-merge
+# symlinks, and the canonical name of the source is not the same as
+# the target, the source file is copied to its canonical name in the
+# initramfs and the target is created as a symlink.
+#
+# Returns:
+# * If the file was copied successfully, 0
+# * If the target file already existed, 1
+# * On error, >1
 copy_file() {
        local type src target link_target
 
@@ -168,7 +184,7 @@
 
        [ -f "${src}" ] || return 2
 
-       if [ -d "${DESTDIR}/${target}" ]; then
+       if [ -d "${DESTDIR}/${target}" ] || [ "${target%/}" != "$target" ]; then
                target="${target}/${src##*/}"
        fi
 
@@ -176,7 +192,12 @@
        # will work
        target="$(realpath -ms "/${target}")" || return 2
 
-       # Canonicalise usr-merged target directories
+       # Canonicalise usr-merged directories
+       case "${src}" in
+       /bin/* | /lib* | /sbin/*)
+               [ "$(readlink -f /bin)" = /usr/bin ] && src="/usr${src}"
+               ;;
+       esac
        case "${target}" in
        /bin/* | /lib* | /sbin/*) target="/usr${target}" ;;
        esac
@@ -219,10 +240,16 @@
        cp -pP "${src}" "${DESTDIR}/${target}" || return $(($? + 1))
 }
 
-# $1 = executable/shared library to copy to initramfs, with dependencies
-# $2 (optional) Name for the file on the initramfs
-# Location of the image dir is assumed to be $DESTDIR
-# We never overwrite the target if it exists.
+# Copy an executable or shared library to the initramfs:
+# $1 = source file name
+# $2 (optional) = target file or directory name in the initramfs
+#
+# The source and all its shared library dependencies are copied
+# using copy_file.
+#
+# Returns:
+# * If the files were copied successfully or already exited, 0
+# * On error, >0
 copy_exec() {
        local src target x nonoptlib ret
 
@@ -528,11 +555,12 @@
                class_add_modules "$class"
        done
 
-       # clk, USB-PHY and pinctrl devices are outside the device model (!) so
-       # match loaded modules by name
+       # clk, USB-PHY, pinctrl and reset devices are outside the device
+       # model (!) so match loaded modules by name
        add_loaded_modules 'clk[-_]*'
        add_loaded_modules 'phy[-_]*'
        add_loaded_modules 'pinctrl[-_]*'
+       add_loaded_modules 'reset[-_]*'
 
        # Sys walk keyboards.  We identify keyboards as input devices
        # that can generate at least key events 1-31; udev has the

Attachment: signature.asc
Description: PGP signature

Reply via email to