From patchwork Tue Oct 18 09:47:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9381787 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 46DB860487 for ; Tue, 18 Oct 2016 09:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36CDC29130 for ; Tue, 18 Oct 2016 09:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A2A0294E6; Tue, 18 Oct 2016 09:47:42 +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 lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B52C029130 for ; Tue, 18 Oct 2016 09:47:41 +0000 (UTC) Received: from localhost ([::1]:39932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwQzk-0004u0-E6 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Oct 2016 05:47:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwQzS-0004sw-QQ for qemu-devel@nongnu.org; Tue, 18 Oct 2016 05:47:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwQzS-00059k-45 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 05:47:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwQzM-00057Q-W6; Tue, 18 Oct 2016 05:47:17 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24181335F92; Tue, 18 Oct 2016 09:47:16 +0000 (UTC) Received: from javelin.localdomain (vpn1-48-97.bne.redhat.com [10.64.48.97]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9I9l7Yu023847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 18 Oct 2016 05:47:11 -0400 From: P J P To: Qemu Developers Date: Tue, 18 Oct 2016 15:17:05 +0530 Message-Id: <1476784025-27293-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Oct 2016 09:47:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] char: cadence: check divider against baud rate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Edgar E . Iglesias" , qemu-arm@nongnu.org, Huawei PSIRT , Prasad J Pandit , Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit The Cadence UART device emulator calculates speed by dividing the baud rate by a divider. If this divider was to be zero or if baud rate was to be lesser than the divider, it could lead to a divide by zero error. Add check to avoid it. Reported-by: Huawei PSIRT Signed-off-by: Prasad J Pandit --- hw/char/cadence_uart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index e3bc52f..b18dd7f 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -170,6 +170,10 @@ static void uart_parameters_setup(CadenceUARTState *s) baud_rate = (s->r[R_MR] & UART_MR_CLKS) ? UART_INPUT_CLK / 8 : UART_INPUT_CLK; + if (!s->r[R_BRGR] || !(s->r[R_BDIV] + 1) + || baud_rate < (s->r[R_BRGR] * (s->r[R_BDIV] + 1))) { + return; + } ssp.speed = baud_rate / (s->r[R_BRGR] * (s->r[R_BDIV] + 1)); packet_size = 1;