qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dunrong Huang <riegamaths@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-trivial <qemu-trivial@nongnu.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] block: Don't forget to delete temporary file
Date: Thu, 6 Sep 2012 11:47:31 +0800	[thread overview]
Message-ID: <CAOZVR5bpJc7_gJAxsptEzW08HiuYt7txVTKgj7ALsZ5aPBg-Ww@mail.gmail.com> (raw)
In-Reply-To: <50477D9E.1010408@redhat.com>

2012/9/6 Eric Blake <eblake@redhat.com>:
> On 09/05/2012 10:23 AM, Paolo Bonzini wrote:
>> And finally, the whole get_tmp_filename is unsafe because there is a
>> race window between closing and reopening the file, if the directory is
>> writable and does not have the sticky bit.
>>
>> So the patch is an improvement, but there is still something unpleasing
>> in this code...
>
> I absolutely agree that there is a nasty race here.  If you aren't going
> to use the fd, then mktemp() is sufficient (and just as racy, but then
> you are at least honest that you don't care about the race); in all
Yes, using mktemp() in get_tmp_filename() is ok because we dont
care  about race, but for old gcc version, e.g. for version 4.4, we will get
a annoying unsecure warning "warning: the use of `mktemp' is
dangerous, better use `mkstemp'",
which breaks build.

> other situations, if you want a temporary file name but want to avoid a
> race, then it feels like you should be returning the fd from mkstemp()
> still open (or at a bare minimum, auditing ALL callers to make sure they
> only use the temporary name with O_CREAT|O_EXCL, and that they retry in
> a loop in case they lose the race, at which point they are reinventing
> the loop already done on their behalf by mkstemp()...).
>
> --
> Eric Blake   eblake@redhat.com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>



-- 
Best Regards,

Dunrong Huang

  reply	other threads:[~2012-09-06  3:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05 13:26 [Qemu-devel] [PATCH] block: Don't forget to delete temporary file riegamaths
2012-09-05 15:40 ` Paolo Bonzini
2012-09-05 15:51   ` Dunrong Huang
2012-09-05 16:02   ` Markus Armbruster
2012-09-05 16:23     ` Paolo Bonzini
2012-09-05 16:28       ` Eric Blake
2012-09-06  3:47         ` Dunrong Huang [this message]
2012-09-11 10:23 ` Kevin Wolf
2012-09-14  7:45   ` Stefan Hajnoczi

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=CAOZVR5bpJc7_gJAxsptEzW08HiuYt7txVTKgj7ALsZ5aPBg-Ww@mail.gmail.com \
    --to=riegamaths@gmail.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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).