Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3261252rwb; Mon, 15 Aug 2022 22:36:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR74K9jNjHwoDUJAzkoTQM87DuPmvqGJHG2JvOQxnu54DoR+BSdYdrBgAzEu2v9MbEPBMtpJ X-Received: by 2002:a05:6a00:1786:b0:52e:625d:a08d with SMTP id s6-20020a056a00178600b0052e625da08dmr19996742pfg.76.1660628169250; Mon, 15 Aug 2022 22:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628169; cv=none; d=google.com; s=arc-20160816; b=tkgOnQBdnJFCH35BoTr6HscC5E9xiCrrKkDuB+pv0wFrd0zKarJtzflDboRqg5LaVm YvESYM9M9u85cTreM8dVJ/380nTdxrYI/H7YdzwGr8kmhGGx3+zV1er5psWFvaCPrwHE FewKQE0UShEi2AL55UtN0uy+y+Ru7aoHSNOBXfR14bstfWhHhxM0Sp/0sBiNdtRMaofy H6p85FYymjn3VNnxQuBUJWCHMFqtVhK7GUqP1QHDpYC7AliRWTTjmUlU6sgQMLrnOn1C acu3QAcsFzIVEQZJ0Wupswqa3nGi/Z2LsJPBRpSt3Jdx9j/ekj3KeaVC3GXii7EXfhXw g7Cw== 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=nhv/CoXcHdNV/fKT/iXisbld+tLHnyElmGy5P32Y9u9r//xUmZ7tMA/1mmRXzuecs0 0XOpUAgR2cVzvZ9eJi+cYDHMJblsHa1oLlvlvlVxE4USAe9HH6v1bzveUQB0OgzEjYJU 0XU0sxEb6oGOhBwr2Cq71WQia3o+Vseg6w1fzYeETFe6SWN+DZzzw2wNm8VTO6DDZ+cl ZEY/9A0o5ZTaGOhPqn8nMTyhUfDDaPU385mnX8/2Jv8qVeCiDGyd1h9NIy5dfSZeNsUf 1dND0VCvK0YoSd9/RQJ9Z0encD4ln6LTDLnUhmKmjskXGG4kZFCJ6RDtV7SMNKYpNppX KUMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X8591Ges; 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 pg7-20020a17090b1e0700b001f2df5559dasi14644884pjb.115.2022.08.15.22.35.57; Mon, 15 Aug 2022 22:36:09 -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=X8591Ges; 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 S232715AbiHPErz (ORCPT + 99 others); Tue, 16 Aug 2022 00:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232404AbiHPEpb (ORCPT ); Tue, 16 Aug 2022 00:45:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937E7D805C; Mon, 15 Aug 2022 13:44:20 -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 9007761239; Mon, 15 Aug 2022 20:44:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 885F0C433C1; Mon, 15 Aug 2022 20:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596259; bh=fsOMfTvKS1OwyHIHiFZi4yp3lzMzwBLEDwhB4KCaDkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X8591Ges2otGfVffoFwi9Eh9teNN+GCmAs+Zhy7RiAiMQmNDhxabsQO6TBGISNAOt Se3J0z9UXDZ1uPBlHYRDPSHncBqHVCFJazU7wg8UtgLlpe8owJ7W1c0eAQw31VLPLh aODoT8H8kAloadu3e+yCMQkIlnLXI9e/oppYnQIc= 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.19 1023/1157] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Mon, 15 Aug 2022 20:06:19 +0200 Message-Id: <20220815180520.836992065@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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