Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3406305rwa; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR40w9sm5tabGa9YzQp+bK96sP8SCBUgDKhXe1QEms9lzG2kEcYVDEn/cbaORzBrbbhD8vv6 X-Received: by 2002:a17:903:32c5:b0:172:b0dc:ba44 with SMTP id i5-20020a17090332c500b00172b0dcba44mr23572527plr.92.1661253721059; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253721; cv=none; d=google.com; s=arc-20160816; b=nz2d8uKDqBP8srgYR58NtYWpBQE/j2u+CXVYc3SQbVRxBc393JhN0V34g1OhJeJOPH QdsGJgbjQITjdp3FurH9UNIYIaQu49G7ol1QDNCHiba2KcJ5TevGF28GSOKJP7ISFzCW Z88diInuQgAsMHTGKgc5z9s2ncyRVwTYWUDDJohXX4Jgt2k176nL0k6dgaHP/B7PzXlt 7qnqI1ZCVRL2i/Wiv6KhibNQg+oF5Pe2vbAWwEsP9O/YHp7hN4c1FqFCCK0KatuMpcmT DQDRC4XavwaafQ4m0azDLhTtkH/PmIJAnnSULcW2+rhYa5hWnw/PXo82UynVVFCLSUfl 6d4g== 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=e23DJPAqFnOoe24MLMuAvrJClJPAhH2hDL5HnHrUo2EIHiuZUPW7zB/aT/ckzH6p+f yRHvPqLXEnErjb4XLg3rDMYv4TXoeqwGz9kTVgR5mmbbs4vGw0OQ64XgtqenSiP4lZxT JkfH+YXM+AdA+i+7z4ayevh+cRI9Xh8R/RX9w67Sq3cKhiKoWXFm+J43ve9m8J0G7Oyu gP0ftaplZ7K5FHj6z7vkSZmg1aDuQHliGnJ8pKKkBYIRNeeybbTZ6ZSMAzjbu02Fshyr GNBzWfJxI+xsRTiq8mPAd5WzdpLAztVsGxS2xqRqxPxEFmcqMpiyOqpTYhHv4smCimRX CDAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2LpBY1G3; 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 l8-20020a63ea48000000b0041b577f3356si14476246pgk.720.2022.08.23.04.21.50; Tue, 23 Aug 2022 04:22:01 -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=2LpBY1G3; 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 S1352062AbiHWKEV (ORCPT + 99 others); Tue, 23 Aug 2022 06:04:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348019AbiHWJ70 (ORCPT ); Tue, 23 Aug 2022 05:59:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1B0A1D77; Tue, 23 Aug 2022 01:48:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E96A161517; Tue, 23 Aug 2022 08:48:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D066BC433D7; Tue, 23 Aug 2022 08:48:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244484; bh=wTxpJY+B15fweHM9fBmoHGEdTlkxs3vXb9rtlhbnw7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2LpBY1G3OjsVCwZh+3mf6tgtB+lygOAQT/uPPs7liC9EBlwqkRfyf8kFpxPqh/q0r fWEHAT2CXu1w5zLYA4Ez2y6KU1BoWHXPa6UMDuxuDi7UIBhTqC7ZD3p9sCIzsFsnM0 Xr1vY/en0tlw0VdYzw64DSNy2vhN4C27em1UKw3A= 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.14 144/229] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Tue, 23 Aug 2022 10:25:05 +0200 Message-Id: <20220823080058.812832833@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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