Message ID | 20230315092254.1042615-1-harperchen1110@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2230670wrd; Wed, 15 Mar 2023 02:46:22 -0700 (PDT) X-Google-Smtp-Source: AK7set+9F+V8cO/0HKKALce5+6YxKcFVHGIziXdhsLVBE4q9MKwa4FsBaEo/MM/T0ODYahaRdfCL X-Received: by 2002:a17:902:d486:b0:19c:a866:6a76 with SMTP id c6-20020a170902d48600b0019ca8666a76mr2197190plg.42.1678873582436; Wed, 15 Mar 2023 02:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678873582; cv=none; d=google.com; s=arc-20160816; b=GcybsrCimMOkZoPqomF1XaqrBzIxfVqT9GRumwo69Bo9cUtR8IjCWBYU7mBq8Xfwh0 vuOcYf1u2eDd4ZmmFWlisNVDsmg3mf9WfPFfF+X2sc4PWDQoDElzDVhohoKcAM3JUncV 866qcX8v1Jo8Uw8BG5kDF9jToLHwygMZnRWbTEuCCytSB7VFM7j8hy+/wGzl/0vmkCaO Wc981FOG8NdBwx0fg8qpKzqOVtX4qEtkKHjUEXmrK/dVvv8EqYILb+6NenVBHGHP3SeL DDNzBJgAE/gLs/kPe8m66p+2uzg39uwgWW6/d1pYub6Y+gad0voV6lKcw8UHipwWswzj weYQ== 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=YIlDmOhHfzUv00AnBDlY+LrTEjW0fV7JmMX/NObYM/0=; b=keA7LnV+jxYTn0nDKjqmKZt99m+qeQgyCzr3k3aVi7VA4DQWGvy+OUW7+uVmPrINzF Ohiv0E7zA71e+Hi1eM6+jvjXS5cuHQpF4y6n8E9ICUD/Eu5UB7fGwGSpnFDZr8KRyJUF GtyWr17GD9qACdVYQPRtMlwuuhmKltw1uAKic7PFpDKmK24GcTzvU9xgw+GOWgPJfGTY enDJq0KwAndqTRa2jvky1yqOuHvGXHJeJGfn5NB5UpJHJRDGLlvuiI/x2fWrmJDBDzdn q/i1bnpve0fgQj76xg6SWodw2NL8+0R6bx4ikUrpR14c0h8PbFyFex9aHlcsmMEbZgds 7s/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jMwS04iE; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj13-20020a170903048d00b001a180df91besi191396plb.32.2023.03.15.02.46.07; Wed, 15 Mar 2023 02:46:22 -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=jMwS04iE; 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 S231641AbjCOJXN (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Wed, 15 Mar 2023 05:23:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231774AbjCOJXH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Mar 2023 05:23:07 -0400 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3826A23316; Wed, 15 Mar 2023 02:23:06 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-17683b570b8so20251273fac.13; Wed, 15 Mar 2023 02:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678872185; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YIlDmOhHfzUv00AnBDlY+LrTEjW0fV7JmMX/NObYM/0=; b=jMwS04iE8sVc508yTw9rVt892u9Rx8nIWzDE5QGMJFsTaUDANTrUlNIsCG6yP5o3pu LDq2LfysPHaMkjGL3j9ODWL1DA3syFL55sDXFj70tGRHmR6FlSiD87AkrDjb3TPJqvjH NyvgT/ZmlxD/mplejH8J3tRK9SroSe/gXIiUXr4kjiN6w3+4Js+9XZjU4XRY1TGZtfC1 V/xY2lkfNuaU6Xzsb1UT4vH9MPGKqL5KAkCNxKTSgucGvV3ratbp1Bn1e8d04rpmfE5j V49tuMg/Be72TYhgkZymUVkjjrEPICEUok0rFpXWcTx1OGVG8kIQctvpTa934wxhR7Bt nlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678872185; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YIlDmOhHfzUv00AnBDlY+LrTEjW0fV7JmMX/NObYM/0=; b=gIKUIOQziX+Bz1UmAvZXa6PyuqTOniZxiM4fYUfghOWML3TRanmMuRRXc05naYmeJG Vc22KcyWcUEQh0TzsQs7asFkx5feTdGj62WDrpwvjCEOAeohxQKLjXFESQYOPxOKcWyn F4KcuM2vsjiUcuXku0Y+1DBOG/tZ/t4sLWnqmSViPvQsWwd6IHBD0Xh6hoTailx7aC1R BdzR2LiNWFXSldLGMiZwPVt9ob9AiGI5DxXq9J2Koj5GBhRqPO1Q2nBFW2hAGiEJFxHB U78yTESruFn/fhlO1d0gdYT57C+MDyh1eRf5vpokQJ535fxVfJLq0OIVHQoA+/YQ79C6 R55g== X-Gm-Message-State: AO0yUKXC9nIaXvxw7swIpef2iG7GeJEb5zQckBJbQg9Wj2RW51xVHbKP qlHhK6wHwyQLvO/JokV2RN8= X-Received: by 2002:a05:6870:a446:b0:17a:c38e:823f with SMTP id n6-20020a056870a44600b0017ac38e823fmr1205376oal.51.1678872185553; Wed, 15 Mar 2023 02:23:05 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id v5-20020a056870e28500b00176209a6d6asm2037335oad.10.2023.03.15.02.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 02:23:05 -0700 (PDT) From: Wei Chen <harperchen1110@gmail.com> To: deller@gmx.de Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Wei Chen <harperchen1110@gmail.com> Subject: [PATCH] fbdev: au1200fb: Fix potential divide by zero Date: Wed, 15 Mar 2023 09:22:54 +0000 Message-Id: <20230315092254.1042615-1-harperchen1110@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760426545313659975?= X-GMAIL-MSGID: =?utf-8?q?1760426545313659975?= |
Series |
fbdev: au1200fb: Fix potential divide by zero
|
|
Commit Message
Wei Chen
March 15, 2023, 9:22 a.m. UTC
var->pixclock can be assigned to zero by user. Without
proper check, divide by zero would occur when invoking
macro PICOS2KHZ in au1200fb_fb_check_var.
Error out if var->pixclock is zero.
Signed-off-by: Wei Chen <harperchen1110@gmail.com>
---
drivers/video/fbdev/au1200fb.c | 3 +++
1 file changed, 3 insertions(+)
Comments
Hi, thanks for looking through these drivers. Am 15.03.23 um 10:22 schrieb Wei Chen: > var->pixclock can be assigned to zero by user. Without > proper check, divide by zero would occur when invoking > macro PICOS2KHZ in au1200fb_fb_check_var. > > Error out if var->pixclock is zero. > > Signed-off-by: Wei Chen <harperchen1110@gmail.com> > --- > drivers/video/fbdev/au1200fb.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c > index 81c315454428..b6b22fa4a8a0 100644 > --- a/drivers/video/fbdev/au1200fb.c > +++ b/drivers/video/fbdev/au1200fb.c > @@ -1040,6 +1040,9 @@ static int au1200fb_fb_check_var(struct fb_var_screeninfo *var, > u32 pixclock; > int screen_size, plane; > > + if (!var->pixclock) > + return -EINVAL; > + Instead of the whale-a-mole approach of fixing individual drivers, could this be solved by testing in fb_set_var [1] and fb_try_mode.? [2] Best regards Thomas [1] https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/core/fbmem.c#L958 [2] https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/core/modedb.c#L567 > plane = fbdev->plane; > > /* Make sure that the mode respect all LCD controller and -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Dear Thomas, Thank you for the kind advice. In fact, I notice there was a discussion regarding whether to put the check in each individual driver or solve this problem as a whole as you suggested. The conclusion is that it is better to keep the check per driver rather than in the caller. Related discussions are here: https://lore.kernel.org/all/YXclZQGFTr1NFjbc@ravnborg.org/ https://lore.kernel.org/all/YPgbHMtLQqb1kP0l@ravnborg.org/ https://lore.kernel.org/all/20220404084723.79089-1-zheyuma97@gmail.com/ Thanks, Wei ------ Original Message ------ From "Thomas Zimmermann" <tzimmermann@suse.de> To "Wei Chen" <harperchen1110@gmail.com>; deller@gmx.de Cc linux-fbdev@vger.kernel.org; linux-kernel@vger.kernel.org; dri-devel@lists.freedesktop.org Date 2023/3/15 18:25:52 Subject Re: [PATCH] fbdev: au1200fb: Fix potential divide by zero On Wed, 15 Mar 2023 at 18:25, Thomas Zimmermann <tzimmermann@suse.de> wrote: > > Hi, > > thanks for looking through these drivers. > > Am 15.03.23 um 10:22 schrieb Wei Chen: > > var->pixclock can be assigned to zero by user. Without > > proper check, divide by zero would occur when invoking > > macro PICOS2KHZ in au1200fb_fb_check_var. > > > > Error out if var->pixclock is zero. > > > > Signed-off-by: Wei Chen <harperchen1110@gmail.com> > > --- > > drivers/video/fbdev/au1200fb.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c > > index 81c315454428..b6b22fa4a8a0 100644 > > --- a/drivers/video/fbdev/au1200fb.c > > +++ b/drivers/video/fbdev/au1200fb.c > > @@ -1040,6 +1040,9 @@ static int au1200fb_fb_check_var(struct fb_var_screeninfo *var, > > u32 pixclock; > > int screen_size, plane; > > > > + if (!var->pixclock) > > + return -EINVAL; > > + > > Instead of the whale-a-mole approach of fixing individual drivers, could > this be solved by testing in fb_set_var [1] and fb_try_mode.? [2] > > Best regards > Thomas > > [1] > https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/core/fbmem.c#L958 > [2] > https://elixir.bootlin.com/linux/latest/source/drivers/video/fbdev/core/modedb.c#L567 > > > plane = fbdev->plane; > > > > /* Make sure that the mode respect all LCD controller and > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 Nürnberg, Germany > (HRB 36809, AG Nürnberg) > Geschäftsführer: Ivo Totev
diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 81c315454428..b6b22fa4a8a0 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1040,6 +1040,9 @@ static int au1200fb_fb_check_var(struct fb_var_screeninfo *var, u32 pixclock; int screen_size, plane; + if (!var->pixclock) + return -EINVAL; + plane = fbdev->plane; /* Make sure that the mode respect all LCD controller and