From patchwork Tue Feb 20 09:40:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10229705 X-Patchwork-Delegate: geert@linux-m68k.org 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 AAAC6602A7 for ; Tue, 20 Feb 2018 10:00:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BD8E285D2 for ; Tue, 20 Feb 2018 10:00:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90B7D285D9; Tue, 20 Feb 2018 10:00:11 +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=unavailable 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 35590285D2 for ; Tue, 20 Feb 2018 10:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751469AbeBTJ7P (ORCPT ); Tue, 20 Feb 2018 04:59:15 -0500 Received: from albert.telenet-ops.be ([195.130.137.90]:59734 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751358AbeBTJ51 (ORCPT ); Tue, 20 Feb 2018 04:57:27 -0500 Received: from ayla.of.borg ([84.194.111.163]) by albert.telenet-ops.be with bizsmtp id CxxM1x0053XaVaC06xxMaA; Tue, 20 Feb 2018 10:57:25 +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 1eo4fo-0002mu-Vr; Tue, 20 Feb 2018 10:57:20 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1eo4PU-0000M4-GD; Tue, 20 Feb 2018 10:40:28 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman Cc: Barry Song , Vineet Gupta , Jiri Slaby , Michal Simek , linux-serial@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 9/9] serial: xuartps: Fix out-of-bounds access through DT alias Date: Tue, 20 Feb 2018 10:40:24 +0100 Message-Id: <1519119624-1268-10-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519119624-1268-1-git-send-email-geert+renesas@glider.be> References: <1519119624-1268-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cdns_uart_port[] array is indexed using a value derived from the "serialN" alias in DT, which may lead to an out-of-bounds access. Fix this by adding a range check. Fixes: 1f118c02a1819856 ("serial: xuartps: Fix out-of-bounds access through DT alias") Signed-off-by: Geert Uytterhoeven --- drivers/tty/serial/xilinx_uartps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index b9b2bc76bcac606c..abcb4d09a2d866d0 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -1110,7 +1110,7 @@ static struct uart_port *cdns_uart_get_port(int id) struct uart_port *port; /* Try the given port id if failed use default method */ - if (cdns_uart_port[id].mapbase != 0) { + if (id < CDNS_UART_NR_PORTS && cdns_uart_port[id].mapbase != 0) { /* Find the next unused port */ for (id = 0; id < CDNS_UART_NR_PORTS; id++) if (cdns_uart_port[id].mapbase == 0)