All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: Dima Stepanov <dimastep@yandex-team.ru>
Cc: QEMU <qemu-devel@nongnu.org>, wrfsh@yandex-team.ru
Subject: Re: [Qemu-devel] [PATCH v2 1/2] memfd: fix possible usage of the uninitialized file descriptor
Date: Wed, 13 Jun 2018 12:00:47 +0200	[thread overview]
Message-ID: <CAJ+F1CKLhB16g-LX3KVYtHwAjz7SXcBcurLEK2HFq0RcrrY4Bg@mail.gmail.com> (raw)
In-Reply-To: <1528877995-5043-2-git-send-email-dimastep@yandex-team.ru>

On Wed, Jun 13, 2018 at 10:19 AM, Dima Stepanov <dimastep@yandex-team.ru> 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>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

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



-- 
Marc-André Lureau

  reply	other threads:[~2018-06-13 10:00 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 [this message]
2018-08-31 17:16   ` Thomas Huth
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=CAJ+F1CKLhB16g-LX3KVYtHwAjz7SXcBcurLEK2HFq0RcrrY4Bg@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=dimastep@yandex-team.ru \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.