Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp309111ybi; Wed, 29 May 2019 21:59:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVfWYoC1ojPWkSp9YPXoZdTMNthmefHn+y2elnla9sEhebiDADiep+oUwqgZuPqMUomEGR X-Received: by 2002:a63:455e:: with SMTP id u30mr1917377pgk.189.1559192366594; Wed, 29 May 2019 21:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559192366; cv=none; d=google.com; s=arc-20160816; b=ttRIwri1j8Oi7LMqzPFonbF4VpFp2RbCU0MxwgqKrUBfK9qw/vn+eBGu2zNFrkZNcX jmeqwZR/yu9mRqOfl2ZuswHcWucKjJFOlecXtMuRfd1uDrOXvRdfKFPKhdwDA3XmhbAY 2NRwBCNWeocySDxajzJw+hCm12zvFOM61nmLk2qZoIO/rjnSpMUMB4lncUHr7RDB5vmJ /stlpVGG/jFabYCw8tfEenVFr/LbiVpegmvTiNpqVolR7bKFSn/U9Ikwve88SEeCR5uI AN2k7gtY+aG0jY/QTQlvu6emXijUTwbYBT+ysspXup3VsrLQ0lRXNNsmZXgWyQzWuFlq oBWw== 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=WttzkfRft3gfTjY6eAsbcv8dU2r7nrsSHIxlgFUYm7U=; b=BrDvkQ69hkZuVyVopoqQ7gfvqyCChfch0XaFaLLrRoVYQz/zgbeskw+YYuMBeeomVS N5jOqozkoWDI29TWDGnZMJrFn4sfrIKUxCnlPmzq1eUVVi4lqLABMHdvWHZXgo9SNQ5U TMwxE9nXv7sK5FUqmPKmkzd3c+ktRSDL28XV8dwROw1zxUP2h9DvyRx7wpTLiU+ewSoB 7/R69vJhI3AoDPAeU9A8rzIqok8p630ktf604jTuJecdHzuul7xD2nSWh7Rrn0Sq3iPC 7fZizU5iDNWivYtJuBNokMw4ntnCEdYocszPu7GwxlUWdXSLilFdKD2MbOOkf5tUyqjD ft0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dmpwBt1P; 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 i21si1749115pju.82.2019.05.29.21.59.09; Wed, 29 May 2019 21:59:26 -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=dmpwBt1P; 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 S1727968AbfE3DKJ (ORCPT + 99 others); Wed, 29 May 2019 23:10:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727758AbfE3DJq (ORCPT ); Wed, 29 May 2019 23:09:46 -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 1174224490; Thu, 30 May 2019 03:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185786; bh=2+OW7A+l+B7DYsuCucwPknFz8grKw7lT3eprsyBUHo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dmpwBt1Pfmk1M/iBoOW6FwKUgbkgHUrq6Lo4XbdXy0Xk/CXFsNWUhpeljQpMKJ1He NnNSwVaHTxGY8q0iHnwsLHACHNv6xOsmqZqF89+xxLggZXOfozKQK6vZ6QGzVJEAwJ KMNCLSci/fraHUj+JTlzSBDmOBpB/tMH6d9PygpE= 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 5.1 053/405] mmc: core: Verify SD bus width Date: Wed, 29 May 2019 20:00:51 -0700 Message-Id: <20190530030543.532960743@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.291644921@linuxfoundation.org> References: <20190530030540.291644921@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 265e1aeeb9d88..d3d32f9a2cb18 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -221,6 +221,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