Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1863640rwb; Fri, 19 Aug 2022 10:38:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qdFUrTvPtt5FV++WkZmNrOcESt0JfqZIxp0uTjveahJ4lH6FKVxzcx1QCzcjlN6S10W0M X-Received: by 2002:a63:9141:0:b0:41d:22d:1910 with SMTP id l62-20020a639141000000b0041d022d1910mr7076908pge.145.1660930716636; Fri, 19 Aug 2022 10:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930716; cv=none; d=google.com; s=arc-20160816; b=tCPl8QkEMzbD+P3T+Zvb9DGSauMH8xINJ6SNzzVEOdG0+CdIvJOnlreTq7HmuP7AzP CGLta9Ch4bqT9hz1nHS7FxdhQ0nyztH7PD/EKqllclvA1p9uyGNvgkUXJn1YZJIAiSwc ggLBGVv1hGvN5/b1blBzXFMGgE9ZZ3MUzCdQJkKHVnDJ0ZFXTe4h8OrnOOZJU39sLLIA l2NhJgRVCgPt7K6E+OGHropCBKm5C3CEbpqwaFZzNh59UBKPgyKKSuXBjwwJx59P4VpH ZrkYOKnnuqkPVq9llJjOdIVUiedtzYdLwxiOIzivn/GNwXKijhmzk34LIy0oRcA+YvEV /l4A== 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=yiSi/Kc8PyEK+4SzKVdjsrnFcJ1cl68S9iL1iAkRtpaDKkUTFx5AeTWlShvaqgzG8K Y96NfX1+z0LA9eSPofjiMpL38FssSFrNrHMTrgTRqvKRujYefQDr1daYaz+rqmbzZEYN EZ0uGYQ39CgRA09CbyX3GiQSCJTzS58i+dif2s+w07a/h/qo8cB0TsS4c8PV59T17maR RMFc6g1q482qosZ9DMZE0h5kW2/+I55Xfoq5Gv+BNqNI3gDd0qnfvKxpi12bPBJzchA1 DgE8zESIPIaj0rGOvQmaE8N5veVeIvANWEhpkbJ5/58NiPNgMbM9W2+a7douWLFPstgF u6Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qB9z85/d"; 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 ng5-20020a17090b1a8500b001f25fdf4252si5487775pjb.123.2022.08.19.10.38.25; Fri, 19 Aug 2022 10:38: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="qB9z85/d"; 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 S1353535AbiHSQic (ORCPT + 99 others); Fri, 19 Aug 2022 12:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353595AbiHSQgd (ORCPT ); Fri, 19 Aug 2022 12:36:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B2710DCC7; Fri, 19 Aug 2022 09:07:44 -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 9093CB82819; Fri, 19 Aug 2022 16:07:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED2CDC433C1; Fri, 19 Aug 2022 16:07:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925252; bh=LCo2QkVytE7Tr9hl2fNVtY5d98hSWfj7DY3qjB6UhnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qB9z85/doUsoJuxFVRGKceagqEGO3r6vl1v9ZyVQdzlm/dNpHGS2WyI29htdSG7qP YDdBKYi2n7+49KIaeokB0ScR8iLk56Z3xTAPAlhViS4vJdbJwOerFnODsof/3m7gy5 p3lIVeszXqpw5YY3uEoOr7IoG+gNG39t1qayjwwU= 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.10 432/545] video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() Date: Fri, 19 Aug 2022 17:43:22 +0200 Message-Id: <20220819153848.752648083@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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