From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7413CC46460 for ; Thu, 30 May 2019 04:13:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 433CA251E3 for ; Thu, 30 May 2019 04:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559189617; bh=xLK+GB7522f2QXrf/TUYNcfRXdrfcjqNLXPFEZK22mE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sntBjV3EttASG9fk98wq5bm7IpC56G3KhPg6RMBYWerBE5bNOywgtQGiZ6mYUZWNj Yn+HuRbqR+rfmRA0NS0CL45Gu+IIpqriSISOqho6cqyQ9FO2EO3CYt4f1nH0qPYCwD PvxP7EBeY4xu3VHDS/RJl1Y8DALrLtvrwqhR4cvA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727289AbfE3ENI (ORCPT ); Thu, 30 May 2019 00:13:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:41614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730665AbfE3DQY (ORCPT ); Wed, 29 May 2019 23:16:24 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9CC482458C; Thu, 30 May 2019 03:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186183; bh=xLK+GB7522f2QXrf/TUYNcfRXdrfcjqNLXPFEZK22mE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KnYLYhKgdBZ8dE7tlWrzhlFfVn4yeQDjv+JuqwGFsv17INrVZfrRx6nU5c+e7OLbl OzjzIoy5r8TbxQBjYFUjsMUJ2Qlwt2TFSOwxMqQfKo/2qcArj51nLci3/7KHZH3CFy 6aJPJtXyfXX7CCYytcxCV016WZy8/g7ql5oMYGmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Raul E Rangel , Ulf Hansson , Sasha Levin Subject: [PATCH 4.19 049/276] mmc: core: Verify SD bus width Date: Wed, 29 May 2019 20:03:27 -0700 Message-Id: <20190530030527.953816859@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 9e4be8d03f50d1b25c38e2b59e73b194c130df7d ] 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. 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. Reviewed-by: Avri Altman Signed-off-by: Raul E Rangel Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/core/sd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index d0d9f90e7cdfb..cfb8ee24eaba1 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -216,6 +216,14 @@ static int mmc_decode_scr(struct mmc_card *card) if (scr->sda_spec3) scr->cmds = UNSTUFF_BITS(resp, 32, 2); + + /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ + if (!(scr->bus_widths & SD_SCR_BUS_WIDTH_1) || + !(scr->bus_widths & SD_SCR_BUS_WIDTH_4)) { + pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); + return -EINVAL; + } + return 0; } -- 2.20.1