[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ys6Pp6ZPwJTdJvpk@ip-172-31-24-42.ap-northeast-1.compute.internal>
Date: Wed, 13 Jul 2022 09:25:59 +0000
From: Hyeonggon Yoo <42.hyeyoo@...il.com>
To: Christoph Lameter <cl@...two.de>
Cc: Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Joe Perches <joe@...ches.com>,
Vasily Averin <vasily.averin@...ux.dev>,
Matthew WilCox <willy@...radead.org>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Marco Elver <elver@...gle.com>
Subject: Re: [PATCH 16/16] mm/sl[au]b: check if large object is valid in
__ksize()
On Tue, Jul 12, 2022 at 05:13:44PM +0200, Christoph Lameter wrote:
> On Tue, 12 Jul 2022, Hyeonggon Yoo wrote:
>
> > __ksize() returns size of objects allocated from slab allocator.
> > When invalid object is passed to __ksize(), returning zero
> > prevents further memory corruption and makes caller be able to
> > check if there is an error.
> >
> > If address of large object is not beginning of folio or size of
> > the folio is too small, it must be invalid. Return zero in such cases.
>
> Why return 0 if there is an error and why bother the callers with these
> checks. BUG()?
I thought BUG should be used when there is no other solution.
> > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > index 1f8db7959366..0d6cbe9d7ad0 100644
> > --- a/mm/slab_common.c
> > +++ b/mm/slab_common.c
> > @@ -1013,8 +1013,12 @@ size_t __ksize(const void *object)
> >
> > folio = virt_to_folio(object);
> >
> > - if (unlikely(!folio_test_slab(folio)))
> > + if (unlikely(!folio_test_slab(folio))) {
> > + if (WARN_ON(object != folio_address(folio) ||
> > + folio_size(folio) <= KMALLOC_MAX_CACHE_SIZE))
>
> Hmmm... This may change things a bit. Before this patch it was possible to
> determine the storage size of order-0 pages using ksize(). Now this
> returns 0?
>
> I guess this is an error since the order-0 page cannot come from slab
> allocations.
comment in ksize() says:
"The caller must guarantee that objp points to a valid object
previously allocated with either kmalloc() or kmem_cache_alloc()."
It should not be used on order-0 page that is not allocated from slab. No?
Powered by blists - more mailing lists