Commit 6a050da45b5d855b48b057446847ff1542977b52

Authored by Mark Huang
Committed by Linus Torvalds
1 parent 698d070746

[PATCH] initramfs: fix CPIO hardlink check

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>

Showing 1 changed file with 4 additions and 4 deletions Side-by-side Diff

... ... @@ -26,10 +26,12 @@
26 26  
27 27 /* link hash */
28 28  
  29 +#define N_ALIGN(len) ((((len) + 1) & ~3) + 2)
  30 +
29 31 static __initdata struct hash {
30 32 int ino, minor, major;
31 33 struct hash *next;
32   - char *name;
  34 + char name[N_ALIGN(PATH_MAX)];
33 35 } *head[32];
34 36  
35 37 static inline int hash(int major, int minor, int ino)
... ... @@ -57,7 +59,7 @@
57 59 q->ino = ino;
58 60 q->minor = minor;
59 61 q->major = major;
60   - q->name = name;
  62 + strcpy(q->name, name);
61 63 q->next = NULL;
62 64 *p = q;
63 65 return NULL;
... ... @@ -132,8 +134,6 @@
132 134 this_header += n;
133 135 count -= n;
134 136 }
135   -
136   -#define N_ALIGN(len) ((((len) + 1) & ~3) + 2)
137 137  
138 138 static __initdata char *collected;
139 139 static __initdata int remains;