From patchwork Wed Oct 21 17:34:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11849539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 594A814B7 for ; Wed, 21 Oct 2020 17:48:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B3B2C2242F for ; Wed, 21 Oct 2020 17:48:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BJckA9U2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3B2C2242F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVIEK-0007hD-Kr for patchwork-qemu-devel@patchwork.kernel.org; Wed, 21 Oct 2020 13:48:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVI1j-0004G3-4j for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:35:55 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:35339) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVI1h-0006IZ-Ok for qemu-devel@nongnu.org; Wed, 21 Oct 2020 13:35:54 -0400 Received: by mail-wm1-x32e.google.com with SMTP id q5so3462708wmq.0 for ; Wed, 21 Oct 2020 10:35:53 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Fm7KbLir3gbzmjKy+27eSKs45PUg9V/AzuCpZDRK/Q=; b=BJckA9U2TgiC+CxfBuvijCXXMaUfzkPWmqaDBx8HO6JNH6gaogOPzZLGozrWjTu46x XTz0jbJQLeBLigFgBopZdMMy2E+5xv6p9TCrb16908nc1++1fC1wVpp6OhLG0VWLbda5 5e42Re/cufcyukyEKQj6h7+UUiwq3BrTl0p6ozYbipJ9dLn3WYut1QuBVf+S1B9N+Gk1 KkQgV/RBgEwpgtH1uDSm5vfI5BI7r9DJfxe9T4gMgMpMGQe92+SMg4z3S4v3L0Qk338I d5vhhlW1cnou8N77tkIaOmHeNMehe3389IXkCNTEkp0juq9azyvS3XNuJ/6XwE/ua9xy HeOA== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=+Fm7KbLir3gbzmjKy+27eSKs45PUg9V/AzuCpZDRK/Q=; b=PUXobAKqJFFcPfxf3FVN1nJKY/8DT1JxLjDR00NRV8xdaZwAvSP6FSF72dQ3QsBMJ5 SAGw3eCVpz8b5fDU+oSPIUIMBMW5TyQZ38yAIMz1XdAPXgBYZvpkty/KqVc/5HLyKDi9 MXJwhdr+vbmEieg+K3uWH9It4av2RebosMDfeeTVpbz2BGAzrp4UlW3O8X47ZV9xgyTg pcY9zWGqz7PZkKrCJ6UHFRkpHNhPymn0ke26v165RYbd7baxiIADfPgWG70aharWDuX+ 9TU33Xfjb4FI4qfywejwyfS8r8sJbVt/WjrAluZRmRqaNZIvXd97MzKljgVELcU1133C QXpg== X-Gm-Message-State: AOAM5304TgQVnttgmz3V4KY4el9JNYxljyxPx2xyTOP1Kk5KJn5NVHAl oTakaqh6h/1HiuR0k8hh1D1eXS1V+KY= X-Google-Smtp-Source: ABdhPJyXZR7NSQEPtzfFgA+cILOxyz/oir9OSDeP9Ffxb2N9bdWfaYwgiQ6vdyLLGtlnl4JBwr9PrA== X-Received: by 2002:a7b:c418:: with SMTP id k24mr4913652wmi.118.1603301752277; Wed, 21 Oct 2020 10:35:52 -0700 (PDT) Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id 133sm8735201wmb.2.2020.10.21.10.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 10:35:51 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 13/13] hw/sd/sdcard: Assert if accessing an illegal group Date: Wed, 21 Oct 2020 19:34:50 +0200 Message-Id: <20201021173450.2616910-14-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201021173450.2616910-1-f4bug@amsat.org> References: <20201021173450.2616910-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x32e.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: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no 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: Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We can not have more group than 'wpgrps_size'. Assert if we are accessing a group above this limit. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Alexander Bulekov Message-Id: <20201015063824.212980-7-f4bug@amsat.org> --- hw/sd/sd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4454d168e2f..c3febed2434 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -780,6 +780,7 @@ static void sd_erase(SDState *sd) sd->csd[14] |= 0x40; for (i = erase_start; i <= erase_end; i++) { + assert(i < sd->wpgrps_size); if (test_bit(i, sd->wp_groups)) { sd->card_status |= WP_ERASE_SKIP; } @@ -794,6 +795,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) wpnum = sd_addr_to_wpnum(addr); for (i = 0; i < 32; i++, wpnum++, addr += WPGROUP_SIZE) { + assert(wpnum < sd->wpgrps_size); if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) { ret |= (1 << i); }