Patchwork [15/28] kvm tools: Allow initrd_check() to match a cpio

login
register
mail settings
Submitter Matt Evans
Date Dec. 6, 2011, 3:40 a.m.
Message ID <4EDD8EC7.5010603@ozlabs.org>
Download mbox | patch
Permalink /patch/129510/
State New
Headers show

Comments

Matt Evans - Dec. 6, 2011, 3:40 a.m.
cpios are valid as initrds too, so allow them through the check.

Signed-off-by: Matt Evans <matt@ozlabs.org>
---
 tools/kvm/kvm.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg - Dec. 6, 2011, 10:26 a.m.
On Tue, Dec 6, 2011 at 5:40 AM, Matt Evans <matt@ozlabs.org> wrote:
> cpios are valid as initrds too, so allow them through the check.
>
> Signed-off-by: Matt Evans <matt@ozlabs.org>
> ---
>  tools/kvm/kvm.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
> index 33243f1..457de1a 100644
> --- a/tools/kvm/kvm.c
> +++ b/tools/kvm/kvm.c
> @@ -317,10 +317,11 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
>  /* RFC 1952 */
>  #define GZIP_ID1               0x1f
>  #define GZIP_ID2               0x8b
> -
> +#define CPIO_MAGIC             "0707"
> +/* initrd may be gzipped, or a plain cpio */
>  static bool initrd_check(int fd)
>  {
> -       unsigned char id[2];
> +       unsigned char id[4];
>
>        if (read_in_full(fd, id, ARRAY_SIZE(id)) < 0)
>                return false;
> @@ -328,7 +329,8 @@ static bool initrd_check(int fd)
>        if (lseek(fd, 0, SEEK_SET) < 0)
>                die_perror("lseek");
>
> -       return id[0] == GZIP_ID1 && id[1] == GZIP_ID2;
> +       return (id[0] == GZIP_ID1 && id[1] == GZIP_ID2) ||
> +               !memcmp(id, CPIO_MAGIC, 4);
>  }
>
>  bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,

Looks good to me.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 33243f1..457de1a 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -317,10 +317,11 @@  struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
 /* RFC 1952 */
 #define GZIP_ID1		0x1f
 #define GZIP_ID2		0x8b
-
+#define CPIO_MAGIC		"0707"
+/* initrd may be gzipped, or a plain cpio */
 static bool initrd_check(int fd)
 {
-	unsigned char id[2];
+	unsigned char id[4];
 
 	if (read_in_full(fd, id, ARRAY_SIZE(id)) < 0)
 		return false;
@@ -328,7 +329,8 @@  static bool initrd_check(int fd)
 	if (lseek(fd, 0, SEEK_SET) < 0)
 		die_perror("lseek");
 
-	return id[0] == GZIP_ID1 && id[1] == GZIP_ID2;
+	return (id[0] == GZIP_ID1 && id[1] == GZIP_ID2) ||
+		!memcmp(id, CPIO_MAGIC, 4);
 }
 
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,