Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3029299rwb; Mon, 15 Aug 2022 16:28:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4DkrJcpFtffLVljnxgVjjfzI1jzUtYkeNWtGoRgkjsgnsrxrKfbfS4ONOtoPL5TzYmL1OK X-Received: by 2002:a17:907:2bd7:b0:730:8f34:28ad with SMTP id gv23-20020a1709072bd700b007308f3428admr11784123ejc.632.1660605965893; Mon, 15 Aug 2022 16:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605965; cv=none; d=google.com; s=arc-20160816; b=HN/BXbGI8IJ4Q9XF8EXZZMqwnTVDDE3OP5NGWlLVUYjANaPKve+RYT8RTjDNi4ArQL 43tnG95neBzMU1sgH+s5QUnd0EgGz3CozWeY9zxbTPm26ySc1pI3LApar91cE3xxH7iU RmIyU7ImgzmgPleAWvBGJmSIXoGl+6wnK/jgHOQ2LXOnLtQ81xMIU97ZSnraKqHa1d0W Xuw95Dxd6d1PiR93fq60wTeFh+gVarObJFuZZ/cWBz4ahQDbwPK85aOSwmSCpinRSMmu a7ytl0dLbwNVz3pVtMPPlqQr8ZDW7zSM15u0r9MeHZk2fIpwPLMk6vRkRAL7EGRjgVP+ KXhg== 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=frGaNNY8cECB/5My9uMWYT5zdpnTzQ5MMizNcRmY07s=; b=l4+MaTiFvHtdaofe9BV+H6PrBtFpUkmuHR9+n9amSDnAhoTFQXma7AFn/UpWlzkp8a 8SF65O68i2CN6ap9NKKVmxed+0fP76MKId2aWQiZeZ1LlMwW5Hc+QpjYKmnRoPdvrYDA B4kDVrLFotaDzom4PL2R2LS1KD+d1kvdpFN54NdJxmfxwJmuVQXkFQBWWVmyfD0+7W6e 9V6rqK8mkIRrKNVZIQ0zAGDxgZ+V9NrabVBqPdK1I+YLiiv++MlFt8aJnVsOQ7bsDH2W Tg3nwuB0O07qIHLcOev4OuAlCyHFIWene5dddelXwfovv9hVw07IOT4XA6tphBESuSQM JoqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jtMXy5dv; 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 wu12-20020a170906eecc00b00730e4be74d1si9685242ejb.815.2022.08.15.16.25.40; Mon, 15 Aug 2022 16:26:05 -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=jtMXy5dv; 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 S245047AbiHOXCK (ORCPT + 99 others); Mon, 15 Aug 2022 19:02:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245104AbiHOXAW (ORCPT ); Mon, 15 Aug 2022 19:00:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E89D78215; Mon, 15 Aug 2022 12:57:34 -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 B120460FD8; Mon, 15 Aug 2022 19:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F89CC433C1; Mon, 15 Aug 2022 19:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593453; bh=fsOMfTvKS1OwyHIHiFZi4yp3lzMzwBLEDwhB4KCaDkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jtMXy5dvCtwB66Jtf0ziuNaLAdCCzOwNn+VYi1PfZMEvFgp0BewYruWazUeGClJZx +7zmz+3m0Jp2HyJhr5969z3gVZfQ47wsojd3kydmt1O8ZCaswOYt5e8exl2+hn4KIN byMHTMRpNcmJvybI3EUukqwmqN22ssO2ACyUI97I= 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 5.18 0948/1095] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Mon, 15 Aug 2022 20:05:47 +0200 Message-Id: <20220815180508.344597258@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 eb3e47c58c5f..ed76ddc7df3d 100644 --- a/drivers/video/fbdev/arkfb.c +++ b/drivers/video/fbdev/arkfb.c @@ -781,7 +781,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