Skip to content

Commit ff17967

Browse files
Sergey Shtylyovmcgrof
authored andcommitted
firmware_loader: prevent integer overflow in firmware_loading_timeout()
In firmware_loading_timeout(), *int* result of __firmware_loading_timeout() multiplied by HZ might overflow before being implicitly cast to *long* when being returned. Rewrite the function using check_mul_overflow() and capping the result at LONG_MAX on actual overflow... Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool. Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> Cc: stable@vger.kernel.org Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent fd08609 commit ff17967

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/base/firmware_loader/fallback.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ void fw_fallback_set_default_timeout(void)
3535

3636
static long firmware_loading_timeout(void)
3737
{
38-
return __firmware_loading_timeout() > 0 ?
39-
__firmware_loading_timeout() * HZ : MAX_JIFFY_OFFSET;
38+
long timeout;
39+
40+
if (__firmware_loading_timeout() <= 0)
41+
return MAX_JIFFY_OFFSET;
42+
if (check_mul_overflow(__firmware_loading_timeout(), HZ, &timeout))
43+
return LONG_MAX;
44+
return timeout;
4045
}
4146

4247
static inline int fw_sysfs_wait_timeout(struct fw_priv *fw_priv, long timeout)

0 commit comments

Comments
 (0)