Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp289588rwb; Thu, 18 Aug 2022 04:03:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6XykYIZzIwoJDMP/FDkZOyOHxkjwidWBvmqB0UVRvqIwxsDB+VR72eyFjSEJEGPAF/RAIg X-Received: by 2002:aa7:9813:0:b0:52d:395d:c98d with SMTP id e19-20020aa79813000000b0052d395dc98dmr2464539pfl.55.1660820637693; Thu, 18 Aug 2022 04:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660820637; cv=none; d=google.com; s=arc-20160816; b=Vw9INsiwelf41JHzt0CFSIo40mfA5V2TMNb77NAs+bNBSj+xfmrEIfmKK+4NmnQshJ 9/qEfVchbpDg82cDQEel/ra4MxU9UnjY3AfskCQsP5fI39WQr5uVewuK/rPlibARkoNu KecalLTEwWX6gtKy4fcn4+hnb1uaoMVMWpQXWiA0Nss/Tv2/bbMx7mvMjRebaHEg5ZCg wxuC0Fa0vsa1h7t/8O0TDLrydiEEZqDnJSFT6RoTH8of1U21KfNEOPzUdTne10gAFLJE zfM2JKVdBLagyzkMPGIOr+dYCO01YL1Riodl/Or/TRGTippJu31Vl1LkAjkeOHIiGIhW +GWA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zfVmtS6KYvfWod3rab4fz6qOWga4E5X5CB2HKYlhhHQ=; b=WCq3cO02mWsyzDn9TJj9oeaSb/yxXKjwT3RtzXJ/P6teIZ+QYFzRWMb8xf8u6RC5Sr zQht3zlj0wdIjM3fyiE3CjPuH3Pf7XiB1/PHORCb2o4hJscyxkSrN1xJA8Fq0LNByxQR tc1FS/Qmkk2A8p6gAYVA3R+baZjTRwoQ4pawDqlmSfyMnS77srUxxLFcCC9nCnaFSbaJ DpaW0eoCQN6TESLTKRbLPZiDBpq1c9tyxbjs+VKWe4i6K+KOihfyvO9KA2jq8pvNkFmK puKOODTWfvE6MhZBrJEmMMYJIpARygbSMEcbvQDXiKQPyvuB6v1zVE36bKNn0oQ8Ciww yOWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jEGIS+8S; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a170902ccc500b0016d9d416df3si991827ple.574.2022.08.18.04.03.45; Thu, 18 Aug 2022 04:03:57 -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=@gmail.com header.s=20210112 header.b=jEGIS+8S; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243857AbiHRKoh (ORCPT + 99 others); Thu, 18 Aug 2022 06:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238978AbiHRKof (ORCPT ); Thu, 18 Aug 2022 06:44:35 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28F5B7FE5B; Thu, 18 Aug 2022 03:44:33 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id s36-20020a17090a69a700b001faad0a7a34so4310438pjj.4; Thu, 18 Aug 2022 03:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=zfVmtS6KYvfWod3rab4fz6qOWga4E5X5CB2HKYlhhHQ=; b=jEGIS+8SyNLsj44iJPWD2f6FwCHwEq/YUUlEAN64vyrvH8958MyzjjRJy7Xs5wV5r6 yL+mLLihw3u8AirH32WN4aHlfqLvLeR0pkGRQUSV0+Og3cmWs56c4IAPLZqG3k2Uzc7s /PTEahfh3u7jQfr5N6adgTjW91FkhXlwBN9Y09Dv3pT+SYxff16KvZ2mw52NkiOB1kc7 IwWBuTak94mPXTbgsjSB7TRIED/Ouc5GJNUphLIarEj7dqYLKNah/poNTPj8TIJ89h0a pydqUVEtW5VYZWrDd12y+X5WFZCuPx27553kmBvnHqQvoVZ1XU1y6S0g1MkKX2z6TkId QnIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=zfVmtS6KYvfWod3rab4fz6qOWga4E5X5CB2HKYlhhHQ=; b=iWGWStj6orX1rvCTgRPeUO2CXQQ26G5lzXMTrpQpqFshHYAY35eEp+FnLCa4yci73Q 4MObBFhltzq2BLoRabszjlZ9q3Muk6MU8zzSBxqJpWC/VyDtepABG1prYWOuBV6y+Tk9 JRTZFhYVtmahVudRH4KKuOH9bOjYSDcEPnohiiEtleJk0FRvhzF9/9Sqv9H7Cr/smZdV lDqdlPlhaRscLW9pdtitJXxJXUsnDUmQXns0WSpby1K2bY5U+8QN40uEpXl41yVR4JAF yxir9AsC30U1VB9oKC7ru6Kb2tf/w8RRyVEfQiTMacKVXiVVMFfv2lxjz7iGs+j78s7I j1iQ== X-Gm-Message-State: ACgBeo2eJgK3JsCLTe2qg9XLVeQePKAQh2fVqHv8qvWgiELdscFVKPKu +JA3zvEi5uDCFqAKfG7JzHI= X-Received: by 2002:a17:902:6b82:b0:16d:d268:3842 with SMTP id p2-20020a1709026b8200b0016dd2683842mr2194918plk.16.1660819472611; Thu, 18 Aug 2022 03:44:32 -0700 (PDT) Received: from fanta-arch.localdomain (ec2-35-78-114-158.ap-northeast-1.compute.amazonaws.com. [35.78.114.158]) by smtp.gmail.com with ESMTPSA id z12-20020aa7990c000000b0052d36feb7fcsm1263220pff.198.2022.08.18.03.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 03:44:32 -0700 (PDT) From: Letu Ren To: deller@gmx.de, baihaowen@meizu.com Cc: fantasquex@gmail.com, zheyuma97@gmail.com, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] fb_pm2: Add a check to avoid potential divide by zero error Date: Thu, 18 Aug 2022 18:44:24 +0800 Message-Id: <20220818104425.35573-1-fantasquex@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 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 --- 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 d3be2c64f1c0..8fd79deb1e2a 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.37.2