Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4486217rwe; Tue, 30 Aug 2022 10:57:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6oJOuJCxoaNHLkLpvlskJsMiEirha9Iu5Gf9NrgxwOBEc+6S5VEvqOoLIjNlTgLfar8BKY X-Received: by 2002:a05:6402:35c7:b0:448:95be:380 with SMTP id z7-20020a05640235c700b0044895be0380mr6913991edc.393.1661882228374; Tue, 30 Aug 2022 10:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661882228; cv=none; d=google.com; s=arc-20160816; b=tSKZIAxHK955SZx2j6tk61OYChjkVYN6PImNE8g8sML/EfiC8BdINcdgHGqNwtXC2Y X6ElPgIkRxrgqMQjBK+ttZl79xJWXxVKZGsLXHlYaqNgYjDbNLugQUqOSPgZp2Esvtex VP3b7mL3PIQ8TQoCOmgRxJSq5BSPhdr0jmiZga/+P6PqzZ8usfUEe1H6vrZubuxT5n3r GgbZNG6++vmc0stKQgHzehjvLSdE2TyBee1yzzOTOUT/NBS+cb7DJs9fzEux5Wx3MCER SW8kVcNtu2jbISkTRS/64nrxEdSHbOf94ZT4EkyuV3kAfZ3N08MPbp5zROpxsYh9on36 bMvQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L7HeaVnA2HWqMFUdVb3fQFO6bLEs65vycVqKVQQqxGQ=; b=uwYyAepX+LfuXmI9Ao9y2sDI0xMNA4fYy73Uq8KriwucPkT0BE4nDwFcUY1m+J/h4i Irwk4yn8eM7ihdfPzH9Mec0ErZLS1210ZkgJd/LmO8hdG6oX0IT5quvdsjcPn8kYTT0W Pv06YqS2TKv9e1JFF/n5jXozAj4yluNUbA5YOj1AwCLmYst7vc25RCFylNw4rsqkNbhK PV5xE8bKnXTPKA9L6e/4xGlJnr+OwAaRp0QiwHUto5fawkdIAWfEno5AoWHDoXM62P/R 755fRQdAmb3FMD0GIp1ulTzcw7IU8MedywYR/95ldZq7mbdAc5w6suXbhMS6Kb+aEtzk xqGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pGXgE+9H; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a170906c08300b0073d635877ffsi8125680ejz.478.2022.08.30.10.56.42; Tue, 30 Aug 2022 10:57:08 -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=@kernel.org header.s=k20201202 header.b=pGXgE+9H; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231434AbiH3RXa (ORCPT + 99 others); Tue, 30 Aug 2022 13:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbiH3RWo (ORCPT ); Tue, 30 Aug 2022 13:22:44 -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 5B382F493E; Tue, 30 Aug 2022 10:20: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 CD61361734; Tue, 30 Aug 2022 17:20:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46326C433C1; Tue, 30 Aug 2022 17:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661880053; bh=SiimXSh2Ur3GproHmiMWpVk5SoQv/iNe1BlOzQpcE3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pGXgE+9HZIxov0U7SLss5jgDPOEv7XcsKdHPF2KIpyW+qv1iIi/80bZN2X4ZbIlgu r43Ucwq+zh0d7Hn87ZRAdQ2dh5H6uG17AXumVZJ56QKULyoZ9YAJLKVLPfqsd4IHz8 DDS9KLoH1sphyPfnkDZDfvoM/pcL+ULcZCHybE8AVipZqOGIIYq5+m5fo/V5FqDJc4 3A9zOzxkJJFqBi5gIRIVOdUmp0HtWATaMVCQ+6hDjMqxfsQZj+4cHrdXyI1KJAc3eS 4ziJy/h8YIMOrrCwwvEW8GqF/uhITXyr6G9C7pPdaKQCFkRZdR0DaoyHbql/lxERMD +2sTjC0ClUhEA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Letu Ren , Zheyu Ma , Helge Deller , Sasha Levin , baihaowen@meizu.com, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.19 28/33] fbdev: fb_pm2fb: Avoid potential divide by zero error Date: Tue, 30 Aug 2022 13:18:19 -0400 Message-Id: <20220830171825.580603-28-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220830171825.580603-1-sashal@kernel.org> References: <20220830171825.580603-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 19f953e7435644b81332dd632ba1b2d80b1e37af ] 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: Sasha Levin --- drivers/video/fbdev/pm2fb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c index d3be2c64f1c08..8fd79deb1e2ae 100644 --- a/drivers/video/fbdev/pm2fb.c +++ b/drivers/video/fbdev/pm2fb.c @@ -617,6 +617,11 @@ static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 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)); -- 2.35.1