linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] watchdog: fix array may be out of bound
@ 2021-12-13  3:34 zhangyue
  2021-12-13  4:03 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: zhangyue @ 2021-12-13  3:34 UTC (permalink / raw)
  To: wim, linux; +Cc: linux-watchdog, linux-kernel

In this function, the param 'idx' may be
equal to 'DW_WDT_NUM_TOPS'.
At this time, the array 'dw_wdt->timeouts'
may be out of bound

Signed-off-by: zhangyue <zhangyue1@kylinos.cn>
---
 drivers/watchdog/dw_wdt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index cd578843277e..15fb1895c085 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -155,6 +155,9 @@ static unsigned int dw_wdt_get_min_timeout(struct dw_wdt *dw_wdt)
 			break;
 	}
 
+	if (idx == DW_WDT_NUM_TOPS)
+		return 1;
+
 	return dw_wdt->timeouts[idx].sec;
 }
 
-- 
2.30.0


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

* Re: [PATCH] watchdog: fix array may be out of bound
  2021-12-13  3:34 [PATCH] watchdog: fix array may be out of bound zhangyue
@ 2021-12-13  4:03 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-12-13  4:03 UTC (permalink / raw)
  To: zhangyue, wim; +Cc: linux-watchdog, linux-kernel

On 12/12/21 7:34 PM, zhangyue wrote:
> In this function, the param 'idx' may be
> equal to 'DW_WDT_NUM_TOPS'.
> At this time, the array 'dw_wdt->timeouts'
> may be out of bound
> 
> Signed-off-by: zhangyue <zhangyue1@kylinos.cn>
> ---
>   drivers/watchdog/dw_wdt.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
> index cd578843277e..15fb1895c085 100644
> --- a/drivers/watchdog/dw_wdt.c
> +++ b/drivers/watchdog/dw_wdt.c
> @@ -155,6 +155,9 @@ static unsigned int dw_wdt_get_min_timeout(struct dw_wdt *dw_wdt)
>   			break;
>   	}
>   
> +	if (idx == DW_WDT_NUM_TOPS)
> +		return 1;
> +

Please look at the code (and the comments) more closely.
This can not happen.

Guenter

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

end of thread, other threads:[~2021-12-13  4:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  3:34 [PATCH] watchdog: fix array may be out of bound zhangyue
2021-12-13  4:03 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).