Skip to content

Commit

Permalink
acct: fix potential integer overflow in encode_comp_t()
Browse files Browse the repository at this point in the history
[ Upstream commit c5f31c6 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Zheng Yejian authored and gregkh committed Dec 31, 2022
1 parent a16731f commit 0aac6e6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/acct.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ static comp_t encode_comp_t(unsigned long value)
exp++;
}

if (exp > (((comp_t) ~0U) >> MANTSIZE))
return (comp_t) ~0U;
/*
* Clean it up and polish it off.
*/
Expand Down

0 comments on commit 0aac6e6

Please sign in to comment.