Package: firmware-b43-installer Version: 1:019-2 Severity: important Tags: patch
I'm fearful this should be marked "serious", rather than "important". firmware-b43-installer's handling of /lib/firmware/b43 is very brittle. Notably it doesn't register the contents of the directory with `dpkg`. Worse, during *postrm* it does an `rm -rf /lib/firmware/b43`. As a result, even a package that merely conflicts with firmware-b43-installer will be broken since the rm will be done *after* that package is installed. The attached patch attempts to remedy this in two ways. First, it creates a file in /lib/firmware/b43 cataloging the firmware files that have been installed. Second, during removal the list of files is run past `dpkg-query -S` to ensure nothing taken over by other packages is removed. A better solution is bug #819136. Making the firmware into a package which can then be installed using `dpkg` and thus removal is safely handled. -- (\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | ehem+sig...@m5p.com PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
>From 12387d36ac959d6355af15103c13681afda56298 Mon Sep 17 00:00:00 2001 From: Elliott Mitchell <ehem+deb...@drgnwing.com> Date: Thu, 31 Mar 2016 17:33:23 -0700 Subject: [PATCH 01/10] Implement catalog of firmware files installed This allows for targeted removal of downloaded firmware files, instead of needing to remove the whole directory. Also pass paths to be removed through `dpkg-query -S`, increasing safety of removals. This is much safer and allows for other features. --- debian/firmware-b43-installer.postinst | 33 +++++++++++++++++++++++++------- debian/firmware-b43-installer.postrm | 15 --------------- debian/firmware-b43-installer.prerm | 28 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 22 deletions(-) delete mode 100644 debian/firmware-b43-installer.postrm create mode 100644 debian/firmware-b43-installer.prerm diff --git a/debian/firmware-b43-installer.postinst b/debian/firmware-b43-installer.postinst index 0d9c0e1..d8794c2 100644 --- a/debian/firmware-b43-installer.postinst +++ b/debian/firmware-b43-installer.postinst @@ -25,16 +25,35 @@ fi if ! wget --timeout=60 http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2 ; then echo "Some problem occurred during the firmware download. Please check your internet connection." exit 0 - else - if [ -d /lib/firmware/b43 ]; then - echo "Deleting old extracted firmware..." - rm -rf /lib/firmware/b43 - fi fi tar xvjf broadcom-wl-5.100.138.tar.bz2 cd broadcom-wl-5.100.138/linux -b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" wl_apsta.o +if [ -d "${FIRMWARE_INSTALL_DIR}/b43" ]; then + echo "Deleting old extracted firmware..." + xargs -r -0 -a "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" dpkg-query -S 2>&1 1>/dev/null | cut -d/ -f4- | xargs rm -- + rm "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" +fi +mkdir "${FIRMWARE_INSTALL_DIR}/b43" || true +catalog="${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" +retcode=0 +b43-fwcutter -w "${FIRMWARE_INSTALL_DIR}" wl_apsta.o | while read line +do echo "${line}" + file="${line#Extracting }" + if [ "${file}" != "${line}" ] + then if [ "${retcode}" -ne 0 ] + then rm "${FIRMWARE_INSTALL_DIR}/${file}" + + elif [ -z "${FIRMWARE_INSTALL_DIR}/${file}" ] || \ + ! printf %s/%s\\x00 "${FIRMWARE_INSTALL_DIR}" "${file}" >> "${catalog}" + then echo "$0: Failed during extraction of ${file} from ${WL_APSTA}" 1>&2 + echo "$0: Warning, manual removal/cleaning of ${FIRMWARE_INSTALL_DIR}/b43 may be needed!" 1>&2 + rm "${FIRMWARE_INSTALL_DIR}/${file}" + retcode=1 + fi + fi +done rm -rf $tmp +[ ${retcode} -eq 0 ] || exit ${retcode} } # check environment @@ -48,7 +67,7 @@ if [ "$(stat -c %d/%i /)" != "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; echo "No chroot environment found. Starting normal installation" fi - + # check kernel version diff --git a/debian/firmware-b43-installer.postrm b/debian/firmware-b43-installer.postrm deleted file mode 100644 index 339d140..0000000 --- a/debian/firmware-b43-installer.postrm +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -set -e - -if [ "$1" = purge ] || [ "$1" = remove ]; then - - if [ -d /lib/firmware/b43 ]; then - echo "Deleting old extracted firmware..." - rm -rf /lib/firmware/b43/* - fi -fi - -#DEBHELPER# - -exit 0 diff --git a/debian/firmware-b43-installer.prerm b/debian/firmware-b43-installer.prerm new file mode 100644 index 0000000..535ffd2 --- /dev/null +++ b/debian/firmware-b43-installer.prerm @@ -0,0 +1,28 @@ +#!/bin/sh + +######################################################################### +#$Id$ # +######################################################################### + +FIRMWARE_INSTALL_DIR="/lib/firmware" + +######################################################################### +# stable sections below, not updated for firmware updates # +######################################################################### + + +set -e + +if [ "$1" = purge ] || [ "$1" = remove ]; then + if [ -s "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" ]; then + echo "$0: Deleting installed firmware..." 1>&2 + xargs -r -0 -a "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43-installer.catalog" dpkg-query -S 2>&1 1>/dev/null | cut -d/ -f4- | xargs rm -- + rm "${FIRMWARE_INSTALL_DIR}/b43/firmware-b43.catalog" + rmdir "${FIRMWARE_INSTALL_DIR}/b43" || exit 0 + fi +fi + +#DEBHELPER# + +exit 0 + -- 1.7.10.4