qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Dima Stepanov <dimastep@yandex-team.ru>, qemu-devel@nongnu.org
Cc: wrfsh@yandex-team.ru, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] memfd: fix possible usage of the uninitialized file descriptor
Date: Fri, 31 Aug 2018 19:16:41 +0200	[thread overview]
Message-ID: <482dc9cb-c5d5-f5b6-bb9f-9518af5a44f0@redhat.com> (raw)
In-Reply-To: <1528877995-5043-2-git-send-email-dimastep@yandex-team.ru>

On 2018-06-13 10:19, Dima Stepanov wrote:
> 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>
> ---
>  util/memfd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/util/memfd.c b/util/memfd.c
> index d248a53..6287946 100644
> --- a/util/memfd.c
> +++ b/util/memfd.c
> @@ -187,6 +187,7 @@ bool qemu_memfd_alloc_check(void)
>          int fd;

(in case you respin: You could also write "int fd = -1;" in above line)

>          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);
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>

(FWIW: GCC complains with -O3 about this uninitialized variable, too, so
the build breaks with -Werror here - just noticed this today)

  parent reply	other threads:[~2018-08-31 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-13  8:19 [Qemu-devel] [PATCH v2 0/2] misc fixes found by static analyzer Dima Stepanov
2018-06-13  8:19 ` [Qemu-devel] [PATCH v2 1/2] memfd: fix possible usage of the uninitialized file descriptor Dima Stepanov
2018-06-13 10:00   ` Marc-André Lureau
2018-08-31 17:16   ` Thomas Huth [this message]
2018-06-13  8:19 ` [Qemu-devel] [PATCH v2 2/2] memory: fix possible NULL pointer dereference Dima Stepanov
2018-06-19 14:12   ` Dima Stepanov
2018-07-11  8:34     ` Dima Stepanov
2018-07-11 13:47       ` Philippe Mathieu-Daudé
2018-07-11 14:09         ` Peter Maydell
2018-07-11 16:03           ` Dima Stepanov
2018-07-11 16:01         ` Dima Stepanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=482dc9cb-c5d5-f5b6-bb9f-9518af5a44f0@redhat.com \
    --to=thuth@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dimastep@yandex-team.ru \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wrfsh@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).