Subject: CVE-2024-42316: mm/mglru: fix div-by-zero in vmpressure_calc_level()

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

mm/mglru: fix div-by-zero in vmpressure_calc_level()

evict_folios() uses a second pass to reclaim folios that have gone through
page writeback and become clean before it finishes the first pass, since
folio_rotate_reclaimable() cannot handle those folios due to the
isolation.

The second pass tries to avoid potential double counting by deducting
scan_control->nr_scanned.  However, this can result in underflow of
nr_scanned, under a condition where shrink_folio_list() does not increment
nr_scanned, i.e., when folio_trylock() fails.

The underflow can cause the divisor, i.e., scale=scanned+reclaimed in
vmpressure_calc_level(), to become zero, resulting in the following crash:

  [exception RIP: vmpressure_work_fn+101]
  process_one_work at ffffffffa3313f2b

Since scan_control->nr_scanned has no established semantics, the potential
double counting has minimal risks.  Therefore, fix the problem by not
deducting scan_control->nr_scanned in evict_folios().

The Linux kernel CVE team has assigned CVE-2024-42316 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 6.1 with commit 359a5e1416ca and fixed in 6.1.103 with commit 8de7bf77f210
	Issue introduced in 6.1 with commit 359a5e1416ca and fixed in 6.6.44 with commit d6510f234c7d
	Issue introduced in 6.1 with commit 359a5e1416ca and fixed in 6.10.3 with commit a39e38be632f
	Issue introduced in 6.1 with commit 359a5e1416ca and fixed in 6.11 with commit 8b671fe1a879

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2024-42316
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	mm/vmscan.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/8de7bf77f21068a5f602bb1e59adbc5ab533509d
	https://git.kernel.org/stable/c/d6510f234c7d117790397f9bb150816b0a954a04
	https://git.kernel.org/stable/c/a39e38be632f0e1c908d70d1c9cd071c03faf895
	https://git.kernel.org/stable/c/8b671fe1a879923ecfb72dda6caf01460dd885ef