linux-stable/include
SeongJae Park d44b509ba8 mm/damon: implement a function for max nr_accesses safe calculation
commit 35f5d94187 upstream.

Patch series "avoid divide-by-zero due to max_nr_accesses overflow".

The maximum nr_accesses of given DAMON context can be calculated by
dividing the aggregation interval by the sampling interval.  Some logics
in DAMON uses the maximum nr_accesses as a divisor.  Hence, the value
shouldn't be zero.  Such case is avoided since DAMON avoids setting the
agregation interval as samller than the sampling interval.  However, since
nr_accesses is unsigned int while the intervals are unsigned long, the
maximum nr_accesses could be zero while casting.

Avoid the divide-by-zero by implementing a function that handles the
corner case (first patch), and replaces the vulnerable direct max
nr_accesses calculations (remaining patches).

Note that the patches for the replacements are divided for broken commits,
to make backporting on required tres easier.  Especially, the last patch
is for a patch that not yet merged into the mainline but in mm tree.


This patch (of 4):

The maximum nr_accesses of given DAMON context can be calculated by
dividing the aggregation interval by the sampling interval.  Some logics
in DAMON uses the maximum nr_accesses as a divisor.  Hence, the value
shouldn't be zero.  Such case is avoided since DAMON avoids setting the
agregation interval as samller than the sampling interval.  However, since
nr_accesses is unsigned int while the intervals are unsigned long, the
maximum nr_accesses could be zero while casting.  Implement a function
that handles the corner case.

Note that this commit is not fixing the real issue since this is only
introducing the safe function that will replaces the problematic
divisions.  The replacements will be made by followup commits, to make
backporting on stable series easier.

Link: https://lkml.kernel.org/r/20231019194924.100347-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20231019194924.100347-2-sj@kernel.org
Fixes: 198f0f4c58 ("mm/damon/vaddr,paddr: support pageout prioritization")
Signed-off-by: SeongJae Park <sj@kernel.org>
Reported-by: Jakub Acs <acsjakub@amazon.de>
Cc: <stable@vger.kernel.org>	[5.16+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-11-28 17:15:01 +00:00
..
acpi ACPI: APEI: Fix AER info corruption when error status data has multiple sections 2023-11-28 17:14:42 +00:00
asm-generic hyperv-fixes for 6.5-rc5 2023-08-04 17:16:14 -07:00
clocksource
crypto crypto: api - Use work queue in crypto_destroy_instance 2023-09-13 09:53:05 +02:00
drm drm: bridge: samsung-dsim: Fix waiting for empty cmd transfer FIFO on older Exynos 2023-11-20 11:56:58 +01:00
dt-bindings dt-bindings: clock: qcom,gcc-sc8280xp: Add missing GDSCs 2023-09-13 09:53:27 +02:00
keys KEYS: Add forward declaration in asymmetric-parser.h 2023-06-23 16:15:37 +08:00
kunit
kvm KVM: arm64: vgic-v4: Make the doorbell request robust w.r.t preemption 2023-07-13 22:23:34 +00:00
linux mm/damon: implement a function for max nr_accesses safe calculation 2023-11-28 17:15:01 +00:00
math-emu
media media: cec: core: add adap_unconfigured() callback 2023-09-13 09:53:40 +02:00
memory
misc
net net: sched: do not offload flows with a helper in act_ct 2023-11-28 17:14:57 +00:00
pcmcia
ras
rdma rdma: fix INFINIBAND_USER_ACCESS dependency 2023-07-03 16:55:04 -07:00
rv
scsi scsi: sd: Introduce manage_shutdown device flag 2023-11-02 09:36:55 +01:00
soc firmware: tegra: Add suspend hook and reset BPMP IPC early on resume 2023-11-20 11:57:06 +01:00
sound ASoC: SOF: Pass PCI SSID to machine driver 2023-11-28 17:14:46 +00:00
target SCSI misc on 20230629 2023-06-30 11:57:07 -07:00
trace btrfs: remove v0 extent handling 2023-11-02 09:36:50 +01:00
uapi vsock: read from socket's error queue 2023-11-28 17:14:43 +00:00
ufs scsi: ufs: Fix residual handling 2023-09-13 09:53:36 +02:00
vdso
video fbdev: stifb: Make the STI next font pointer a 32-bit signed offset 2023-11-28 17:15:01 +00:00
xen xen/evtchn: Introduce new IOCTL to bind static evtchn 2023-07-26 08:42:34 +02:00