[PATCH v3 0/3] fix unexpected type conversions and potential overflows
From: Qi Zheng
Date: Fri Mar 27 2026 - 06:28:20 EST
From: Qi Zheng <zhengqi.arch@xxxxxxxxxxxxx>
Changes in v3:
- squash [PATCH v2 4/4] into [PATCH v2 2/4] (suggested-by Lorenzo Stoakes)
- split complex calculation into multiple steps (suggested-by Lorenzo Stoakes)
- collect Reviewed-bys
- rebase onto the next-20260326
Changes in v2:
- modified all commit messages. (suggested-by Lorenzo Stoakes)
- added a fix patch to resolve the unexpected massive positive number
(pointed-by Harry Yoo and sashiko)
- fix the print type mismatch in [PATCH 3/3]
- collect Reviewed-by
Hi all,
As Harry Yoo pointed out [1], in scenarios where massive state updates occur
(e.g., during the reparenting of LRU folios), the values passed to memcg stat
update functions can accumulate and exceed the upper limit of a 32-bit integer.
If the parameter types are not large enough (like 'int') or are handled
incorrectly, it can lead to severe truncation, potential overflow issues,
and unexpected type conversion bugs.
This series aims to address these issues by correcting the parameter types
in the relevant functions, and fixing an implicit conversion bug in
memcg_state_val_in_pages().
This series is based on the next-20260326.
Comments and suggestions are welcome!
Thanks,
Qi
[1]. https://lore.kernel.org/all/acDxaEgnqPI-Z4be@hyeyoo/
Qi Zheng (3):
mm: memcontrol: correct the type of stats_updates to unsigned long
mm: memcontrol: change val type to long in
__mod_memcg_{lruvec_}state()
mm: memcontrol: correct the nr_pages parameter type of
mem_cgroup_update_lru_size()
include/linux/memcontrol.h | 2 +-
include/trace/events/memcg.h | 10 ++++-----
mm/memcontrol.c | 40 +++++++++++++++++++++---------------
3 files changed, 29 insertions(+), 23 deletions(-)
--
2.20.1