lkml.org 
[lkml]   [2022]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: 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

    \
     
     \ /
      Last update: 2022-07-08 10:08    [W:6.592 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site