linux/mm/kmsan
Ryan Roberts 4795d205d7 mm: kmsan: fix poisoning of high-order non-compound pages
kmsan_free_page() is called by the page allocator's free_pages_prepare()
during page freeing.  Its job is to poison all the memory covered by the
page.  It can be called with an order-0 page, a compound high-order page
or a non-compound high-order page.  But page_size() only works for order-0
and compound pages.  For a non-compound high-order page it will
incorrectly return PAGE_SIZE.

The implication is that the tail pages of a high-order non-compound page
do not get poisoned at free, so any invalid access while they are free
could go unnoticed.  It looks like the pages will be poisoned again at
allocation time, so that would bookend the window.

Fix this by using the order parameter to calculate the size.

Link: https://lkml.kernel.org/r/20260104134348.3544298-1-ryan.roberts@arm.com
Fixes: b073d7f8ae ("mm: kmsan: maintain KMSAN metadata for page operations")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Tested-by: Alexander Potapenko <glider@google.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-01-14 22:16:25 -08:00
..
Makefile kmsan: disable ftrace in kmsan core code 2023-02-20 12:46:16 -08:00
core.c mm: fix some typos in mm module 2025-11-16 17:27:52 -08:00
hooks.c mm/kmsan: fix kmsan kmalloc hook when no stack depots are allocated yet 2025-11-09 21:19:42 -08:00
init.c kmsan: apply clang-format to files mm/kmsan/ 2025-05-21 09:55:15 -07:00
instrumentation.c kmsan: rework kmsan_in_runtime() handling in kmsan_report() 2025-05-21 09:55:16 -07:00
kmsan.h kmsan: drop the declaration of kmsan_save_stack() 2025-05-21 09:55:16 -07:00
kmsan_test.c kmsan: fix out-of-bounds access to shadow memory 2025-09-25 16:10:34 -07:00
report.c kmsan: rework kmsan_in_runtime() handling in kmsan_report() 2025-05-21 09:55:16 -07:00
shadow.c mm: kmsan: fix poisoning of high-order non-compound pages 2026-01-14 22:16:25 -08:00