* slab: krealloc with GFP_ZERO defect
@ 2013-08-29 21:47 Joe Perches
2013-09-10 23:51 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: Joe Perches @ 2013-08-29 21:47 UTC (permalink / raw)
To: Christoph Lameter, Pekka Enberg, Matt Mackall, linux-mm; +Cc: LKML
This sequence can return non-zeroed memory from the
padding area of the original allocation.
ptr = kzalloc(foo, GFP_KERNEL);
if (!ptr)
...
new_ptr = krealloc(ptr, foo + bar, GFP_KERNEL | __GFP_ZERO);
If the realloc size is within the first actual allocation
then the additional memory is not zeroed.
If the realloc size is not within the original allocation
size, any non-zeroed padding from the original allocation
is overwriting newly allocated zeroed memory.
Maybe someone more familiar with the alignment & padding can
add the proper memset(,0,) for the __GFP_ZERO cases and also
optimize kmalloc_track_caller to not use __GFP_ZERO, memcpy
the current (non padded) size and zero the newly returned
remainder if necessary.
from: mm/util.c
---------------------------
static __always_inline void *__do_krealloc(const void *p, size_t new_size,
gfp_t flags)
{
void *ret;
size_t ks = 0;
if (p)
ks = ksize(p);
if (ks >= new_size)
return (void *)p;
ret = kmalloc_track_caller(new_size, flags);
if (ret && p)
memcpy(ret, p, ks);
return ret;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: slab: krealloc with GFP_ZERO defect
2013-08-29 21:47 slab: krealloc with GFP_ZERO defect Joe Perches
@ 2013-09-10 23:51 ` Joe Perches
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2013-09-10 23:51 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Pekka Enberg, Matt Mackall, linux-mm, LKML
ping?
On Thu, 2013-08-29 at 14:47 -0700, Joe Perches wrote:
> This sequence can return non-zeroed memory from the
> padding area of the original allocation.
>
> ptr = kzalloc(foo, GFP_KERNEL);
> if (!ptr)
> ...
> new_ptr = krealloc(ptr, foo + bar, GFP_KERNEL | __GFP_ZERO);
>
> If the realloc size is within the first actual allocation
> then the additional memory is not zeroed.
>
> If the realloc size is not within the original allocation
> size, any non-zeroed padding from the original allocation
> is overwriting newly allocated zeroed memory.
>
> Maybe someone more familiar with the alignment & padding can
> add the proper memset(,0,) for the __GFP_ZERO cases and also
> optimize kmalloc_track_caller to not use __GFP_ZERO, memcpy
> the current (non padded) size and zero the newly returned
> remainder if necessary.
>
> from: mm/util.c
> ---------------------------
> static __always_inline void *__do_krealloc(const void *p, size_t new_size,
> gfp_t flags)
> {
> void *ret;
> size_t ks = 0;
>
> if (p)
> ks = ksize(p);
>
> if (ks >= new_size)
> return (void *)p;
>
> ret = kmalloc_track_caller(new_size, flags);
> if (ret && p)
> memcpy(ret, p, ks);
>
> return ret;
> }
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-10 23:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-29 21:47 slab: krealloc with GFP_ZERO defect Joe Perches
2013-09-10 23:51 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).