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.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 A24C7C282DC for ; Wed, 22 May 2019 19:30:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6946A217F9 for ; Wed, 22 May 2019 19:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558553434; bh=UapYmnCpWuab03TBWLBB+gBSRoAtQj094QqbPvWrKzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=S1Wg/Jlxclh6Hg347Gth2VEoIgRJU1rCmP8IctQAB98e26SfpAjVgd5/amVgaX6Wq skrz6R09X0M4V+3qFHxWPH7sVQdWl/Y6sZ5XnUTksHlNGu3rhfhzumMf69UYFVmz5R KPSxUbyMkh//5s22fi9Cc2ZlUHzMBuPnbJhKrcLQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732789AbfEVTac (ORCPT ); Wed, 22 May 2019 15:30:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:53852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732749AbfEVTaX (ORCPT ); Wed, 22 May 2019 15:30:23 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACA7F20879; Wed, 22 May 2019 19:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558553422; bh=UapYmnCpWuab03TBWLBB+gBSRoAtQj094QqbPvWrKzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OyVyfnCq+djQdsrGJ9W8kDaU9tKUXR+CIeDBLIJ1LVZdeexyLaU8x00+OqVIY4w9b Lds4ihz26V2qlKQgrX5HywZpqZk5AIdiwi6C4Mx5Q0UxRy+ZWVTcHY+fG7zl6JnwWB ltU2OJV1j8vIBBe29nSjr5Ly9RDr0NoB0ijY7MPE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Raul E Rangel , Avri Altman , Ulf Hansson , Sasha Levin , linux-mmc@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 003/114] mmc: core: Verify SD bus width Date: Wed, 22 May 2019 15:28:26 -0400 Message-Id: <20190522193017.26567-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190522193017.26567-1-sashal@kernel.org> References: <20190522193017.26567-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Raul E Rangel [ 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 f09148a4ab557..00ba8807dafe4 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -214,6 +214,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