Linux kernel NULL-pointer dereference in memset from kzalloc
The header is mainly used for userspace testing, such as virtio_test
.
From the git-log of tools/virtio/virtio_test.c
:
This is the userspace part of the tool: it includes a bunch of stubs for linux APIs, somewhat simular to linuxsched. This makes it possible to recompile the ring code in userspace.
A small test example is implemented combining this with vhost_test module.
So yes, the code is a bit unsafe (clean coding would test for a NULL
pointer prior to memset()
and bail out with an appropriate error message), but since it is just a testing tool, it seems to have been considered uncritical to skip this test.
Yes, that definitely looks like a bug.
The tools/
subdirectory is a collection of user space tools (as the name suggests). You can also see this by the fact that several C standard library headers are included. So this of course is not a kernel bug (that would have been very bad), just a minor oversight in the virtio
testing tool.
That virtio
testing tool seems to re-define some kernel APIs to mock their behavior in userspace. That function though doesn't seem to be ever used in practice, just merely defined.
marco:~/git/linux/tools/virtio$ grep -r kzalloc
linux/kernel.h:static inline void *kzalloc(size_t s, gfp_t gfp)
ringtest/ptr_ring.c:static inline void *kzalloc(unsigned size, gfp_t flags)
marco:~/git/linux/tools/virtio$
It's probably meant to be used by someone who wishes to test some virtio kernel code in userspace.
In any case, you could try reporting the bug. The get_mantainer.pl
script suggests:
$ perl scripts/get_maintainer.pl -f tools/virtio/linux/kernel.h
Bad divisor in main::vcs_assign: 0
"Michael S. Tsirkin" <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS)
Jason Wang <[email protected]> (maintainer:VIRTIO CORE AND NET DRIVERS)
[email protected] (open list:VIRTIO CORE AND NET DRIVERS)
[email protected] (open list)