qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: mrezanin@redhat.com
To: qemu-devel@nongnu.org
Cc: Miroslav Rezanina <mrezanin@redhat.com>,
	pmatouse@redhat.com, P J P <pjp@fedoraproject.org>
Subject: [Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP
Date: Mon,  1 Jun 2015 09:06:09 +0200	[thread overview]
Message-ID: <1433142369-14266-1-git-send-email-mrezanin@redhat.com> (raw)

From: Miroslav Rezanina <mrezanin@redhat.com>

Qemu's user mode networking stack(-net user) is vulnerable to
a predictable temporary file creation flaw. This patch uses
mkdtemp(3) routine to fix it.

Fixes CVE-2015-4037.

Signed-off-by: P J P <pjp@fedoraproject.org>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
[1] http://seclists.org/oss-sec/2015/q2/538
---
 net/slirp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index 0e15cf6..804b095 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -27,6 +27,7 @@
 
 #ifndef _WIN32
 #include <pwd.h>
+#include <stdlib.h>
 #include <sys/wait.h>
 #endif
 #include "net/net.h"
@@ -481,9 +482,9 @@ static void slirp_smb_cleanup(SlirpState *s)
 static int slirp_smb(SlirpState* s, const char *exported_dir,
                      struct in_addr vserver_addr)
 {
-    static int instance;
     char smb_conf[128];
     char smb_cmdline[128];
+    char smb_dir[] = "/tmp/qemu-smb.XXXXXX",  *tmpdir = NULL;
     struct passwd *passwd;
     FILE *f;
 
@@ -505,12 +506,11 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
         return -1;
     }
 
-    snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d",
-             (long)getpid(), instance++);
-    if (mkdir(s->smb_dir, 0700) < 0) {
-        error_report("could not create samba server dir '%s'", s->smb_dir);
+    if (!(tmpdir = mkdtemp(smb_dir))) {
+        error_report("could not create samba server dir '%s'", smb_dir);
         return -1;
     }
+    strncpy(s->smb_dir, tmpdir, sizeof(s->smb_dir));
     snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, "smb.conf");
 
     f = fopen(smb_conf, "w");
-- 
2.4.1

             reply	other threads:[~2015-06-01  7:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01  7:06 mrezanin [this message]
2015-06-01  7:58 ` [Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP Markus Armbruster
2015-06-01  8:38   ` Miroslav Rezanina
2015-06-01  8:47   ` Paolo Bonzini
2015-06-01  8:49     ` Michael Tokarev
2015-06-02  6:51   ` P J P
2015-06-03 11:03     ` Markus Armbruster
2015-06-04  4:29       ` P J P

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=1433142369-14266-1-git-send-email-mrezanin@redhat.com \
    --to=mrezanin@redhat.com \
    --cc=pjp@fedoraproject.org \
    --cc=pmatouse@redhat.com \
    --cc=qemu-devel@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).