Message ID | 20230606075527.155346-1-suhui@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3240134vqr; Tue, 6 Jun 2023 01:41:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60ljZmXp1B7TBup6Sw/eBk5+JEcRNGkmqTSZhs79XDuAI+IY2PBCuQg/OgFLINklu8OWAm X-Received: by 2002:a05:620a:2b11:b0:75b:23a0:d9c0 with SMTP id do17-20020a05620a2b1100b0075b23a0d9c0mr1350318qkb.22.1686040875040; Tue, 06 Jun 2023 01:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686040875; cv=none; d=google.com; s=arc-20160816; b=TTIILVs0JOdbnFSnZIWPV3VTUkrOVEf2Zo85bYK7nGRZuLCdnfG+5epGPhF2Saeei0 Kxk68/uGaVd0hjJ+VhKcbtGxmVYFeZ1PNm4cBkyJ6sEgAQn0xeaWZF/lAKsB0qAog6Eh c1JVd1mrjVAmR4XB7vNyIS58Lq0ZmzavBLbTIAB2LwIhsZpdoxt5p1xi648sb66jZbyN yRHovwwsM21uH7vo/wPOMdE5gGThlN5JjMrR7otFyioS5oqet4oLb3UWKSW5rRkg9P3T OxL2Sa9iO5DgVQm3FIuglEbrrVUbOskr+Ts0K2L4VB3nL5qh3GKW/gnpK0bNDD5KSfaA 0Y/w== 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; bh=5jXxzf5Xp9BVWVWnYgoJBz0SX1boM2W0DcxMW2I3wNg=; b=QeZwAUsg7daL7yu32ygAhzqdeNkVsMEXgjanOuzUuR7RsW0hMfKHzaflmWpglia1VZ 6UhgotETadHgUCy5sW/rhY1k4YOPI8oSvPgmMLLNXyVhdomxTTWWK51PMfMYiK5PPUla K/9rvvSQ5G2WSR/I2jX408evAoK4YKcD5L+C/msWosav0nqk7YExjDfGx4BDZfaaoiTu fhPHj9isajo95eRpsG75SVff044VWWioTBaeR0+RlXhZusdDBsevVqiK5JQ3DJwcafcO 51Xes6Y3yJm1V0on6EsGQRbP4VJLZ2yUzsuBQwir14fbIid9pD/rXOBZMhpQjPTIvoHX 8etw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020a05622a061400b003f899c3e435si203924qta.448.2023.06.06.01.41.00; Tue, 06 Jun 2023 01:41:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236099AbjFFIAm (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 04:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236973AbjFFIAI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 04:00:08 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 481B4273D for <linux-kernel@vger.kernel.org>; Tue, 6 Jun 2023 00:57:35 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id DBF29180121FCD; Tue, 6 Jun 2023 15:55:28 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui <suhui@nfschina.com> To: Douglas Anderson <dianders@chromium.org>, Andrzej Hajda <andrzej.hajda@intel.com>, Neil Armstrong <neil.armstrong@linaro.org>, Robert Foss <rfoss@kernel.org>, Laurent Pinchart <Laurent.pinchart@ideasonboard.com>, Jonas Karlman <jonas@kwiboo.se>, Jernej Skrabec <jernej.skrabec@gmail.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch> Cc: u.kleine-koenig@pengutronix.de, andersson@kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Su Hui <suhui@nfschina.com> Subject: [PATCH] drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow Date: Tue, 6 Jun 2023 15:55:27 +0800 Message-Id: <20230606075527.155346-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1767941996796934613?= X-GMAIL-MSGID: =?utf-8?q?1767941996796934613?= |
Series |
drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow
|
|
Commit Message
Su Hui
June 6, 2023, 7:55 a.m. UTC
Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5.
Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
drivers/gpu/drm/bridge/ti-sn65dsi86.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
Hi, On Tue, Jun 6, 2023 at 12:56 AM Su Hui <suhui@nfschina.com> wrote: > > Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5. > > Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip") > Signed-off-by: Su Hui <suhui@nfschina.com> > --- > drivers/gpu/drm/bridge/ti-sn65dsi86.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c > index 7a748785c545..952aae4221e7 100644 > --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c > +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c > @@ -305,7 +305,8 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) > * The PWM refclk is based on the value written to SN_DPPLL_SRC_REG, > * regardless of its actual sourcing. > */ > - pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; > + if (i < refclk_lut_size) > + pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; I don't think this is quite the right fix. I don't think we can just skip assigning "pdata->pwm_refclk_freq". In general I think we're in pretty bad shape if we ever fail to match a refclk from the table and I'm not quite sure how the bridge chip could work at all in this case. Probably that at least deserves a warning message in the logs. There's no place to return an error though, so I guess the warning is the best we can do and then we can do our best to do something reasonable. In this case, I think "reasonable" might be that if the for loop exits and "i == refclk_lut_size" that we should set "i" to 1. According to the datasheet [1] setting a value of 5 (which the existing code does) is the same as setting a value of 1 (the default) and if it's 1 then we'll be able to look this up in the table. [1] https://www.ti.com/lit/gpn/sn65dsi86 -Doug
Hi, On 2023/6/6 23:28, Doug Anderson wrote: > Hi, > > On Tue, Jun 6, 2023 at 12:56 AM Su Hui <suhui@nfschina.com> wrote: >> Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5. >> >> Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip") >> Signed-off-by: Su Hui <suhui@nfschina.com> >> --- >> drivers/gpu/drm/bridge/ti-sn65dsi86.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> index 7a748785c545..952aae4221e7 100644 >> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> @@ -305,7 +305,8 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) >> * The PWM refclk is based on the value written to SN_DPPLL_SRC_REG, >> * regardless of its actual sourcing. >> */ >> - pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; >> + if (i < refclk_lut_size) >> + pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; > I don't think this is quite the right fix. I don't think we can just > skip assigning "pdata->pwm_refclk_freq". In general I think we're in > pretty bad shape if we ever fail to match a refclk from the table and > I'm not quite sure how the bridge chip could work at all in this case. > Probably that at least deserves a warning message in the logs. There's > no place to return an error though, so I guess the warning is the best > we can do and then we can do our best to do something reasonable. > > In this case, I think "reasonable" might be that if the for loop exits > and "i == refclk_lut_size" that we should set "i" to 1. According to > the datasheet [1] setting a value of 5 (which the existing code does) > is the same as setting a value of 1 (the default) and if it's 1 then > we'll be able to look this up in the table. I think you are right. And " if ( i >= refclk_lut_size) i=1" is a suitable change. I will send patch v2 a litter latter. Thanks for your suggestion. Su Hui > > [1] https://www.ti.com/lit/gpn/sn65dsi86 > > -Doug
Hi, On 2023/6/6 23:28, Doug Anderson wrote: > Hi, > > On Tue, Jun 6, 2023 at 12:56 AM Su Hui <suhui@nfschina.com> wrote: >> Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5. >> >> Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip") >> Signed-off-by: Su Hui <suhui@nfschina.com> >> --- >> drivers/gpu/drm/bridge/ti-sn65dsi86.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> index 7a748785c545..952aae4221e7 100644 >> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c >> @@ -305,7 +305,8 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) >> * The PWM refclk is based on the value written to SN_DPPLL_SRC_REG, >> * regardless of its actual sourcing. >> */ >> - pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; >> + if (i < refclk_lut_size) >> + pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; > I don't think this is quite the right fix. I don't think we can just > skip assigning "pdata->pwm_refclk_freq". In general I think we're in > pretty bad shape if we ever fail to match a refclk from the table and > I'm not quite sure how the bridge chip could work at all in this case. > Probably that at least deserves a warning message in the logs. There's > no place to return an error though, so I guess the warning is the best > we can do and then we can do our best to do something reasonable. > > In this case, I think "reasonable" might be that if the for loop exits > and "i == refclk_lut_size" that we should set "i" to 1. According to > the datasheet [1] setting a value of 5 (which the existing code does) > is the same as setting a value of 1 (the default) and if it's 1 then > we'll be able to look this up in the table. I think you are right, set i to 1 if i >= refclk_lut_size. I will resend this patch soon. Thanks for your reply! Su Hui > > [1] https://www.ti.com/lit/gpn/sn65dsi86 > > -Doug
diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c index 7a748785c545..952aae4221e7 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c @@ -305,7 +305,8 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) * The PWM refclk is based on the value written to SN_DPPLL_SRC_REG, * regardless of its actual sourcing. */ - pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; + if (i < refclk_lut_size) + pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; } static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata)