On Fri, Jul 16, 2021 at 03:23:41PM -0500, Eric Blake wrote:
On Tue, Jul 13, 2021 at 11:26:05PM +0200, Martin Kletzander wrote:
> diff --git a/fuzzing/libnbd-fuzz-wrapper.c b/fuzzing/libnbd-fuzz-wrapper.c
> index 99a6d803258f..3d127e673e9e 100644
> --- a/fuzzing/libnbd-fuzz-wrapper.c
> +++ b/fuzzing/libnbd-fuzz-wrapper.c
> @@ -41,6 +41,34 @@
> static void client (int s);
> static void server (int fd, int s);
>
> +static int
> +get_socketpair (int domain, int type, int protocol, int *fds)
> +{
> + int ret;
> +
> +#ifdef __APPLE__
> + size_t i;
> +#else
> + type |= SOCK_CLOEXEC;
> +#endif
> +
> + ret = socketpair (domain, type, protocol, fds);
> +
> +#ifdef __APPLE__
> + if (ret == 0) {
> + for (i = 0; i < 2; i++) {
> + if (fcntl (fds[i], F_SETFD, FD_CLOEXEC) == -1) {
> + close(fds[0]);
> + close(fds[1]);
> + return -1;
> + }
> + }
> + }
Is the fuzzer multithreaded? Or can we just blindly do the workaround
ourselves and not worry about trying to use SOCK_CLOEXEC here? Also, it feels like some
duplication; can we not reuse nbd_internal_socketpair from the fuzzer?
AFL-type fuzzers which all use libnbd-fuzz-wrapper.c are not
multithreaded. They will launch a new process for each test case. I
don't think they could easily be multithreaded: part of the goal is to
try to make the test program crash, and they also require
instrumenting the test binary.
As an aside our test case / wrapper also creates a subprocess since it
creates a phony NBD server (the child), connects the two processes by
a socketpair, and runs libnbd in the parent. (Now that I look again
at the code this might be changed to use two threads instead of
processes, not that it would make much difference on Linux.)
Since the test case never calls exec it doesn't seem to me that we
need to set SOCK_CLOEXEC at all, it's just a code cleanliness thing.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/