linux-image postinst matches header_postinst_hook for postinst_hook incorrectly

Bug #125816 reported by Matt Domsch
6
Affects Status Importance Assigned to Milestone
kernel-package (Ubuntu)
Fix Released
High
Unassigned
Feisty
Won't Fix
Undecided
Unassigned
linux-source-2.6.20 (Ubuntu)
Fix Released
High
Ben Collins
Feisty
Invalid
Undecided
Unassigned
linux-source-2.6.22 (Ubuntu)
Fix Released
Medium
Unassigned
Feisty
Invalid
Undecided
Unassigned

Bug Description

Binary package hint: linux-image-2.6-686

From <email address hidden> Fri Jul 13 11:12:48 2007
Date: Fri, 13 Jul 2007 11:12:48 -0500
From: Matt Domsch <email address hidden>
To: "Brinkman, Alexander" <email address hidden>
Cc: <email address hidden>, Ben Collins <email address hidden>
Subject: Re: ANNOUNCE: dkms 2.0.17
Mail-Followup-To: "Brinkman, Alexander" <email address hidden>,
        <email address hidden>, Ben Collins <email address hidden>
References: <email address hidden>
Status: RO

On Fri, Jul 13, 2007 at 11:06:42AM +0200, Brinkman, Alexander wrote:
>
> It would seem that the new Ubuntu stuff that was introduced still has a
> little bug in it. Or better said: probably DKMS is ok, but the hook
> mechanism is not working correctly anymore.
>
> With DKMS 2.0.17 the file /etc/kernel-img.conf now reads:
> do_symlinks = yes
> relative_links = yes
> do_bootloader = no
> do_bootfloppy = no
> do_initrd = yes
> link_in_boot = no
> postinst_hook = /sbin/update-grub
> postrm_hook = /sbin/update-grub
> header_postinst_hook = /etc/kernel/postinst.d/dkms
>
> When this last line is in the config file the previous lines are not
> called anymore (the postinst and postrm hooks). So update-grub is not
> executed anymore on a kernel update (or remove), which is not good.
>
> It can fairly easily be fixed by adding a link in the
> /etc/kernel/postinst.d directory to /sbin/update-grub.
>
> But I'm not really sure why the hooks in the config file are not used
> anymore. Perhaps because the /etc/kernel/* directories were empty
> before, and now there's a dkms script in them (which would maybe
> overrule the postinst/postrm_hook entries in the config file?). However,
> when removing the last line from the kernel-img.conf file, update-grub
> is again called upon installation of a new kernel... very confusing...

Doh. See this in /var/lib/dpkg/info/linux-image-2.6.20-16-generic.postinst:

      $postinst_hook = "$1" if /postinst_hook\s*=\s*(\S+)/ig;

Notice the test. It's matching postinst_hook on the
header_postinst_hook line from the /etc/kernel-img.conf file, so it's
overriding the call to update-grub with another call to dkms.

That is a bug in the linux-image scripts. Will file as such.

I guess that also means we can't rely on that to hook in DKMS for a
while... :-( And we'll have to respin DKMS to remove that...

Revision history for this message
Matt Domsch (matt-domsch) wrote :

bumping to High; as we need to figure out how to deal with this in our FI images.

Changed in redfish:
importance: Undecided → High
Revision history for this message
Michael Morgan (mikmorg) wrote :

So there are three packages which use perl regexp to do string matching, to read the config file. The following files need to be fixed, and I am currently looking into patching the respective git repositories (at least one being git://kernel.ubuntu.com/ubuntu/ubuntu-feisty.git). If anyone can verify that this works before I send a kernel patch, I would appreciate it.

 linux-headers-2.6.20-16.postinst
 linux-image-2.6.20-16-generic.config
 linux-image-2.6.20-16-generic.postinst
 linux-image-2.6.20-16-generic.postrm
 linux-image-2.6.20-16-generic.preinst
 linux-image-2.6.20-16-generic.prerm
 linux-source-2.6.20.postinst

Revision history for this message
Michael Morgan (mikmorg) wrote :

I have attached a patch against the files that need fixing. This needs to be fixed in make-kpkg.

Changed in kernel-package:
status: New → In Progress
Revision history for this message
Tim Gardner (timg-tpi) wrote :

Michael,

Your patch needs to be against the package files:

dget http://archive.ubuntu.com/ubuntu/pool/main/k/kernel-package/kernel-package_10.065ubuntu5.dsc
dpkg-source -x kernel-package_10.065ubuntu5.dsc

Please develop a patch against the appropriate files in kernel-package-10.065ubuntu5/kernel.

I'm not that familiar with perl, but it looks like your intent is to change the expression so that it exactly matches the token. Correct?

Revision history for this message
Michael Morgan (mikmorg) wrote :

Ok, here is the new patch against kernel-package.

Revision history for this message
Michael Morgan (mikmorg) wrote :

Oops, I noticed I left an artifact in the last patch. Here it is, revised.

Tim Gardner (timg-tpi)
Changed in kernel-package:
assignee: nobody → timg-tpi
Revision history for this message
Tim Gardner (timg-tpi) wrote :

kernel-package_10.065ubuntu6 will soon find its way into Feisty proposed. I'll check Gutsy for the same problem.

Is there a reason this bug is marked private?

Changed in kernel-package:
importance: Undecided → High
Tim Gardner (timg-tpi)
Changed in redfish:
assignee: nobody → timg-tpi
status: New → In Progress
Revision history for this message
Tim Gardner (timg-tpi) wrote :

Package components in chinstrap.ubuntu.com:/home/rtg/kernel-package/feisty/kernel-package_10.065ubuntu6.dsc

See attached debdiff.

Revision history for this message
Martin Pitt (pitti) wrote :

Patch looks sane, approved for SRU. However, can you please improve the changelog a bit? It should point out the effect and impact, too, not just a vague description of the fix. Thank you!

Revision history for this message
Tim Gardner (timg-tpi) wrote :

I refreshed chinstrap.ubuntu.com:/home/rtg/kernel-package/feisty/kernel-package_10.065ubuntu6.dsc with the updated changelog.

Revision history for this message
Martin Pitt (pitti) wrote :

I sponsored the upload and accepted it into feisty-proposed. Please go ahead with QA testing according to https://wiki.ubuntu.com/StableReleaseUpdates, and please add a recipe for reproducting the bug (and testing the error) for the verification team.

Changed in kernel-package:
status: In Progress → Fix Committed
Revision history for this message
Martin Pitt (pitti) wrote :

Closing unnecessary Ubuntu task.

Revision history for this message
Michael Vogt (mvo) wrote :

Please add a recipe for reproducting the bug (and testing the error) so that we can sru-verifiy the fix and get it to feisty-updates.

Revision history for this message
Tim Gardner (timg-tpi) wrote :

It is difficult to reproduce this bug without using a Dell DKMS package that affects the kernel. The current recovery media from Dell no longer uses kernel-package. I suspect the fix for this bug has been incorporated into DKMS. The testing that I have done for stock Feisty installs has merely verified that no regressions were introduced.

Revision history for this message
Matt Domsch (matt-domsch) wrote :

you can install http://linux.dell.com/dkms/debian/dkms_2.0.17-1_all.deb which will demonstrate the problem on kernels produced by the older kernel-package, upgrade the kernel to one built with the newer kernel-package (with the above patch applied) and see that it no longer demonstrates the problem.

The demonstrated problem is that when installing a kernel built with the broken kernel-package, DKMS is invoked twice - once by post_hook and once by /etc/kernel/postinst.d/dkms; but update-grub is _never_ called from postinst_hook (because postinst_hook was overwritten with the value from header_postinst_hook, namely invoking dkms). DKMS should only be invoked once (from /etc/kernel/postinst.d/dkms) and update-grub should be invoked from postinst_hook.

I'm working on packaging newer copies of DKMS, but am torn; should it try to use header_postinst_hook at all? If it does, then it's subject to this breakage. If it does not, then there's a chance that the ordering of dpkg installs of new linux-image and linux-headers packages will cause the dkms_autoinstaller to fail. I need the dkms_autoinstaller to be run after both linux-image and linux-headers are installed. To guarantee this, I've been hooking both of those package's postinst hooks, so regardless of install order dkms_autoinstaller is run after they're both installed.

I'm open to advice on this point.

Revision history for this message
Matt Domsch (matt-domsch) wrote :

I'm not convinced this is fixed in Gutsy either. From the kernel in git: ubuntu-gutsy/debian/control-scripts/postinst

      $postinst_hook = "$1" if /postinst_hook\s*=\s*(\S+)/ig;
      $postrm_hook = "$1" if /postrm_hook\s*=\s*(\S+)/ig;
      $preinst_hook = "$1" if /preinst_hook\s*=\s*(\S+)/ig;
      $prerm_hook = "$1" if /prerm_hook\s*=\s*(\S+)/ig;

This has not had the patch from above applied to it.

Revision history for this message
Martin Pitt (pitti) wrote :

Tim, can you please fix the gutsy package as well? Thanks!

Revision history for this message
Tim Gardner (timg-tpi) wrote :

Martin, Ben says Gutsy only uses kernel-package for custom compiled kernels, e.g., builds using make-kpg. He will correct the regular expressions in the Gutsy debian/control-scripts/* before the next upload. In the meantime I'll have a Gutsy kernel-package prepared for upload soon.

Revision history for this message
Tim Gardner (timg-tpi) wrote :

Martin, Gutsy kernel-package components in chinstrap.ubuntu.com:/home/rtg/kernel-package/gutsy/kernel-package_11.001ubuntu1.dsc

Revision history for this message
Ben Collins (ben-collins) wrote :

Committed to ubuntu-gutsy.git. New headers-postinst script with appropriate portions of this patch applied.

Changed in linux-source-2.6.20:
assignee: nobody → ben-collins
importance: Undecided → High
status: New → Fix Committed
Changed in dell:
status: In Progress → Fix Committed
Revision history for this message
Jose De la Rosa (jose-de-la-rosa) wrote :

Ben:

Has this fix been released?

Revision history for this message
Matt Domsch (matt-domsch) wrote :

gutsy kernel UBUNTU: release Ubuntu-2.6.22-14.46

has a correct headers-postinst script (thank you!), however it does not have a correct debian/control-scripts/postinst script. It's still missing all the ^ characters in these (examples here).

     $postinst_hook = "$1" if /postinst_hook\s*=\s*(\S+)/ig;
      $postrm_hook = "$1" if /postrm_hook\s*=\s*(\S+)/ig;
      $preinst_hook = "$1" if /preinst_hook\s*=\s*(\S+)/ig;
      $prerm_hook = "$1" if /prerm_hook\s*=\s*(\S+)/ig;

Revision history for this message
Matt Domsch (matt-domsch) wrote :

patch

Revision history for this message
Tim Gardner (timg-tpi) wrote :

Gutsy commit f865d06fb2754d444ef7ba25f08666b8a155ca32

Changed in linux-source-2.6.22:
importance: Undecided → Medium
milestone: none → ubuntu-7.10-rc
status: Confirmed → Fix Committed
Revision history for this message
Matt Domsch (matt-domsch) wrote :

This fix did not make it into Gutsy gold, but will be included in any future kernel update for Gutsy, which is where it would be needed (and executed) anyhow. DKMS 2.0.17.4-0ubuntu2 in gutsy/universe is not affected by it as it does not use the broken hooks anymore, so that's good.

Tim Gardner (timg-tpi)
Changed in kernel-package:
assignee: timg-tpi → nobody
status: Fix Committed → Fix Released
Changed in dell:
assignee: timg-tpi → nobody
status: Fix Committed → Fix Released
Revision history for this message
Phillip Lougher (phillip-lougher) wrote :

linux-source-2.6.22 (2.6.22-14.47) gutsy-security; urgency=low

  [Security]

  * wait_task_stopped: Check p->exit_state instead of TASK_TRACED
    (CVE-2007-5500)
  * [TCP]: Make sure write_queue_from does not begin with NULL ptr
    (CVE-2007-5501)
  * [IEEE80211]: avoid integer underflow for runt rx frames (CVE-2007-4997)
  * [JFFS2] Fix ACL vs. mode handling. (CVE-2007-4849)
  * minixfs: limit minixfs printks on corrupted dir i_size (CVE-2006-6058)
  * NFS: Fix the mount regression

  [Fabio Massimo Di Nitto]

  * fix DLM regression

  [Tim Gardner]

  * linux-image postinst matches header_postinst_hook for postinst_hook
    incorrectly
    - LP: #125816

  [Upstream Kernel Changes]

  * [SPARC64]: Fix bugs in SYSV IPC handling in 64-bit processes.
  * [SPARC64]: Fix register usage in xor_raid_4().
  * [NIU]: Fix write past end of array in niu_pci_probe_sprom().
  * [NIU]: getting rid of __ucmpdi2 in niu.o
  * [SPARC64]: Do not use alloc_bootmem*low().
  * [SPARC64]: Fix bogus '&' conditinal in set_rtc_mmss().
  * [FUTEX]: Fix address computation in compat code.
  * [NIU]: Fix link LED handling.
  * [SPARC64]: Fix memory controller register access when non-SMP.
  * [SPARC64]: Fix endless loop in cheetah_xcall_deliver().
  * [SPARC64]: Fix two kernel linear mapping setup bugs.

 -- Phillip Lougher <email address hidden> Thu, 13 Dec 2007 23:57:58 +0000

Changed in linux-source-2.6.22:
status: Fix Committed → Fix Released
Changed in linux-source-2.6.20:
status: Fix Committed → Fix Released
Revision history for this message
Marcel Stimberg (marcelstimberg) wrote : Failed to install kernel update

The linux-image update of today failed to install via the update-manager on my up-to-date gutsy installation.
It states that the post-installation script of linux-image-2.6.22-14-generic and linux-image-2.6.22-14-generic exited with value 1.

When running the upgrade command from the terminal, I get the following messages (The output also mentioned to change the /etc/kernel-img.conf, which I did before running the command with the output stated here):
------------
Setting up linux-image-2.6.22-14-386 (2.6.22-14.47) ...
Running depmod.
update-initramfs: Generating /boot/initrd.img-2.6.22-14-386
Not updating initrd symbolic links since we are being updated/reinstalled
(2.6.22-14.46 was configured last, according to dpkg)
Not updating image symbolic links since we are being updated/reinstalled
(2.6.22-14.46 was configured last, according to dpkg)
Running postinst hook script /usr/sbin/update-grub.
Searching for GRUB installation directory ...
No GRUB directory found. To create a template run 'mkdir /boot/grub' first. To install grub, install it manually or try the 'grub-install' command. ### Warning, grub-install is used to change your MBR. ###

User postinst hook script [/usr/sbin/update-grub] exited with value 1
dpkg: error processing linux-image-2.6.22-14-386 (--configure):
 subprocess post-installation script returned error exit status 1
------------

It seems, that my grub directory disappeared... After manually creating /boot/grub, the installation went fine (regenerating the menu.lst)

Revision history for this message
Martin Pitt (pitti) wrote :

This still has a pending kernel-package in feisty-proposed. Can someone please test this and confirm that it fixes the issue and still works otherwise? Or tell me to just remove it from -proposed because it is obsolete? Thank you!

Changed in kernel-package:
status: New → Fix Committed
Changed in linux-source-2.6.20:
status: New → Invalid
Changed in linux-source-2.6.22:
status: New → Invalid
Revision history for this message
Tim Gardner (timg-tpi) wrote :

Martin - It looks like with the fixes in DKMS and kernel that kernel-packages in Gutsy proposed is no longer relevant. I think it is safe to remove.

Revision history for this message
Martin Pitt (pitti) wrote :

I removed kernel-package from feisty-proposed.

Changed in kernel-package:
status: Fix Committed → Won't Fix
Revision history for this message
Launchpad Janitor (janitor) wrote : Kernel team bugs

Per a decision made by the Ubuntu Kernel Team, bugs will longer be assigned to the ubuntu-kernel-team in Launchpad as part of the bug triage process. The ubuntu-kernel-team is being unassigned from this bug report. Refer to https://wiki.ubuntu.com/KernelTeamBugPolicies for more information. Thanks.

Changed in somerville:
importance: Undecided → High
status: New → Fix Released
no longer affects: dell
Revision history for this message
Timothy R. Chavez (timrchavez) wrote :

The bug task for the somerville project has been removed by an automated script. This bug has been cloned on that project and is available here: https://bugs.launchpad.net/bugs/1305721

no longer affects: somerville
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.