Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2430604ybi; Sun, 9 Jun 2019 11:35:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxghxvbtlJJgVL4r1sdBQCzzwwbZKI5d1tOKcZcy7VD/jMjgNDZjtmCKQwbO+V59fQKJv1Q X-Received: by 2002:a17:902:ac81:: with SMTP id h1mr61572910plr.129.1560105352532; Sun, 09 Jun 2019 11:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560105352; cv=none; d=google.com; s=arc-20160816; b=k9qULDdrfNJ7ljFGRvaG1j6BeWa7Qz5KHgcm3lRjxI29/R0iotdXV+ku9e61Llddj2 OGO1lO97lorzQqMB2FM/F7UpDon4LbNBXq1fzH8H0HWJWNArnFlIwf/j5P8wDAYuVAUO 6+4OR7OT4RZXY1NoRTVilpawQKAn7kupYN3Lc3yeVpuR//6X2HeRcqw/icPnl9Rw1+2M iaf9A21N4uAU1cOmpgj6txFqyrz/0EntMoUynzQ86VoPqyLLu9wqoEEJNbU5CowFFPas FW79rU3CfC1ENfUkPFSGUoRtKhohGoEWpW/elxpltAfVNpZABIszfkoQ8QQtB8sXZE+M tXOg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3fMNA4an3+/f2qQvxkEN+g0IQNIjE4HPhW9agD3ABUs=; b=OKV9Bb3MASvXu2ETuIok1+Ye5XmiegMkBtD1mkEfioRVcdgmd5GudBqYrGl0ju+GPj 2EOhEVKV2BSM+infx7OrgdhqgsEeD+9bClNcM9vU8Ht0UrrcQKeRKJ/oRvQq4liezykH oHJkANTNy1tpbGD70p/UyToBj/5w4lPSFJ98yQiWkrrqw6YW25LTenw9DC0i5APLaCeb sil3lLkyqS+pBEVDujj84CyClGw6aiVpFKWshkZAjCtyrQanWlncXnCnZz+sRh34Xahr 1MXdm5E6+rYrahV/Z7Za+8izEfBNEjYgkCtY0m42ZDp2Gx+VidgaJj6Vf26+3MzyYUqv qSIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rbtQnkWh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o127si567947pga.593.2019.06.09.11.35.35; Sun, 09 Jun 2019 11:35:52 -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=@kernel.org header.s=default header.b=rbtQnkWh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388689AbfFIRLE (ORCPT + 99 others); Sun, 9 Jun 2019 13:11:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:39358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733260AbfFIRBu (ORCPT ); Sun, 9 Jun 2019 13:01:50 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 7A5D5208C0; Sun, 9 Jun 2019 17:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099710; bh=gF7m42X1PrEptWyk5LBiKFn0g3ZJIyjsxi25BehhXFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rbtQnkWhrpuepuQnsADvEBcEAUkTY4ljEeE9nYiWWZ42YyV/JWdiMlBIWKA2BJc4I Qov6AeLNriBeEU/N7HVovoUBbVfKmHsS+fcu0fqqR+YsQl5qtBvSDltPVeeP//wb+P 2UzJ6vjdkPOLp1baJkJ911T6zum/4wnzFJHK5U5c= 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.4 095/241] mmc: core: Verify SD bus width Date: Sun, 9 Jun 2019 18:40:37 +0200 Message-Id: <20190609164150.538605430@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164147.729157653@linuxfoundation.org> References: <20190609164147.729157653@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 967535d76e346..fb8741f18c1f5 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