Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2025464rwe; Fri, 2 Sep 2022 07:31:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR659vvp3nTApHywi2kQ3eEJn/r+Of8XjasjDqP7tzib6o+QyjkAkV8mVxXNzkgA49l6NbUW X-Received: by 2002:a17:907:7f9f:b0:73d:6e87:17ce with SMTP id qk31-20020a1709077f9f00b0073d6e8717cemr27113905ejc.366.1662129065826; Fri, 02 Sep 2022 07:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662129065; cv=none; d=google.com; s=arc-20160816; b=AdEMMGxBjlTkKBj8Uagzt/q65QfJ/HNbBrgBWWCEI19WURKJU7MrhpA+IxHJKfh2Zt i5ptNiG/oCEoxYvwgu6nuAHOc8FtXE69BzKp0EdM0NDf7FNQYFxqXX5ZheUOD4LGBiC0 8Hjt3qlLmbcm7Syug3d+lTrNQJEhp61PVMgQvZBXcL8DOAdi7ytxNvi+cLDkNar/Bthk vlUefQv5xgUMMVxaU3H5qEdO/okmcUKMWaQ6haboPC7Opbb0RZc+LECslyXGbG0FfpiC 2EwKsPPdD+YHwbk0UIDEcvHDryCW8RmLkb6N2LP/UVZ75JH//j09Pt0OcGucBhTqjgZz p80Q== 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=a5uzfOk60WFFY0fh+xCHCkfyFtUwkMdOiTI3xISOpbc=; b=p0zsOPMW1hnQJ8vMicR5NAWKyCDtiI4oRtyywYUljBQGlu7D+cwjykl7jhM8qQGl2n 3UuzPECjYixR+FPrOclIeiJzKzJUGWZSDlZueledSnS7T/Hq7jpZD2JyWvQrSVR1ONxt FlUoniWp3b9hVPSor4PopGHzTZJBBSQE1D9Ma1MoZKitgqR6ukmhwd7fXCptFCs607wQ zr2LQoWo90Phg5L1WudjkbKV5F/h3Im/UE68NZNo73MF5yzMg2iI9KdkF3hxOZ1SbmqE 5bM+A388VWD3LwfXd14Yb+YQrQfDWzRYrfX/z9vgms66bSJrgdX+UePyHyanZjVYU+pz qTcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Aw3XBgf; 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 ne27-20020a1709077b9b00b0073d19e6ce0bsi2037023ejc.301.2022.09.02.07.30.36; Fri, 02 Sep 2022 07:31: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=1Aw3XBgf; 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 S236306AbiIBMX6 (ORCPT + 99 others); Fri, 2 Sep 2022 08:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236237AbiIBMXG (ORCPT ); Fri, 2 Sep 2022 08:23:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCB69D87E0; Fri, 2 Sep 2022 05:21:54 -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 D0E00620ED; Fri, 2 Sep 2022 12:21:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEBF2C433C1; Fri, 2 Sep 2022 12:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121300; bh=X2kyHRGmPFA4IG7DMX7lJ498RS9kJ6XcbHqpncdeLrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Aw3XBgfwTPJpXaX3MBwXEOlqqqik8ZfAybFJx2CO6JcTzqE8mBpsdU41OWEgmUo6 z0251/s3SxmvohcMgM/rmuRNPOB/HbS/6RWClecfx3g8QcywPyS1MYK706luHrFyFJ q0rliq4MXp6fCQbMMvddrfSbZZ6ExkyyZVgQBK/c= 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 4.9 25/31] fbdev: fb_pm2fb: Avoid potential divide by zero error Date: Fri, 2 Sep 2022 14:18:51 +0200 Message-Id: <20220902121357.673526487@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121356.732130937@linuxfoundation.org> References: <20220902121356.732130937@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: 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 @@ -614,6 +614,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));