Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3408753rwa; Tue, 23 Aug 2022 04:24:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR6eYhSDSVME4b9QeV24FpN9fVFbMxBYINKly0bnCsNs0r77c/t1e/XSEGwfSMBZgD4HqEWr X-Received: by 2002:a17:902:a70e:b0:172:c859:dcc1 with SMTP id w14-20020a170902a70e00b00172c859dcc1mr17956094plq.121.1661253876917; Tue, 23 Aug 2022 04:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253876; cv=none; d=google.com; s=arc-20160816; b=ZrmNvlVD2UyeOH1gT36yy2cR6J3ugK5k8m7iBqf7J9zovkF4v+Bofr5R5LMET2OXDm s53RUa8k67ZTCr4SVgtQUp5pcDVh4bpinPDRBT0xTeJ6OmhKoNEBRxCQe9NMocXs9xZC WCFMvZeH3uBd+JelKLU6fTUMvNIEPt1X9N68JLW1gzX2QAW8OTyH+MR2fJHxUmQ52SH0 RJ8zcaR7SF+spDvEyDiobfvmRY+cq/2vfQpragA9M773q+NZBysPZ5+tmg9BnwrDrI1m hRi7dQUvIzDkB5cmehQ2ZnhtUEtZ6n6e/YsNxf11BzDepNE2cojNo+yu88MiQW4Ba0Lm sf7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FT6Ce9mhC9+OSN0YDTO9vdEjvORw9ZkFdYI1BoD5BRg=; b=h6zIBSP2WPI+Zdq7F52ykj3swABnuLj59TaQ+LUIrdFRnMNmJCV7FHSZ3Go4ojrMsZ R9dOxKQJYEZ1qQP2ldYiV9wTxNlKaLWKK21C24kAzjxzTu+O3GxUSJCycbhc2WNNM6bN C6N2nXejkjTesX7+4e62Iw0T7eWWPq1QxN2e1fM+bzVSFoIiE4iTbXv6kgkO/ey9BWHo a4D6QCYUI0AsifaRsWCODmbzW6daXrJPuNgx/JrxQwKMArIdbHPoyyrhCxMoHglS1hsE J09ZvpcRoYh6D+oFWdsH+S0WN6VVn4SmIzZIUqJbB3qYtdUt7xFbhfxwssDR33khGa42 hV7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uu3U7LB9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a17090322ce00b0016eec129304si16713074plg.259.2022.08.23.04.24.25; Tue, 23 Aug 2022 04:24:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uu3U7LB9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356992AbiHWKwu (ORCPT + 99 others); Tue, 23 Aug 2022 06:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355860AbiHWKo7 (ORCPT ); Tue, 23 Aug 2022 06:44:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832356CD0D; Tue, 23 Aug 2022 02:10:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2DC22B81C63; Tue, 23 Aug 2022 09:10:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07A83C433C1; Tue, 23 Aug 2022 09:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245849; bh=wTxpJY+B15fweHM9fBmoHGEdTlkxs3vXb9rtlhbnw7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uu3U7LB94U5jj9wxbLi4ExC1mbXY2yk84S1r9m7Aqp/wzAbS89ckaWivwOxyrKa1Q XF1yCAUXYzPhxSPnyyh0x1P1yUPCG4/0P5brgbAzeWuZdPE1J+E59+Y6YCfSRpcfkP gu4BlUOLI8JTdp2J0S01Ag7CAz6GgtZrf/P7gpfM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Helge Deller , Sasha Levin Subject: [PATCH 4.19 179/287] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Tue, 23 Aug 2022 10:25:48 +0200 Message-Id: <20220823080106.800250184@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheyu Ma [ Upstream commit 2f1c4523f7a3aaabe7e53d3ebd378292947e95c8 ] Since the user can control the arguments of the ioctl() from the user space, under special arguments that may result in a divide-by-zero bug in: drivers/video/fbdev/arkfb.c:784: ark_set_pixclock(info, (hdiv * info->var.pixclock) / hmul); with hdiv=1, pixclock=1 and hmul=2 you end up with (1*1)/2 = (int) 0. and then in: drivers/video/fbdev/arkfb.c:504: rv = dac_set_freq(par->dac, 0, 1000000000 / pixclock); we'll get a division-by-zero. The following log can reveal it: divide error: 0000 [#1] PREEMPT SMP KASAN PTI RIP: 0010:ark_set_pixclock drivers/video/fbdev/arkfb.c:504 [inline] RIP: 0010:arkfb_set_par+0x10fc/0x24c0 drivers/video/fbdev/arkfb.c:784 Call Trace: fb_set_var+0x604/0xeb0 drivers/video/fbdev/core/fbmem.c:1034 do_fb_ioctl+0x234/0x670 drivers/video/fbdev/core/fbmem.c:1110 fb_ioctl+0xdd/0x130 drivers/video/fbdev/core/fbmem.c:1189 Fix this by checking the argument of ark_set_pixclock() first. Fixes: 681e14730c73 ("arkfb: new framebuffer driver for ARK Logic cards") Signed-off-by: Zheyu Ma Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/arkfb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c index 13ba371e70aa..bfa221b68d71 100644 --- a/drivers/video/fbdev/arkfb.c +++ b/drivers/video/fbdev/arkfb.c @@ -778,7 +778,12 @@ static int arkfb_set_par(struct fb_info *info) return -EINVAL; } - ark_set_pixclock(info, (hdiv * info->var.pixclock) / hmul); + value = (hdiv * info->var.pixclock) / hmul; + if (!value) { + fb_dbg(info, "invalid pixclock\n"); + value = 1; + } + ark_set_pixclock(info, value); svga_set_timings(par->state.vgabase, &ark_timing_regs, &(info->var), hmul, hdiv, (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1, -- 2.35.1