From nobody Sun May 5 08:17:22 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 1505553522635481.7039727821875; Sat, 16 Sep 2017 02:18:42 -0700 (PDT) Received: from localhost ([::1]:56503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dt9FI-000801-43 for importer@patchew.org; Sat, 16 Sep 2017 05:18:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dt9ER-0007gJ-Ij for qemu-devel@nongnu.org; Sat, 16 Sep 2017 05:17:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dt9EO-0003cY-Dk for qemu-devel@nongnu.org; Sat, 16 Sep 2017 05:17:47 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:60859) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dt9EO-0003bh-6x for qemu-devel@nongnu.org; Sat, 16 Sep 2017 05:17:44 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dt9EE-0001b8-H6; Sat, 16 Sep 2017 11:17:34 +0200 Received: from mol by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dt9EE-0002lp-1F; Sat, 16 Sep 2017 11:17:34 +0200 From: Michael Olbrich To: qemu-devel@nongnu.org Date: Sat, 16 Sep 2017 11:16:11 +0200 Message-Id: <20170916091611.10241-1-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.11.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mol@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 92.198.50.35 Subject: [Qemu-devel] [PATCH] hw/sd: fix out-of-bounds check for multi block reads 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: Michael Olbrich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current code checks if the next block exceeds the size of the card. This generates an error while reading the last block of the card. Do the out-of-bounds check when starting to read a new block to fix this. This issue became visible with increased error checking in Linux 4.13. Signed-off-by: Michael Olbrich --- hw/sd/sd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ba47bff4db80..94ff52512c43 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1797,8 +1797,13 @@ uint8_t sd_read_data(SDState *sd) break; =20 case 18: /* CMD18: READ_MULTIPLE_BLOCK */ - if (sd->data_offset =3D=3D 0) + if (sd->data_offset =3D=3D 0) { + if (sd->data_start + io_len > sd->size) { + sd->card_status |=3D ADDRESS_ERROR; + break; + } BLK_READ_BLOCK(sd->data_start, io_len); + } ret =3D sd->data[sd->data_offset ++]; =20 if (sd->data_offset >=3D io_len) { @@ -1812,11 +1817,6 @@ uint8_t sd_read_data(SDState *sd) break; } } - - if (sd->data_start + io_len > sd->size) { - sd->card_status |=3D ADDRESS_ERROR; - break; - } } break; =20 --=20 2.14.1