From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R25Lb-0007Mw-Cw for qemu-devel@nongnu.org; Fri, 09 Sep 2011 13:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R25La-0004ma-AH for qemu-devel@nongnu.org; Fri, 09 Sep 2011 13:58:39 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:33462) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R25La-0004l4-4y for qemu-devel@nongnu.org; Fri, 09 Sep 2011 13:58:38 -0400 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by e36.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p89HpPF3030651 for ; Fri, 9 Sep 2011 11:51:25 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p89Hw0r5062926 for ; Fri, 9 Sep 2011 11:58:02 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p89BvxXC023748 for ; Fri, 9 Sep 2011 05:57:59 -0600 Message-ID: <4E6A53A5.7020904@us.ibm.com> Date: Fri, 09 Sep 2011 12:57:57 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1315078543-28522-1-git-send-email-levinsasha928@gmail.com> In-Reply-To: <1315078543-28522-1-git-send-email-levinsasha928@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] pc_init: Fail on bad kernel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sasha Levin Cc: qemu-devel@nongnu.org, "H. Peter Anvin" On 09/03/2011 02:35 PM, Sasha Levin wrote: > When providing QEMU with a bad '-kernel' parameter, such as a file which > is not really a kernel, QEMU will attempt to allocate a huge amount of > memory and fail either with "Failed to allocate memory: Cannot allocate > memory" or a GLib error: "GLib-ERROR **: gmem.c:170: failed to allocate > 18446744073709529965 bytes" > > This patch handles the case where the magic sig wasn't located in the > provided kernel, and loading it as multiboot failed as well. > > Cc: Anthony Liguori > Signed-off-by: Sasha Levin > --- > hw/pc.c | 8 +++++++- > 1 files changed, 7 insertions(+), 1 deletions(-) > > diff --git a/hw/pc.c b/hw/pc.c > index 6b3662e..428440b 100644 > --- a/hw/pc.c > +++ b/hw/pc.c > @@ -691,8 +691,14 @@ static void load_linux(void *fw_cfg, > /* This looks like a multiboot kernel. If it is, let's stop > treating it like a Linux kernel. */ > if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename, > - kernel_cmdline, kernel_size, header)) > + kernel_cmdline, kernel_size, header)) { > return; > + } else { > + fprintf(stderr, "qemu: could not load kernel '%s': %s\n", > + kernel_filename, strerror(errno)); > + exit(1); > + } > + There's trailing whitespace on this line. But I also don't think this is the right fix. This change makes the line below unreachable. There is still code in this path attempting to handle protocols < 2.00. Admittedly, these would be ancient kernels that I doubt anyone would really use but the code is there to support it nonetheless. I think a better fix would be to positively identify kernels that are older than this. Perhaps hpa knows how we could positively identify a kernel that's older than protocol 200? Regards, Anthony Liguori > protocol = 0; > } >