Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13472372ybl; Sun, 29 Dec 2019 12:43:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyJ/3z5/50bpGJr04P/a+0oxs5mwfJcmnZz/pufQHr0m+NsIF5QcCFkunHCjHofVlh8waZq X-Received: by 2002:a05:6830:3050:: with SMTP id p16mr25405750otr.301.1577652232110; Sun, 29 Dec 2019 12:43:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652232; cv=none; d=google.com; s=arc-20160816; b=UEWdi3b/iJbAcmTPrhaZCYmLHUBgn545YeXnU1UEf0hEgQ+ps1IkGyZgI7DAb3AEwF Shk2DPPhJSY06OMDY1ORUXc1nJM6/f+M3zA+Ndulsu+7rLLoXvINc6kFUCWurMvnkKcB gGrb93LaPMcbpMiAZFSYAl8S75BS6SPHIir80ejBFKxozVbX5ikxDy7PqTxlIEStLKwq B/KYcVMz7xhk6gH3SfkLx2WBiaZnAhJZVpiSyV9ZiItzcIML3OdtrEn+t+A/t7wjs8Q1 I06ibpWbnD5ByrCPM/Fo5j6IY3D8LcgGtKfNLwSIG55LxBYrOR5tR/O1VXAfSs/+VyBJ 5DmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D7zRRBoUlSOL61erGqA0UTUs//oJnT/qjyjHSHeraF0=; b=zEL1HpzptwsILTfTm0DPP512HyiSLAyNS73jJ+VZfHO0yJP722wM1c9UdDmg/wUjoc R5m1RKHfvyP/hBdeqnVbmNxBFFnPh3qbGoJPzGIMN3pQtJEbr6TbT4Cxx6ZTEHscb29J 7FJErmpyNbCJM61wMPLUiaE3AGEW2CqRSgEuxW5PbUTJ86o535oXLPKjZreCrUWzJKg7 Vr2/K/9MVPtwIn5VViPdYbUrRMltcYjRQFX0FcYsh76bZ0bMwDJgmVWNBnuiIbop123c 5AqkB59wuHXXIODbezhJKu+oKyLgkTbiHqmszWgxl/E6ZK5dmLoRyDuu0JTyIbg5IVQ2 wfpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LIH/E6Mo"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x142si17989768oia.220.2019.12.29.12.43.40; Sun, 29 Dec 2019 12:43:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LIH/E6Mo"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730449AbfL2RnQ (ORCPT + 99 others); Sun, 29 Dec 2019 12:43:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:50276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730435AbfL2RnM (ORCPT ); Sun, 29 Dec 2019 12:43:12 -0500 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 5AB2821744; Sun, 29 Dec 2019 17:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641391; bh=8bdOIu18jZB6fruSVNfOW/sII9TzV1EYlcWBJzTdZ1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIH/E6ModobQX+0SdeHfeYTmUExYWEYalTDdMn80KJz7NNAMvsjWyev4qaqq4SFi1 i2YGccOX9iAgfU8/A49MdvsDlXlkuVxf/ir59cXj+SrCYSCB62noU0WvuBPQ1SX57Q 90AQQloEcl1AieDeJX+mV7DHu+DjIKs2yPuatU84= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Sasha Levin Subject: [PATCH 5.4 046/434] drm/mipi-dbi: fix a loop in debugfs code Date: Sun, 29 Dec 2019 18:21:39 +0100 Message-Id: <20191229172705.060721032@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit d72cf01f410aa09868d98b672f3f92328c96b32d ] This code will likely crash if we try to do a zero byte write. The code looks like this: /* strip trailing whitespace */ for (i = count - 1; i > 0; i--) if (isspace(buf[i])) ... We're writing zero bytes so count = 0. You would think that "count - 1" would be negative one, but because "i" is unsigned it is a large positive numer instead. The "i > 0" condition is true and the "buf[i]" access will be out of bounds. The fix is to make "i" signed and now everything works as expected. The upper bound of "count" is capped in __kernel_write() at MAX_RW_COUNT so we don't have to worry about it being higher than INT_MAX. Fixes: 02dd95fe3169 ("drm/tinydrm: Add MIPI DBI support") Signed-off-by: Dan Carpenter [noralf: Adjust title] Signed-off-by: Noralf Trønnes Link: https://patchwork.freedesktop.org/patch/msgid/20190821072456.GJ26957@mwanda Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_mipi_dbi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c index 1961f713aaab..c4ee2709a6f3 100644 --- a/drivers/gpu/drm/drm_mipi_dbi.c +++ b/drivers/gpu/drm/drm_mipi_dbi.c @@ -1187,8 +1187,7 @@ static ssize_t mipi_dbi_debugfs_command_write(struct file *file, struct mipi_dbi_dev *dbidev = m->private; u8 val, cmd = 0, parameters[64]; char *buf, *pos, *token; - unsigned int i; - int ret, idx; + int i, ret, idx; if (!drm_dev_enter(&dbidev->drm, &idx)) return -ENODEV; -- 2.20.1