From patchwork Mon Sep 14 10:07:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 517336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6C57D140770 for ; Mon, 14 Sep 2015 20:08:02 +1000 (AEST) Received: from localhost ([::1]:39543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbQg4-0008WV-LD for incoming@patchwork.ozlabs.org; Mon, 14 Sep 2015 06:08:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbQfb-0007wZ-8S for qemu-devel@nongnu.org; Mon, 14 Sep 2015 06:07:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbQfX-0008MR-62 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 06:07:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbQfX-0008M8-04; Mon, 14 Sep 2015 06:07:27 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 7FD068CF76; Mon, 14 Sep 2015 10:07:26 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-65.ams2.redhat.com [10.36.112.65]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8EA7OCf021726; Mon, 14 Sep 2015 06:07:25 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 14 Sep 2015 12:07:22 +0200 Message-Id: <1442225242-27908-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-trivial@nongnu.org Subject: [Qemu-devel] [PATCH] pc: check for underflow in load_linux X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If (setup_size+1)*512 is small enough, kernel_size -= setup_size can allocate a huge amount of memory. Avoid that. Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 56aecce..6a312bd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -986,6 +986,10 @@ static void load_linux(PCMachineState *pcms, setup_size = 4; } setup_size = (setup_size+1)*512; + if (setup_size > kernel_size) { + fprintf(stderr, "qemu: invalid kernel header\n"); + exit(1); + } kernel_size -= setup_size; setup = g_malloc(setup_size);