All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	klibc@zytor.com, Al Viro <viro@ftp.linux.org.uk>,
	hpa@zytor.com, miltonm@bga.com
Subject: [PATCH] initramfs: CPIO unpacking fix
Date: Fri, 07 Apr 2006 10:33:20 -0700	[thread overview]
Message-ID: <4436A260.9070603@zytor.com> (raw)
In-Reply-To: <20060217160621.99b0ffd4.mikey@neuling.org>


Unlink files, symlinks, FIFOs, devices etc. (except directories) before
writing them when extracting CPIOs.  This stops weird behaviour like:
  1) writing through symlinks created in earlier CPIOs. eg foo->bar in
     the first CPIO.  Having foo as a non-link in a subsequent CPIO,
     results in bar being written and foo remaining as a symlink.
  2) if the first version of file foo is larger than foo in a
     subsequent CPIO, we end up with a mix of the two.  ie. neither
     the first or second version of /foo.
  3) special files like devices, fifo etc. can't be overwritten in
     subsequent CPIOS.

With this, the kernel will more closely replicate
   for i in *.cpio; do cpio --extract --unconditional < $i ; done

This is a change but it's regarded as fixing broken functionality.

Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>

  init/initramfs.c |    3 +++
  1 files changed, 3 insertions(+)

Index: linux-2.6.15/init/initramfs.c
===================================================================
--- linux-2.6.15.orig/init/initramfs.c
+++ linux-2.6.15/init/initramfs.c
@@ -249,6 +249,7 @@ static int __init do_name(void)
  	if (dry_run)
  		return 0;
  	if (S_ISREG(mode)) {
+		sys_unlink(collected);
  		if (maybe_link() >= 0) {
  			wfd = sys_open(collected, O_WRONLY|O_CREAT, mode);
  			if (wfd >= 0) {
@@ -263,6 +264,7 @@ static int __init do_name(void)
  		sys_chmod(collected, mode);
  	} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
  		   S_ISFIFO(mode) || S_ISSOCK(mode)) {
+		sys_unlink(collected);
  		if (maybe_link() == 0) {
  			sys_mknod(collected, mode, rdev);
  			sys_chown(collected, uid, gid);
@@ -291,6 +293,7 @@ static int __init do_copy(void)
  static int __init do_symlink(void)
  {
  	collected[N_ALIGN(name_len) + body_len] = '\0';
+	sys_unlink(collected);
  	sys_symlink(collected + N_ALIGN(name_len), collected);
  	sys_lchown(collected, uid, gid);
  	state = SkipIt;


      parent reply	other threads:[~2006-04-07 17:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-16  7:37 [PATCH] Chained CPIOs writing to the same file bug Michael Neuling
     [not found] ` <20060217160621.99b0ffd4.mikey@neuling.org>
2006-02-21 23:45   ` [PATCH] initramfs: multiple CPIO unpacking fix Michael Neuling
2006-02-22  2:14     ` [klibc] " Jeff Bailey
2006-02-22  2:17       ` H. Peter Anvin
2006-03-22  6:12   ` [PATCH] initramfs: " Michael Neuling
2006-03-22  7:14     ` Jeff Garzik
2006-03-22 16:05       ` [klibc] " H. Peter Anvin
2006-03-22 22:23       ` Rob Landley
2006-03-22 23:22         ` Jeff Garzik
2006-04-07 17:33   ` H. Peter Anvin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4436A260.9070603@zytor.com \
    --to=hpa@zytor.com \
    --cc=akpm@osdl.org \
    --cc=klibc@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miltonm@bga.com \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.