From patchwork Tue Feb 20 09:03:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10229721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C05AD602B1 for ; Tue, 20 Feb 2018 10:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1B8D285CA for ; Tue, 20 Feb 2018 10:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A667D285D2; Tue, 20 Feb 2018 10:22:05 +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=-6.9 required=2.0 tests=BAYES_00,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 48D7D285CA for ; Tue, 20 Feb 2018 10:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751341AbeBTKWD (ORCPT ); Tue, 20 Feb 2018 05:22:03 -0500 Received: from michel.telenet-ops.be ([195.130.137.88]:54362 "EHLO michel.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751339AbeBTKVu (ORCPT ); Tue, 20 Feb 2018 05:21:50 -0500 Received: from ayla.of.borg ([84.194.111.163]) by michel.telenet-ops.be with bizsmtp id CyMo1x00V3XaVaC06yMo6G; Tue, 20 Feb 2018 11:21:49 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1eo4fp-0002mu-2T; Tue, 20 Feb 2018 10:57:21 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1eo3pX-00089o-GB; Tue, 20 Feb 2018 10:03:19 +0100 From: Geert Uytterhoeven To: Jaehoon Chung , Ulf Hansson Cc: linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] mmc: dw_mmc-k3: Fix out-of-bounds access through DT alias Date: Tue, 20 Feb 2018 10:03:13 +0100 Message-Id: <1519117393-31302-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 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 hs_timing_cfg[] array is indexed using a value derived from the "mshcN" alias in DT, which may lead to an out-of-bounds access. Fix this by adding a range check. Fixes: 7d92895208a008a2 ("mmc: dw_mmc-k3: Fix out-of-bounds access through DT alias") Signed-off-by: Geert Uytterhoeven --- Compile-tested only. There is another possible out-of-bounds access in drivers/mmc/host/dw_mmc.c:dw_mci_init_slot(): if (drv_data && drv_data->caps) mmc->caps |= drv_data->caps[ctrl_id]; With ctrl_id derived from "mshcN". Unfortunately the upper bound is not known at run-time, without adding such a field to struct dw_mci_drv_data first. --- drivers/mmc/host/dw_mmc-k3.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c index 73fd75c3c824904d..75ae5803b0db24dd 100644 --- a/drivers/mmc/host/dw_mmc-k3.c +++ b/drivers/mmc/host/dw_mmc-k3.c @@ -135,6 +135,9 @@ static int dw_mci_hi6220_parse_dt(struct dw_mci *host) if (priv->ctrl_id < 0) priv->ctrl_id = 0; + if (priv->ctrl_id >= TIMING_MODE) + return -EINVAL; + host->priv = priv; return 0; }