From patchwork Mon Jun 1 07:06:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miroslav Rezanina X-Patchwork-Id: 478783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 904DF14016A for ; Mon, 1 Jun 2015 17:07:00 +1000 (AEST) Received: from localhost ([::1]:44614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzJoH-0002Lv-Hj for incoming@patchwork.ozlabs.org; Mon, 01 Jun 2015 03:06:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzJnp-0001d9-DT for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:06:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzJnl-00056i-I9 for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:06:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzJnl-00055g-Bp for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:06:25 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9CC73376B77; Mon, 1 Jun 2015 07:06:23 +0000 (UTC) Received: from lws-ntb.brq.redhat.com (ovpn-204-16.brq.redhat.com [10.40.204.16]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5176KL8010183; Mon, 1 Jun 2015 03:06:22 -0400 From: mrezanin@redhat.com To: qemu-devel@nongnu.org Date: Mon, 1 Jun 2015 09:06:09 +0200 Message-Id: <1433142369-14266-1-git-send-email-mrezanin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Miroslav Rezanina , pmatouse@redhat.com, P J P Subject: [Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Miroslav Rezanina 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 Signed-off-by: Miroslav Rezanina Reviewed-by: Markus Armbruster --- [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 +#include #include #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");