Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1975181rwe; Fri, 2 Sep 2022 06:51:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR5i8q5jlsYz0vm4Hao4eXurXZSx9EJdk9WMtK4Y7u3lobN8rAAR8s6qB+a6mkU1o/N+lPTY X-Received: by 2002:a17:902:e5c7:b0:174:e71e:30ef with SMTP id u7-20020a170902e5c700b00174e71e30efmr21428102plf.30.1662126710967; Fri, 02 Sep 2022 06:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126710; cv=none; d=google.com; s=arc-20160816; b=WUhCR+uN9LdMLE9YMmilQRmbyBOOOJM0HLgS8Z4XFUBSuGQozj26yaJE4zeYApYpT/ b5j2pPcgpCwQKMIu298YI2xeVGpRE7+uBn7Jn8UJaVQ9TL9t8tj3CARG6WpSZHP3Jaay K1HF2UmlEc6D1LUx5roNx0yvQtrWDye2gEAX4eig6vOhBhegAt92WaV9iT98TvH9y5yG lrmqQyFIIZZbWsq27Gz0EfxUu0zHEhveZKC9HnlBmfExqJUuECm3hJODWi38k7mgX0tN vzj5viUYsls8w8HxylxZLF8RiYGregqYyL+aK+oBV9jkOf4HFQElAYmO84JYL/KRX+i0 hKzA== 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=hkMeez/pG80pv6xTjfsZOOC0E1AEI7IuCiJnqfWBJSw=; b=HOzjeibAuyfWPnO2uonGP7Uo2N1b5O40ujvdx+daUCaY5dK5G2RSq3/QzDuhxuv1kk +QpqpFbCb9yMrhMKboiex8u6GwH6ZRyHgIhyn2LPu2U2RD/NQBF0kWiI56TRaeLimpIk N41ArffX0WgXlqJgPvh+rtC59STGGbrQ4VNn/saFortpMIzE+KF0BsOsATkbjyAWq+zD gsfMWgAOPgZRbVh/MtUezGgnQznWXsQGvwRP/3PvQrs5SaUUZpph2lRcYESsBZO/hLOd OAn8if1Gai9yBt7URc/tIKlwkwPzyA6XmpMBU/OwcL/mf4sKRjhW6p5ztwz9aE2qS81Z WYNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mgOhocRf; 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 f12-20020a056a001acc00b0052e677b7056si2253912pfv.279.2022.09.02.06.51.38; Fri, 02 Sep 2022 06:51:50 -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=mgOhocRf; 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 S237745AbiIBMwC (ORCPT + 99 others); Fri, 2 Sep 2022 08:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236137AbiIBMvR (ORCPT ); Fri, 2 Sep 2022 08:51:17 -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 505F5F826C; Fri, 2 Sep 2022 05:36:58 -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 1178AB82ACD; Fri, 2 Sep 2022 12:35:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B88CC433D6; Fri, 2 Sep 2022 12:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662122106; bh=Uk4hLiPJocqiO6tbAqBSSCacJn6LjD8UNbJhRkRruFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mgOhocRfLFDENL3l2CU/RcjtHIldn+oyUSnpoff+Tcl+/6cBKNe2UvA2Tn7UNzYSc 6FbyrZ0bKCmRRAP8BFXt/nWGipPAGeF13cKsukp3Fm0DOazOyW0HxZ6F7NINU41MvX E5P47FGnXPlE9o9ctO6uFlfdZbqk+C0aBAK2g3FY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Letu Ren , Helge Deller Subject: [PATCH 5.19 15/72] fbdev: fb_pm2fb: Avoid potential divide by zero error Date: Fri, 2 Sep 2022 14:18:51 +0200 Message-Id: <20220902121405.285931536@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121404.772492078@linuxfoundation.org> References: <20220902121404.772492078@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=unavailable 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: Letu Ren commit 19f953e7435644b81332dd632ba1b2d80b1e37af upstream. In `do_fb_ioctl()` of fbmem.c, if cmd is FBIOPUT_VSCREENINFO, var will be copied from user, then go through `fb_set_var()` and `info->fbops->fb_check_var()` which could may be `pm2fb_check_var()`. Along the path, `var->pixclock` won't be modified. This function checks whether reciprocal of `var->pixclock` is too high. If `var->pixclock` is zero, there will be a divide by zero error. So, it is necessary to check whether denominator is zero to avoid crash. As this bug is found by Syzkaller, logs are listed below. divide error in pm2fb_check_var Call Trace: fb_set_var+0x367/0xeb0 drivers/video/fbdev/core/fbmem.c:1015 do_fb_ioctl+0x234/0x670 drivers/video/fbdev/core/fbmem.c:1110 fb_ioctl+0xdd/0x130 drivers/video/fbdev/core/fbmem.c:1189 Reported-by: Zheyu Ma Signed-off-by: Letu Ren Signed-off-by: Helge Deller Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/pm2fb.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/video/fbdev/pm2fb.c +++ b/drivers/video/fbdev/pm2fb.c @@ -617,6 +617,11 @@ static int pm2fb_check_var(struct fb_var return -EINVAL; } + if (!var->pixclock) { + DPRINTK("pixclock is zero\n"); + return -EINVAL; + } + if (PICOS2KHZ(var->pixclock) > PM2_MAX_PIXCLOCK) { DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));