From nobody Thu May 2 13:43:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507107835672665.3544422552793; Wed, 4 Oct 2017 02:03:55 -0700 (PDT) Received: from localhost ([::1]:33799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzfal-0005sx-US for importer@patchew.org; Wed, 04 Oct 2017 05:03:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzfZl-0005IN-PT for qemu-devel@nongnu.org; Wed, 04 Oct 2017 05:02:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzfZg-0006Ah-Pz for qemu-devel@nongnu.org; Wed, 04 Oct 2017 05:02:45 -0400 Received: from 18.mo5.mail-out.ovh.net ([178.33.45.10]:55801) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzfZg-00069t-Ix for qemu-devel@nongnu.org; Wed, 04 Oct 2017 05:02:40 -0400 Received: from player773.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id C047312F795 for ; Wed, 4 Oct 2017 11:02:36 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player773.ha.ovh.net (Postfix) with ESMTPA id B3ABA600094; Wed, 4 Oct 2017 11:02:31 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 04 Oct 2017 11:02:31 +0200 Message-ID: <150710775137.16096.2606042109300213433.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 11793520052370971125 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrkeelgdduudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.45.10 Subject: [Qemu-devel] [PATCH] spapr: sanity check size of the CAS buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The CAS buffer is provided by SLOF. A broken SLOF could pass a silly size: either smaller than the diff header, in which case the current code will try to allocate 16 Exabytes of memory and g_malloc0() will abort, or bigger than the maximum memory provisioned for SLOF (ie, 40 Megabytes), which doesn't make sense. Both cases indicate that SLOF has a bug. Let's print out an explicit error message and exit since rebooting as we do with other errors would only result in a reset loop. Signed-off-by: Greg Kurz --- hw/ppc/spapr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b284e0b9d43e..1a2ca8a22b6d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -819,6 +819,13 @@ int spapr_h_cas_compose_response(sPAPRMachineState *sp= apr, return 1; } =20 + if (size < sizeof(hdr) || size > FW_MAX_SIZE) { + error_report("SLOF provided an unexpected CAS buffer size " + TARGET_FMT_lu " (min: %lu, max: %u)", + size, sizeof(hdr), FW_MAX_SIZE); + exit(EXIT_FAILURE); + } + size -=3D sizeof(hdr); =20 /* Create skeleton */