Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2542803yba; Mon, 15 Apr 2019 14:02:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8B1tqEABXynpmOoz1z5MBLV1oYx1Dyg3OAEX0K/s2oBlIb7cYj94VM6LUYKA4qLUP1k/3 X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr78092963plb.131.1555362124376; Mon, 15 Apr 2019 14:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555362124; cv=none; d=google.com; s=arc-20160816; b=hKsXWzbOcFYM9GzJ/n1spyjrlBVAEFVKDBH031H6rj99/fnBbRu2BRasRNQ9LE/LF1 jAjDXwDRF8kIhc99b4LXP4ggbCx0FXrJEqXw02turcbvI0XLEZYBMTWe4LUybIquzvhB Gqh1Yv+x82ukugEdGZ1qqgM+CCO2BVMYvwJTGaYUwtyrbyxCIu8wApwGosJR9DEJpmPS s5r30ajgO0eTs0U1+cuwcxGvdhQDfFpqqtay0YnZYOKNbUrA4vblNDKKaEXfpOqtNfr7 Mz/YQQ7VwDL8cOwv/COn/ZhXjLHPJsSlWrdZhOAP5nJJXVfdyPDXbk0HPyCp3xUOoivC Q4iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l2m+OpLOA9wqfqg+vaNnTPXmbZMciiCK62VMT09ujw4=; b=k8p906hVOHC3r5LShVu3aTisG80Kmgj6nGITcw7kcVvLB64d1WqhHOCI1PHsuKvnDW om8QX91dIURgp9KAe9zJOJQjCfQ0PIFh+Db1/+4BUG8Ne6Qj7vclilZT46JHlVHlf3cF MvxNPnyv+wy0CGCGj++eT4NUrtLA42mZwlLDtcr4vHBqYf7n+aBXc9S46tvW/EPSzeR7 ddjLAt8n75G4JIF2U4rHYS6gDAvHv/dnO15Xojuw5cG1dlTInAM9N4s8w3IN+GzL//CL f+q65El7vP9Iznsi1Q/fktowVe/XdE8OcA3GQeQ1zrIVz82D8ySU1vePKArj8Hdg4X4T /Jpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cv0yDBK8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si40888735pgu.544.2019.04.15.14.01.48; Mon, 15 Apr 2019 14:02:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cv0yDBK8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727604AbfDOVAi (ORCPT + 99 others); Mon, 15 Apr 2019 17:00:38 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:39418 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbfDOVAi (ORCPT ); Mon, 15 Apr 2019 17:00:38 -0400 Received: by mail-it1-f195.google.com with SMTP id 139so29121800ita.4 for ; Mon, 15 Apr 2019 14:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l2m+OpLOA9wqfqg+vaNnTPXmbZMciiCK62VMT09ujw4=; b=Cv0yDBK8CJU58r3YrVuPBxtO/pvovvHi7cqo9b7lqey5znqG+RdoVJvJoOuVZivVko EZXe3iKEkOcXEGUUkn1fipK89P3CAerno7luZtvovKogHqqXK9DiPTmSF5gWBF7zhNMv Dw0CTXBT3hOP+ZZ3RJU3N02G+ANGTqe39vs2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l2m+OpLOA9wqfqg+vaNnTPXmbZMciiCK62VMT09ujw4=; b=JRHXcME6uVhGrBMW8IiSnwRcBkhF9gQBOlvz1uVixd82/eRJ4+eR+Pvo/0eXJvaMIa bL3Erwy5orf1rV9Okcs17JoqPHl3Eq6ldLsVm9tMzbQV6XTAlY2SFS1lwDY+09qvXjP0 L6QXsul1532mx9RoYVDrln4aR0QcMh3mTo5Jx1S7it6kk75JfZjZZiSEK8ybtG2dE4m3 jKchS9snIXJnKnSo6rzkW7FSYH1cFpFgtYpmaEdCdJ6InheoOB4AoFY+/qzREy66+1FY pL2Lym84MvfuBSR+i5UAsPz58u271AyZqo6QF+QTPD2U79osfVm0k8XWIKKyr+FdzAWk Ewww== X-Gm-Message-State: APjAAAWp49L6O7UalKh8QDDcVrD0pSP7jFd031etyBderuv3ptWQN8r1 OdSy5UQ6mZxkt1Ee2Gw9tidD0A== X-Received: by 2002:a02:a58e:: with SMTP id b14mr23153214jam.77.1555362037046; Mon, 15 Apr 2019 14:00:37 -0700 (PDT) Received: from localhost ([2620:15c:183:0:20b8:dee7:5447:d05]) by smtp.gmail.com with ESMTPSA id k201sm8428842itb.10.2019.04.15.14.00.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 14:00:36 -0700 (PDT) From: Raul E Rangel To: linux-mmc@vger.kernel.org Cc: djkurtz@chromium.org, zwisler@chromium.org, Raul E Rangel , hongjiefang , Jennifer Dahm , linux-kernel@vger.kernel.org, Kyle Roeschley , Avri Altman , Ulf Hansson Subject: [PATCH v1] mmc: core: Verify SD bus width Date: Mon, 15 Apr 2019 15:00:31 -0600 Message-Id: <20190415210031.54062-1-rrangel@chromium.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SD Physical Layer Spec says the following: Since the SD Memory Card shall support at least the two bus modes 1-bit or 4-bit width, then any SD Card shall set at least bits 0 and 2 (SD_BUS_WIDTH="0101"). This change verifies the card has specified a bus width. verified it didn't mount. Signed-off-by: Raul E Rangel --- AMD SDHC Device 7806 can get into a bad state after a card disconnect where anything transferred via the DATA lines will always result in a zero filled buffer. Currently the driver will continue without error if the HC is in this condition. A block device will be created, but reading from it will result in a zero buffer. This makes it seem like the SD device has been erased, when in actuality the data is never getting copied from the DATA lines to the data buffer. SCR is the first command in the SD initialization sequence that uses the DATA lines. By checking that the response was invalid, we can abort mounting the card. Here is an example of a bad trace: https://pastebin.com/TY2cF9n0 Look for sd_scr and sd_ssr. drivers/mmc/core/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 265e1aeeb9d8..f6481f8e9fe7 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -205,6 +205,13 @@ static int mmc_decode_scr(struct mmc_card *card) scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); + + /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ + if (!scr->bus_widths) { + pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); + return -EINVAL; + } + if (scr->sda_vsn == SCR_SPEC_VER_2) /* Check if Physical Layer Spec v3.0 is supported */ scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1); -- 2.21.0.392.gf8f6787159e-goog