From: Schspa Shi <schspa@gmail.com>
To: wim@linux-watchdog.org, linux@roeck-us.net
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
zhaohui.shi@horizon.ai, Schspa Shi <schspa@gmail.com>
Subject: [PATCH] watchdog: dw_wdt: Fix buffer overflow when get timeout
Date: Tue, 28 Jun 2022 13:45:39 +0800 [thread overview]
Message-ID: <20220628054539.33187-1-schspa@gmail.com> (raw)
The top_val can be obtained from device-tree, if it is not configured
correctly, there will be buffer overflow.
Signed-off-by: Schspa Shi <schspa@gmail.com>
---
drivers/watchdog/dw_wdt.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index cd578843277e..1f8605c0d712 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 (WARN_ON_ONCE(idx == DW_WDT_NUM_TOPS))
+ idx = DW_WDT_NUM_TOPS - 1;
+
return dw_wdt->timeouts[idx].sec;
}
@@ -178,6 +181,9 @@ static unsigned int dw_wdt_get_timeout(struct dw_wdt *dw_wdt)
break;
}
+ if (WARN_ON_ONCE(idx == DW_WDT_NUM_TOPS))
+ idx = DW_WDT_NUM_TOPS - 1;
+
/*
* In IRQ mode due to the two stages counter, the actual timeout is
* twice greater than the TOP setting.
--
2.29.0
next reply other threads:[~2022-06-28 5:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 5:45 Schspa Shi [this message]
2022-06-28 13:55 ` Guenter Roeck
2022-06-28 14:30 ` Schspa Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220628054539.33187-1-schspa@gmail.com \
--to=schspa@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=wim@linux-watchdog.org \
--cc=zhaohui.shi@horizon.ai \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®