From patchwork Fri Feb 23 12:44:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10237561 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 2AE47602A0 for ; Fri, 23 Feb 2018 12:44:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1976229443 for ; Fri, 23 Feb 2018 12:44:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E11F29489; Fri, 23 Feb 2018 12:44:27 +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 60BB129443 for ; Fri, 23 Feb 2018 12:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751399AbeBWMoZ (ORCPT ); Fri, 23 Feb 2018 07:44:25 -0500 Received: from albert.telenet-ops.be ([195.130.137.90]:37102 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751385AbeBWMoY (ORCPT ); Fri, 23 Feb 2018 07:44:24 -0500 Received: from ayla.of.borg ([84.194.111.163]) by albert.telenet-ops.be with bizsmtp id ECkN1x00c3XaVaC06CkNRq; Fri, 23 Feb 2018 13:44:23 +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 1epCi6-0004RV-PN; Fri, 23 Feb 2018 13:44:22 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1epCi6-0003tm-NV; Fri, 23 Feb 2018 13:44:22 +0100 From: Geert Uytterhoeven To: Jaehoon Chung , Ulf Hansson Cc: linux-mmc@vger.kernel.org, devicetree-compiler@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] mmc: dw_mmc-k3: Fix out-of-bounds access through DT alias Date: Fri, 23 Feb 2018 13:44:19 +0100 Message-Id: <1519389859-14947-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: 361c7fe9b02eee7e ("mmc: dw_mmc-k3: add sd support for hi3660") Signed-off-by: Geert Uytterhoeven Reviewed-by: Shawn Lin --- v2: - Fix Fixes reference. 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; }