acct: fix potential integer overflow in encode_comp_t()
authorZheng Yejian <zhengyejian1@huawei.com>
Sat, 15 May 2021 14:06:31 +0000 (22:06 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 1 Dec 2022 00:13:18 +0000 (16:13 -0800)
commitc5f31c655bcc01b6da53b836ac951c1556245305
treeb8bf5588b37bda48fff034aa91653d7df092d207
parent457139f16ae15d86df1e491fc45a9ea56def57b5
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 <zhengyejian1@huawei.com>
Cc: Hanjun Guo <guohanjun@huawei.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zhang Jinhao <zhangjinhao2@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/acct.c