Messages in this thread | | | From | Maurizio Lombardi <> | Date | Fri, 8 Jul 2022 10:06:53 +0200 | Subject | Re: Re: [PATCH v2] mm: page_frag: Warn_on when frag_alloc size is bigger than PAGE_SIZE |
| |
st 1. 6. 2022 v 14:49 odesílatel 愚树 <chen45464546@163.com> napsal: > Can we just add code to the relatively slow path to capture the mistake > before it lead to memory corruption? > Like: > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index e6f211d..ac60a97 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5580,6 +5580,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, > /* reset page count bias and offset to start of new frag */ > nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; > offset = size - fragsz; > + BUG_ON(offset < 0); > } >
Personally, I'm not really convinced this is the best solution. The next time a driver abuses the page_frag_alloc() interface, the bug may go unnoticed for a long time... until a server in production runs into OOM and crashes because it hits the BUG_ON().
And why should the kernel panic? It's perfectly able to handle this condition by failing the allocation and returning NULL, and printing a warning maybe.
Maurizio
| |