]> git.proxmox.com Git - mirror_qemu.git/commitdiff
memfd: fix possible usage of the uninitialized file descriptor
authorDima Stepanov <dimastep@yandex-team.ru>
Wed, 13 Jun 2018 08:19:54 +0000 (11:19 +0300)
committerThomas Huth <thuth@redhat.com>
Tue, 25 Sep 2018 15:26:18 +0000 (17:26 +0200)
The qemu_memfd_alloc_check() routine allocates the fd variable on stack.
This variable is initialized inside the qemu_memfd_alloc() function.
There are several cases when *fd will be left unintialized which can
lead to the unexpected close() in the qemu_memfd_free() call.

Set file descriptor to -1 before calling the qemu_memfd_alloc routine.

Signed-off-by: Dima Stepanov <dimastep@yandex-team.ru>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
util/memfd.c

index d248a53c3c0815bee3a5b2e2309ddcff51c10b2a..6287946b61606ef1a5c45e53f8334640d733919f 100644 (file)
@@ -187,6 +187,7 @@ bool qemu_memfd_alloc_check(void)
         int fd;
         void *ptr;
 
+        fd = -1;
         ptr = qemu_memfd_alloc("test", 4096, 0, &fd, NULL);
         memfd_check = ptr ? MEMFD_OK : MEMFD_KO;
         qemu_memfd_free(ptr, 4096, fd);