All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [v3] gpu: ipu-v3: prg: avoid possible array underflow
@ 2018-03-15 16:19 ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2018-03-15 16:19 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Arnd Bergmann, Lucas Stach, Tobias Jordan, dri-devel, linux-kernel

gcc-8 reports that we access an array with a negative index
in an error case:

drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable':
drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds]

This moves the range check in front of the first time that
variable gets used.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
----
v1: Originally sent on Dec 4, 2017.
v2: Sent again on Jan 16, after no reply, Phillipp said it was merged
v3: Ran into a related problem with CONFIG_UBSAN, sent again fixing both
---
 drivers/gpu/ipu-v3/ipu-prg.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
index 97b99500153d..83f9dd934a5d 100644
--- a/drivers/gpu/ipu-v3/ipu-prg.c
+++ b/drivers/gpu/ipu-v3/ipu-prg.c
@@ -250,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
 {
 	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
 	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
-	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
+	struct ipu_prg_channel *chan;
 	u32 val;
 
-	if (!chan->enabled || prg_chan < 0)
+	if (prg_chan < 0)
+		return;
+
+	chan = &prg->chan[prg_chan];
+	if (!chan->enabled)
 		return;
 
 	pm_runtime_get_sync(prg->dev);
@@ -280,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
 {
 	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
 	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
-	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
+	struct ipu_prg_channel *chan;
 	u32 val;
 	int ret;
 
 	if (prg_chan < 0)
 		return prg_chan;
 
+	chan = &prg->chan[prg_chan];
+
 	if (chan->enabled) {
 		ipu_pre_update(prg->pres[chan->used_pre], *eba);
 		return 0;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] [v3] gpu: ipu-v3: prg: avoid possible array underflow
@ 2018-03-15 16:19 ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2018-03-15 16:19 UTC (permalink / raw)
  To: Philipp Zabel; +Cc: linux-kernel, Tobias Jordan, dri-devel, Arnd Bergmann

gcc-8 reports that we access an array with a negative index
in an error case:

drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable':
drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds]

This moves the range check in front of the first time that
variable gets used.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
----
v1: Originally sent on Dec 4, 2017.
v2: Sent again on Jan 16, after no reply, Phillipp said it was merged
v3: Ran into a related problem with CONFIG_UBSAN, sent again fixing both
---
 drivers/gpu/ipu-v3/ipu-prg.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
index 97b99500153d..83f9dd934a5d 100644
--- a/drivers/gpu/ipu-v3/ipu-prg.c
+++ b/drivers/gpu/ipu-v3/ipu-prg.c
@@ -250,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
 {
 	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
 	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
-	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
+	struct ipu_prg_channel *chan;
 	u32 val;
 
-	if (!chan->enabled || prg_chan < 0)
+	if (prg_chan < 0)
+		return;
+
+	chan = &prg->chan[prg_chan];
+	if (!chan->enabled)
 		return;
 
 	pm_runtime_get_sync(prg->dev);
@@ -280,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
 {
 	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
 	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
-	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
+	struct ipu_prg_channel *chan;
 	u32 val;
 	int ret;
 
 	if (prg_chan < 0)
 		return prg_chan;
 
+	chan = &prg->chan[prg_chan];
+
 	if (chan->enabled) {
 		ipu_pre_update(prg->pres[chan->used_pre], *eba);
 		return 0;
-- 
2.9.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] [v3] gpu: ipu-v3: prg: avoid possible array underflow
  2018-03-15 16:19 ` Arnd Bergmann
@ 2018-03-15 16:53   ` Philipp Zabel
  -1 siblings, 0 replies; 4+ messages in thread
From: Philipp Zabel @ 2018-03-15 16:53 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Lucas Stach, Tobias Jordan, dri-devel, linux-kernel

Hi Arnd,

On Thu, 2018-03-15 at 17:19 +0100, Arnd Bergmann wrote:
> gcc-8 reports that we access an array with a negative index
> in an error case:
> 
> drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable':
> drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds]
> 
> This moves the range check in front of the first time that
> variable gets used.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

thank you, I've replaced v2 with this version in imx-drm/fixes.

regards
Philipp

> ----
> v1: Originally sent on Dec 4, 2017.
> v2: Sent again on Jan 16, after no reply, Phillipp said it was merged
> v3: Ran into a related problem with CONFIG_UBSAN, sent again fixing both
> ---
>  drivers/gpu/ipu-v3/ipu-prg.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
> index 97b99500153d..83f9dd934a5d 100644
> --- a/drivers/gpu/ipu-v3/ipu-prg.c
> +++ b/drivers/gpu/ipu-v3/ipu-prg.c
> @@ -250,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
>  {
>  	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
>  	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
> -	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
> +	struct ipu_prg_channel *chan;
>  	u32 val;
>  
> -	if (!chan->enabled || prg_chan < 0)
> +	if (prg_chan < 0)
> +		return;
> +
> +	chan = &prg->chan[prg_chan];
> +	if (!chan->enabled)
>  		return;
>  
>  	pm_runtime_get_sync(prg->dev);
> @@ -280,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
>  {
>  	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
>  	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
> -	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
> +	struct ipu_prg_channel *chan;
>  	u32 val;
>  	int ret;
>  
>  	if (prg_chan < 0)
>  		return prg_chan;
>  
> +	chan = &prg->chan[prg_chan];
> +
>  	if (chan->enabled) {
>  		ipu_pre_update(prg->pres[chan->used_pre], *eba);
>  		return 0;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [v3] gpu: ipu-v3: prg: avoid possible array underflow
@ 2018-03-15 16:53   ` Philipp Zabel
  0 siblings, 0 replies; 4+ messages in thread
From: Philipp Zabel @ 2018-03-15 16:53 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Tobias Jordan, linux-kernel, dri-devel

Hi Arnd,

On Thu, 2018-03-15 at 17:19 +0100, Arnd Bergmann wrote:
> gcc-8 reports that we access an array with a negative index
> in an error case:
> 
> drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable':
> drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds]
> 
> This moves the range check in front of the first time that
> variable gets used.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

thank you, I've replaced v2 with this version in imx-drm/fixes.

regards
Philipp

> ----
> v1: Originally sent on Dec 4, 2017.
> v2: Sent again on Jan 16, after no reply, Phillipp said it was merged
> v3: Ran into a related problem with CONFIG_UBSAN, sent again fixing both
> ---
>  drivers/gpu/ipu-v3/ipu-prg.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
> index 97b99500153d..83f9dd934a5d 100644
> --- a/drivers/gpu/ipu-v3/ipu-prg.c
> +++ b/drivers/gpu/ipu-v3/ipu-prg.c
> @@ -250,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
>  {
>  	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
>  	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
> -	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
> +	struct ipu_prg_channel *chan;
>  	u32 val;
>  
> -	if (!chan->enabled || prg_chan < 0)
> +	if (prg_chan < 0)
> +		return;
> +
> +	chan = &prg->chan[prg_chan];
> +	if (!chan->enabled)
>  		return;
>  
>  	pm_runtime_get_sync(prg->dev);
> @@ -280,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
>  {
>  	int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
>  	struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
> -	struct ipu_prg_channel *chan = &prg->chan[prg_chan];
> +	struct ipu_prg_channel *chan;
>  	u32 val;
>  	int ret;
>  
>  	if (prg_chan < 0)
>  		return prg_chan;
>  
> +	chan = &prg->chan[prg_chan];
> +
>  	if (chan->enabled) {
>  		ipu_pre_update(prg->pres[chan->used_pre], *eba);
>  		return 0;
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-15 16:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-15 16:19 [PATCH] [v3] gpu: ipu-v3: prg: avoid possible array underflow Arnd Bergmann
2018-03-15 16:19 ` Arnd Bergmann
2018-03-15 16:53 ` Philipp Zabel
2018-03-15 16:53   ` Philipp Zabel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.