[PATCH] workqueue: reject watchdog thresholds that overflow jiffies

Jiacheng Xu posted 1 patch 1 month ago
There is a newer version of this series
kernel/workqueue.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] workqueue: reject watchdog thresholds that overflow jiffies
Posted by Jiacheng Xu 1 month ago
From: m0ck1ng <stitch@zju.edu.cn>

The watchdog threshold is supplied in seconds but is multiplied by HZ
before being used as a jiffies interval. Reject values that exceed
MAX_JIFFY_OFFSET / HZ so the multiplication cannot wrap and the
time_after() comparisons remain within their supported range.

The check is performed before changing the threshold or watchdog timer.
Zero remains the value used to disable the watchdog.

Fixes: 82607adcf9cdf ("workqueue: implement lockup detector")
Signed-off-by: m0ck1ng <stitch@zju.edu.cn>
---
 kernel/workqueue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index bfeef512f6dd..3ea568807f26 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -8026,6 +8026,9 @@ static int wq_watchdog_param_set_thresh(const char *val,
        if (ret)
                return ret;

+       if (thresh > MAX_JIFFY_OFFSET / HZ)
+               return -ERANGE;
+
        if (system_percpu_wq)
                wq_watchdog_set_thresh(thresh);
        else
--
2.25.1
[PATCH RESEND] workqueue: reject watchdog thresholds that overflow jiffies
Posted by Jiacheng Xu 1 month ago
The watchdog threshold is supplied in seconds but is multiplied by HZ
before being used as a jiffies interval. Reject values that exceed
MAX_JIFFY_OFFSET / HZ so the multiplication cannot wrap and the
time_after() comparisons remain within their supported range.

The check is performed before changing the threshold or watchdog timer.
Zero remains the value used to disable the watchdog.

Fixes: 82607adcf9cdf ("workqueue: implement lockup detector")
Signed-off-by: Jiacheng Xu <stitch@zju.edu.cn>
---
 kernel/workqueue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index bfeef512f6dd..3ea568807f26 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -8026,6 +8026,9 @@ static int wq_watchdog_param_set_thresh(const char *val,
        if (ret)
                return ret;

+       if (thresh > MAX_JIFFY_OFFSET / HZ)
+               return -ERANGE;
+
        if (system_percpu_wq)
                wq_watchdog_set_thresh(thresh);
        else
--
2.25.1
Re: [PATCH RESEND] workqueue: reject watchdog thresholds that overflow jiffies
Posted by Tejun Heo 3 weeks, 6 days ago
The posted patch was whitespace-damaged (tabs expanded to spaces) and
didn't apply as-is. Restored the tabs and applied to wq/for-7.3-fixes.
Please fix up the email setup for future postings.

Thanks.

--
tejun