From patchwork Fri May 8 12:31:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 226093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E43C47254 for ; Fri, 8 May 2020 13:20:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 475FB24982 for ; Fri, 8 May 2020 13:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588944047; bh=uYTutWpeFVx8U1uosvVPfF9K6SerEPchJOh+0W11+ig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wwRHpb/YXaQjLTk92LS9yKSOqTdsCFoa3mkpldNr75LEcajJzoS2IV3MoQvKMkUxT Hy7VicicxkxbCKIWZWjcbo3yhEYuGbt5cgM/tjCk+GfUgvx5p579wYxLgYa1VtwOc9 /1g15AxRwL5QrTN26hsaoIobucKevzNbN04b5B0s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728089AbgEHNUm (ORCPT ); Fri, 8 May 2020 09:20:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:34866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgEHMks (ORCPT ); Fri, 8 May 2020 08:40:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 6F82B24973; Fri, 8 May 2020 12:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941647; bh=uYTutWpeFVx8U1uosvVPfF9K6SerEPchJOh+0W11+ig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTMu3o7JhsE6cRQ5JMzZDeEAzRQ7mm4MSEjqxI+e+jOmfRRGPPziEBTK7BeSz3Ru1 c6t+SLa8HNyNuPS6Y78o2wQDX9GYYmF18DYxlazHsRWJz+qrTO7CLJVrB51U4stX3A PEbDsQGZJH3TYPjy63U0MUsicUfU8XNQ4omf6+R4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski Subject: [PATCH 4.4 117/312] serial: samsung: Fix possible out of bounds access on non-DT platform Date: Fri, 8 May 2020 14:31:48 +0200 Message-Id: <20200508123132.697716151@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123124.574959822@linuxfoundation.org> References: <20200508123124.574959822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Krzysztof Kozlowski commit 926b7b5122c96e1f18cd20e85a286c7ec8d18c97 upstream. On non-DeviceTree platforms, the index of serial device is a static variable incremented on each probe. It is incremented even if deferred probe happens when getting the clock in s3c24xx_serial_init_port(). This index is used for referencing elements of statically allocated s3c24xx_serial_ports array. In case of re-probe, the index will point outside of this array leading to memory corruption. Increment the index only on successful probe. Reported-by: Bartlomiej Zolnierkiewicz Fixes: b497549a035c ("[ARM] S3C24XX: Split serial driver into core and per-cpu drivers") Signed-off-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/samsung.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/samsung.c +++ b/drivers/tty/serial/samsung.c @@ -1841,8 +1841,6 @@ static int s3c24xx_serial_probe(struct p ourport->min_dma_size = max_t(int, ourport->port.fifosize, dma_get_cache_alignment()); - probe_index++; - dbg("%s: initialising port %p...\n", __func__, ourport); ret = s3c24xx_serial_init_port(ourport, pdev); @@ -1872,6 +1870,8 @@ static int s3c24xx_serial_probe(struct p if (ret < 0) dev_err(&pdev->dev, "failed to add cpufreq notifier\n"); + probe_index++; + return 0; }