From 332c11344a3c5b064982d556dd40c7a17fdf44e9 Mon Sep 17 00:00:00 2001 From: Suraj Sonawane Date: Mon, 25 Nov 2024 13:19:48 +0530 Subject: [PATCH] v2fix kernel BUG in const_folio_flags syz test Signed-off-by: Suraj Sonawane --- include/linux/page-flags.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 2220bfec2..214ad9d6d 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -8,6 +8,7 @@ #include #include +#include #include #ifndef __GENERATING_BOUNDS_H #include @@ -306,6 +307,12 @@ static const unsigned long *const_folio_flags(const struct folio *folio, { const struct page *page = &folio->page; + long nr_pages = folio_nr_pages(folio); + if (n >= nr_pages) { + pr_err("Invalid folio index: n=%u, folio_nr_pages=%u\n", n, folio_nr_pages(folio)); + return -EINVAL; + } + VM_BUG_ON_PGFLAGS(PageTail(page), page); VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page); return &page[n].flags; -- 2.34.1