Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2882548rwb; Mon, 15 Aug 2022 13:14:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4UI/88Xp3zsoAlQVckFCD7lEgPLOVQ9vUkZaY8bUsupMUu+DCZPVU5YJnmJcdSMqFo9ise X-Received: by 2002:a17:907:1689:b0:731:e57:bf23 with SMTP id hc9-20020a170907168900b007310e57bf23mr11477921ejc.388.1660594479897; Mon, 15 Aug 2022 13:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594479; cv=none; d=google.com; s=arc-20160816; b=nWXscStrTsMaHW24Xlp+aNs+4jp9UJbm0zW7PKtxWLdQhIKIstDwoj/RwMeeora05h jUtC7f0aA+Cp9l6vEWa/u+VecM9f7UenxvLegx/RszSaog5Y/ndVdDzizil6QR5ufIJ7 h1UD4g/W1eCr8Vji/vREl5qE2SX+hgoBI6ewpgWf+TJkXEXxaMncZBVP7miqmov02f1k O0TsOtkjoMYlwmFlnCmcL/lHiImrcsv2yc1PcXni0Q69BL+Yvx/r3GPzM9AeUc3NAWnD OVdpxBSanKSs/V3hBKnfdai2ntby6E1dTc48Y3N/ibrApIFhDugBlrtA00ZHmM5otXGD A+Kw== 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=m9032xaA7itaLnj+aZBhX17z3watKJcRkdOnSki/ZoA=; b=yBft5mXTYVkHnNvr+ki014isVgD/NzFxnCOAvwQyuVSqi3SAUFtMgSshra81D8ejr0 UtPVo18xZvT5Tj69dKr5ks51mMNRYzMgAKcIscQ2HbWgCgz81QEfOZPzRg2QRN4ZXWYx J55uygTLgI2TquKee3M7JopCYUsNdK8ToorQkvnC4x97VROETRAxU2uW2P6flnZpiuHA StkM531P9uSpPOarMMVImJ218i4rPWm+l6NO606C4I4mm5krmATZPsmms9XybAz5t9tw Q23FciVczVtmcItGKuGkgPEH8ctPRNv96mPsyNMi45sClbU6M8zLPBJ7XdTiynI3BDEp 8ayg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t50fAoim; 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 cw7-20020a170906c78700b00730abba3122si6990606ejb.467.2022.08.15.13.14.14; Mon, 15 Aug 2022 13:14:39 -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=t50fAoim; 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 S1344781AbiHOTor (ORCPT + 99 others); Mon, 15 Aug 2022 15:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344734AbiHOTl0 (ORCPT ); Mon, 15 Aug 2022 15:41:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71B741D0E; Mon, 15 Aug 2022 11:47:32 -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 0A3CCB810A1; Mon, 15 Aug 2022 18:47:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3511AC433C1; Mon, 15 Aug 2022 18:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589249; bh=LCo2QkVytE7Tr9hl2fNVtY5d98hSWfj7DY3qjB6UhnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t50fAoimKA7TpEdmkjaGj4CkzaSFRLS8IYIawA5jAojqB2JbZDbAIig14GeWud1nC 6A1KIWJr21l0vM/VOc2KD0u499ZRTpz5uqUBR74Ze0Xe1LmIXJSiYfM4hEf2FwmAUW gAEcHK2M420TKS2z+QMfvsJ4oLr7QizREj+Zor+I= 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.15 658/779] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Mon, 15 Aug 2022 20:05:02 +0200 Message-Id: <20220815180405.492821485@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 edf169d0816e..d94cc5ad1ef6 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