From: Zheng Yejian Date: Sat, 15 May 2021 14:06:31 +0000 (+0800) Subject: acct: fix potential integer overflow in encode_comp_t() X-Git-Tag: v6.6.17~5997^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5f31c655bcc01b6da53b836ac951c1556245305;p=platform%2Fkernel%2Flinux-rpi.git acct: fix potential integer overflow in encode_comp_t() The integer overflow is descripted with following codes: > 317 static comp_t encode_comp_t(u64 value) > 318 { > 319 int exp, rnd; ...... > 341 exp <<= MANTSIZE; > 342 exp += value; > 343 return exp; > 344 } Currently comp_t is defined as type of '__u16', but the variable 'exp' is type of 'int', so overflow would happen when variable 'exp' in line 343 is greater than 65535. Link: https://lkml.kernel.org/r/20210515140631.369106-3-zhengyejian1@huawei.com Signed-off-by: Zheng Yejian Cc: Hanjun Guo Cc: Randy Dunlap Cc: Vlastimil Babka Cc: Zhang Jinhao Signed-off-by: Andrew Morton --- diff --git a/kernel/acct.c b/kernel/acct.c index 31b09cf..010667c 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -350,6 +350,8 @@ static comp_t encode_comp_t(u64 value) exp++; } + if (exp > (((comp_t) ~0U) >> MANTSIZE)) + return (comp_t) ~0U; /* * Clean it up and polish it off. */