Quite by chance stumbled upon some code in kernel jungles and was a bit confused. There are two implementations of kzalloc()
: in tools/virtio/linux/kernel.h and the main one in linux/slab.h. Obviously, in most cases the second one is used. But sometimes the "virtio" kzalloc()
is used.
"virtio" kzalloc()
looks like this:
static inline void *kzalloc(size_t s, gfp_t gfp)
{
void *p = kmalloc(s, gfp);
memset(p, 0, s);
return p;
}
My confusion is that "fake" kmalloc()
used inside "tools" directory can return NULL-pointer. Also it looks like the memset()
implementation doesn't check NULL-pointers so there could be NULL-pointer dereference.
Is it a bug or am I missing something?
virtio/linux/kernel.h
and ` fprintf (stderr` and that it usesmalloc
andposix_memalign
it looks like a userspace header. – Craigie