From patchwork Mon Apr 15 21:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raul Rangel X-Patchwork-Id: 10901529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02E0814DB for ; Mon, 15 Apr 2019 21:00:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEA4B28632 for ; Mon, 15 Apr 2019 21:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFA0A28885; Mon, 15 Apr 2019 21:00:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 995CD28632 for ; Mon, 15 Apr 2019 21:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbfDOVAi (ORCPT ); Mon, 15 Apr 2019 17:00:38 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:53014 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727160AbfDOVAi (ORCPT ); Mon, 15 Apr 2019 17:00:38 -0400 Received: by mail-it1-f195.google.com with SMTP id x132so29516848itf.2 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=X2nJ8CIvgoRyLZXFRJc/awNInoC8sb34oRhxNXLUyPXqYIgXyWdbIMRcFIWTGCkDXA AV3bVHOmIbFj+kT4sjfu0pc5bM/M3zJw+8ZStLOvGcPdHH9O3f4YgCKXMJQdnJY1KawI tekalJbgXXaMOC8ct0ZKGCCvX0+z5jl3p20IOqpLI7bYy2zhQMAfWkDMQR8dEdmiOqLB 7uaZyBmlTFRFXAulyHOnJNachxlVpr1Pn3wLj3pNNoft9RwH4m1FG9PHtEbNoS+qJrt7 5cb1lbpVIxArwK40od67E/YfQVs9pMxb4EFnFlRArV2jhbfXR8Sm8DBqoYWMKLtHzorT CG8Q== X-Gm-Message-State: APjAAAV6erdHUwwIiPXsG+D/7QAHmR3el0eNgIb8WpcxuncD7h/KMbG6 qs+IbF29H9v2PAQggV/h1BlO/82plsOAtA== X-Google-Smtp-Source: APXvYqyjGTH7SBdKIzp5IAYnUPeEjU8yIIfqyQhcM54nkTQKC6fTO3TpfubkoNUVJiqm0ILERVs3jg== 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 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Avri Altman --- 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);