From patchwork Fri Feb 23 13:38:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 877093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rRmFOXTb"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="q4Toc/fE"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3znt4j6Kw0z9sW6 for ; Sat, 24 Feb 2018 00:54:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=/UiR+93YQ8Ja86uPddZKbczC6CE3Nhl8SssULGBShWg=; b=rRm FOXTbwo31kCd0FWWcPJIZUukTN5GwhIBLaYlmlXIsBjOBnpyGvAyjfl4IcHG9YXCnxo0mGW1Eaols 3NFhThXsba3hOnrz66KGUa1BLMncVu5q58YgP2jFXI+K1f9Cecj3wJq6hCrHEiicEgrRXRZqGFqzD uvC3LflwFs/4PRHFV/IOLNauPIX+tgyeYPZpfs51fjNLGk/zLYxHhRZqQpTFrKq4QOcJBH9i+ZgT+ cLP6EA3Q8jxbqPUvvyRGpAQ/6NXiB4yVGtWSRht20qZESCiB3eXtpD7TNNJHcfXoxLClk1E2fb5lj JZW66kCXA+Bu+n0TnBv2ZEZOt0OXkdg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epDnv-0003hA-Pf; Fri, 23 Feb 2018 13:54:27 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epDnu-0003Kl-0r for linux-snps-arc@bombadil.infradead.org; Fri, 23 Feb 2018 13:54:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3ikDNR7UobfOHC17xdnqt6+0i44IT0hlBBWfqRBHD7M=; b=q4Toc/fEJrRN2uptprJPsF4wW IgjLnSmreizZXySu8xOEjOni6h1YH+1Kq+JuOfmuR/BKjkLBZa7B3ETp+rYkzTlT8ug9LRhYKBASk CnDwMCyUGyM2kOI+V6k5bkBfeYy6wr9EGLPk8v1YVxOC6u3iu6dZ/+giSwkwCO4ZaArmnDmN7S/az RxkNHaUBctZ1TYTZAbD5Vniv1DsA9p581p1y3ByAeyLDdRp6ewZz+7mMgGla3K5Sf61xhVDOj7H3O TxyPgtdJpb1QPKcv3PoE3UfjntdMrkUd5Cf3ZQlUmu/mWQT/g2BSCW8Pkn+rkmRbewByuDumTaHAT PeayFsZbg==; Received: from leibniz.telenet-ops.be ([195.130.137.77]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epDZ9-0003ak-1U for linux-snps-arc@lists.infradead.org; Fri, 23 Feb 2018 13:39:14 +0000 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by leibniz.telenet-ops.be (Postfix) with ESMTPS id 3znskZ6HQdzMqn6k for ; Fri, 23 Feb 2018 14:38:46 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by albert.telenet-ops.be with bizsmtp id EDee1x00s3XaVaC06DeerG; Fri, 23 Feb 2018 14:38:44 +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 1epDYc-0004sU-K2; Fri, 23 Feb 2018 14:38:38 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1epDYc-0008LE-ID; Fri, 23 Feb 2018 14:38:38 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman Subject: [PATCH v2 0/9] serial: Fix out-of-bounds accesses through DT aliases Date: Fri, 23 Feb 2018 14:38:28 +0100 Message-Id: <1519393117-31998-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_133911_102880_9C5E8361 X-CRM114-Status: GOOD ( 19.86 ) X-Spam-Score: -2.4 (--) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-2.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [195.130.137.77 listed in list.dnswl.org] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Barry Song , Geert Uytterhoeven , Vineet Gupta , Michal Simek , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-serial@vger.kernel.org, Jiri Slaby , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi all, Serial drivers used on DT platforms use the "serialN" alias in DT to obtain the serial port index for a specific port. Drivers typically use a fixed-size array for keeping track of all available serial ports. However, several drivers do not perform any validation on the index obtained from DT, which may lead to out-of-bounds accesses of these fixed-size arrays. While the DTB passed to the kernel might be considered trusted, some of these out-of-bounds accesses can be triggered by a legitimate DTB: - In some drivers the size of the array is defined by a Kconfig symbol, so a user who doesn't need all serial ports may lower this value rightfully, - Tomorrow's new SoC may have more serial ports than the fixed-size array in today's driver can accommodate, which the user may forget to enlarge. Hence this series fixes that by adding checks for out-of-range aliases, logging an error message when triggered. Changes compared to v1: - Fix Fixes references, - Use ARRAY_SIZE(), - Fix off-by-one error in patch [5/9], - Document where the non-DT case is also fixed by a patch. Tested on r8a7791/koelsch (sh-sci), all other drivers were compile-tested only. Thanks for your comments! Geert Uytterhoeven (9): serial: arc_uart: Fix out-of-bounds access through DT alias serial: fsl_lpuart: Fix out-of-bounds access through DT alias serial: imx: Fix out-of-bounds access through serial port index serial: mxs-auart: Fix out-of-bounds access through serial port index serial: pxa: Fix out-of-bounds access through serial port index serial: samsung: Fix out-of-bounds access through serial port index serial: sh-sci: Fix out-of-bounds access through DT alias serial: sirf: Fix out-of-bounds access through DT alias serial: xuartps: Fix out-of-bounds access through DT alias drivers/tty/serial/arc_uart.c | 5 +++++ drivers/tty/serial/fsl_lpuart.c | 4 ++++ drivers/tty/serial/imx.c | 6 ++++++ drivers/tty/serial/mxs-auart.c | 4 ++++ drivers/tty/serial/pxa.c | 4 ++++ drivers/tty/serial/samsung.c | 4 ++++ drivers/tty/serial/sh-sci.c | 4 ++++ drivers/tty/serial/sirfsoc_uart.c | 5 +++++ drivers/tty/serial/xilinx_uartps.c | 2 +- 9 files changed, 37 insertions(+), 1 deletion(-)