Skip to content

Commit 4795d20

Browse files
ryanhrobakpm00
authored andcommitted
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: b073d7f ("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>
1 parent fb39444 commit 4795d20

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

mm/kmsan/shadow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void kmsan_free_page(struct page *page, unsigned int order)
207207
if (!kmsan_enabled || kmsan_in_runtime())
208208
return;
209209
kmsan_enter_runtime();
210-
kmsan_internal_poison_memory(page_address(page), page_size(page),
210+
kmsan_internal_poison_memory(page_address(page), PAGE_SIZE << order,
211211
GFP_KERNEL & ~(__GFP_RECLAIM),
212212
KMSAN_POISON_CHECK | KMSAN_POISON_FREE);
213213
kmsan_leave_runtime();

0 commit comments

Comments
 (0)