From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 798D6C17443 for ; Sun, 10 Nov 2019 02:48:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 450FB22583 for ; Sun, 10 Nov 2019 02:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573354135; bh=kL6FU9R5156ffI4nRNa+Oy0TifVNeORlwgtnvFjve3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EYwC/Lsi36caedxvLP2mYh087JWCStpxDMOZS2tsBrCjQrOiUIXT2V9R52XAdgz0h TYco3RM2LqDil36GPgjPAr3bqieGBY9RxkJqrHvqOgWwqlGfQZBaWDXDxV3x1X/naM bWI3DJCLI3UEKR7fOOPynIJjTlSTdv2HCgdAzKHU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729350AbfKJCsv (ORCPT ); Sat, 9 Nov 2019 21:48:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:56682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729327AbfKJCsv (ORCPT ); Sat, 9 Nov 2019 21:48:51 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 760CC22583; Sun, 10 Nov 2019 02:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573354130; bh=kL6FU9R5156ffI4nRNa+Oy0TifVNeORlwgtnvFjve3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KxyDu0MZ57EF4QLeITtSXLiTVnxXkbS5qMg9N6GGhMtDYWz00eo/B1sFFooXMaxq5 K3+lfhG3bETRnqde4JTIIOUqPFr63hpOuig6KqVBmq4Koiqiik8AICirFCJ5Ytyw4R g1mtqQLxzQjd/fDl7V/E2HqTV2YwH1CU6wDBxgXA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anton Vasilyev , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 03/66] serial: mxs-auart: Fix potential infinite loop Date: Sat, 9 Nov 2019 21:47:42 -0500 Message-Id: <20191110024846.32598-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191110024846.32598-1-sashal@kernel.org> References: <20191110024846.32598-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anton Vasilyev [ Upstream commit 5963e8a3122471cadfe0eba41c4ceaeaa5c8bb4d ] On the error path of mxs_auart_request_gpio_irq() is performed backward iterating with index i of enum type. Underline enum type may be unsigned char. In this case check (--i >= 0) will be always true and error handling goes into infinite loop. The patch changes the check so that it is valid for signed and unsigned types. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev Acked-by: Uwe Kleine-König Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/mxs-auart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 1d9d778828bae..515bf18c82943 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -1635,8 +1635,9 @@ static int mxs_auart_request_gpio_irq(struct mxs_auart_port *s) /* * If something went wrong, rollback. + * Be careful: i may be unsigned. */ - while (err && (--i >= 0)) + while (err && (i-- > 0)) if (irq[i] >= 0) free_irq(irq[i], s); -- 2.20.1