From patchwork Sat Sep 16 10:35:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Olbrich X-Patchwork-Id: 814488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xvTFy67lQz9t2c for ; Sat, 16 Sep 2017 20:36:19 +1000 (AEST) Received: from localhost ([::1]:56680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtASP-0004IP-7n for incoming@patchwork.ozlabs.org; Sat, 16 Sep 2017 06:36:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtARp-0004IF-6O for qemu-devel@nongnu.org; Sat, 16 Sep 2017 06:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtARn-0005sR-V2 for qemu-devel@nongnu.org; Sat, 16 Sep 2017 06:35:41 -0400 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]:39857) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dtARn-0005rh-MC for qemu-devel@nongnu.org; Sat, 16 Sep 2017 06:35:39 -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 1dtARl-0003Zh-5T; Sat, 16 Sep 2017 12:35:37 +0200 Received: from mol by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dtARj-0000ks-HS; Sat, 16 Sep 2017 12:35:35 +0200 From: Michael Olbrich To: qemu-devel@nongnu.org Date: Sat, 16 Sep 2017 12:35:23 +0200 Message-Id: <20170916103523.1482-1-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <150555367996.36.15771330325496067998@69b6ddf88678> References: <150555367996.36.15771330325496067998@69b6ddf88678> 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: Genre and OS details not recognized. X-Received-From: 2001:67c:670:201:290:27ff:fe1d:cc33 Subject: [Qemu-devel] [PATCH v2] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Alistair Francis --- Changes in v2: - fixed warning I'm not quite sure if 0x00 is the correct return value, but it's used elsewhere in the same function when an error occurs, so it seems reasonable. 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..35347a5bbcde 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1797,8 +1797,13 @@ uint8_t sd_read_data(SDState *sd) break; case 18: /* CMD18: READ_MULTIPLE_BLOCK */ - if (sd->data_offset == 0) + if (sd->data_offset == 0) { + if (sd->data_start + io_len > sd->size) { + sd->card_status |= ADDRESS_ERROR; + return 0x00; + } BLK_READ_BLOCK(sd->data_start, io_len); + } ret = sd->data[sd->data_offset ++]; if (sd->data_offset >= 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 |= ADDRESS_ERROR; - break; - } } break;