From nobody Sat May 18 17:34:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1591292105; cv=none; d=zohomail.com; s=zohoarc; b=cDPwnHQq5qM2bLa8lKcFmtm1DrNWPTj7MPOmCVY0+gUjzRRT4n7DrDCP2v8/YEGRd0Ai+0UHME+NuBGBuPs9kHenpZQNjfLGN4JlonJsPhly9BZ4QjNQqomZAG4nsyzq8noQUGQ8pH5vaB9pmFz9VaoM8zNm/57ZCmT2KY90zkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591292105; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=c/njtRoD2PI3vve6feg3VXUYaI7/H7zNIgbrnDw9lnM=; b=gLHEf+pox+XpF365+HCkK5SLsZM6svVfksf0RghaFgGs9V8ELXvC8lApSOx5dyrNUQ5C1o3qaB5/9JT73Z28opHYALRW23uoxn+TJJVFCwE7lglyZbhg+nUhnMWnTEVqJw4U+s1iMezUc/4S2rIQzA0lUXATrAV6uP6csjaf5N4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591292105561866.6476289190915; Thu, 4 Jun 2020 10:35:05 -0700 (PDT) Received: from localhost ([::1]:35262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgtlg-0000t4-Bo for importer@patchew.org; Thu, 04 Jun 2020 13:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgtkz-0000TJ-Kn for qemu-devel@nongnu.org; Thu, 04 Jun 2020 13:34:21 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:34846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jgtky-0004lv-I9 for qemu-devel@nongnu.org; Thu, 04 Jun 2020 13:34:21 -0400 Received: by mail-wm1-x344.google.com with SMTP id q25so6554844wmj.0 for ; Thu, 04 Jun 2020 10:34:19 -0700 (PDT) Received: from localhost.localdomain (181.red-88-10-103.dynamicip.rima-tde.net. [88.10.103.181]) by smtp.gmail.com with ESMTPSA id l1sm10481640wrb.31.2020.06.04.10.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 10:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=c/njtRoD2PI3vve6feg3VXUYaI7/H7zNIgbrnDw9lnM=; b=U8WDJfhuBBsseJLybz7Mv7A2QnRqudlwwgVVhFtl0l5G2ITuIyJPJJlcH4bwJEBSY5 cpK6xT9idWTCApfHjoi0OG+jiFig+Rr9feFUcYVEqWa+nHD9wIywHa5LCg7JhJnmec9p S2yqVW3KpfWiSMV1vgqHQxUywPRRRKBUaUJ5kjKBDnVUtnAD6jDSBMTz67DVSKpNPXxR PvARapMRTeFIQ7eisFRxQLLlsg8Q1UMpJ1JJOpOXKWkhXyjen16AdkvaD9HxD1F0WynD G2uGTfzU85gScrTAuq9mKpTTtu0iYYJq6m//xff8+Y8dDtb3FuAjMZuiw4E2FYih4CL0 8Qxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=c/njtRoD2PI3vve6feg3VXUYaI7/H7zNIgbrnDw9lnM=; b=ZYQq2ilCCoXirJ8Q0boRGKI3QxIju86ePsO5SgSfNVyBD0MdpAtQEyYNYKPaBN+VdW YE4JMOx/WkJJ1ONaDpvq/4UA4BgOQhtL5JJDOLoV9HDLrzUddNVR9uUw2t6Mf8m8+m4E jOOEsVie20ya5n5UX/2JiBOhU5CM5vpnEFqJRVY6Lgc4TipzsWyH/OXHjj3tH67x3KvW Ti7/OhX72P1dg4QU9FibcRTmLHek2S0UfAERVW6JCbZ0hOCDXh1fj9H9mD9NMdwjgzm8 Er/4AEB/znUSSn6rfGYCkj6warY6f0xTEATCGN2lz+1HNsh/ul3VJr4qKVRNkk+q3GZv duWg== X-Gm-Message-State: AOAM530obcEsWBNlyGIUeLBnbQvdjSXiF5HWsgneg8s9ziiMyfXp3R+J 9nI8BHYQVg/Q+gHrDSt4Nwv4DTF8 X-Google-Smtp-Source: ABdhPJycOXqyyoiGS3tSf2WEW32x6LEA/60JvZ/oWOKtoUP9rkaMAd7NaUWdpQROHmM6/0DztA8Shw== X-Received: by 2002:a1c:2bc2:: with SMTP id r185mr5342488wmr.49.1591292058246; Thu, 04 Jun 2020 10:34:18 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH] hw/sd/sdcard: Verify CMD24 (Block Write) address is valid Date: Thu, 4 Jun 2020 19:34:10 +0200 Message-Id: <20200604173410.21074-1-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , 1880822@bugs.launchpad.net, Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Avoid OOB access by verifying the requested address belong to the actual card size. Return ADDRESS_ERROR when not in range. "SD Specifications Part 1 Physical Layer Simplified Spec. v3.01" 4.3.4 Data Write * Block Write Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. Fixes: CVE-2020-13253 Reported-by: Alexander Bulekov Buglink: https://bugs.launchpad.net/qemu/+bug/1880822 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- Cc: Prasad J Pandit --- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3c06a0ac6d..0ced3b5e14 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1211,6 +1211,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) /* Writing in SPI mode not implemented. */ if (sd->spi) break; + if (addr >=3D sd->size) { + sd->card_status |=3D ADDRESS_ERROR; + return sd_r1; + } sd->state =3D sd_receivingdata_state; sd->data_start =3D addr; sd->data_offset =3D 0; --=20 2.21.3