Skip to content

Commit

Permalink
[PATCH] initramfs: fix CPIO hardlink check
Browse files Browse the repository at this point in the history
Copy the filenames of hardlinks when inserting them into the hash, since
the "name" pointer may point to scratch space (name_buf).  Not doing so
results in corruption if the scratch space is later overwritten: the wrong
file may be hardlinked, or, if the scratch space contains garbage, the link
will fail and a 0-byte file will be created instead.

Signed-off-by: Mark Huang <mlhuang@cs.princeton.edu>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Mark Huang authored and Linus Torvalds committed May 15, 2006
1 parent 698d070 commit 6a050da
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ static void __init free(void *where)

/* link hash */

#define N_ALIGN(len) ((((len) + 1) & ~3) + 2)

static __initdata struct hash {
int ino, minor, major;
struct hash *next;
char *name;
char name[N_ALIGN(PATH_MAX)];
} *head[32];

static inline int hash(int major, int minor, int ino)
Expand Down Expand Up @@ -57,7 +59,7 @@ static char __init *find_link(int major, int minor, int ino, char *name)
q->ino = ino;
q->minor = minor;
q->major = major;
q->name = name;
strcpy(q->name, name);
q->next = NULL;
*p = q;
return NULL;
Expand Down Expand Up @@ -133,8 +135,6 @@ static inline void eat(unsigned n)
count -= n;
}

#define N_ALIGN(len) ((((len) + 1) & ~3) + 2)

static __initdata char *collected;
static __initdata int remains;
static __initdata char *collect;
Expand Down

0 comments on commit 6a050da

Please sign in to comment.