Received: from eggs.gnu.org ([2001:4830:134:3::10]:59161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzKbx-00012o-Vn for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:58:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzKbt-000192-TI for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:58:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzKbt-00018a-Jt for qemu-devel@nongnu.org; Mon, 01 Jun 2015 03:58:13 -0400 From: Markus Armbruster References: <1433142369-14266-1-git-send-email-mrezanin@redhat.com> Date: Mon, 01 Jun 2015 09:58:10 +0200 In-Reply-To: <1433142369-14266-1-git-send-email-mrezanin@redhat.com> (mrezanin@redhat.com's message of "Mon, 1 Jun 2015 09:06:09 +0200") Message-ID: <87iob7lv1p.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] net: fix insecure temporary file creation in SLiRP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mrezanin@redhat.com Cc: Michael Tokarev , pmatouse@redhat.com, qemu-devel@nongnu.org, P J P mrezanin@redhat.com writes: > 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 > --- > [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)); We tend to eschew strncpy() and use our (slightly less bad) pstrcpy(). Recommend to use it here, too. > snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, > "smb.conf"); > > f = fopen(smb_conf, "w"); Michael (cc'ed) already posted "[PATCH] slirp: use less predictable directory name in /tmp for smb config (CVE-2015-4037)"[*]. His patch clobbers s->smb_dir[] when mkdtemp() fails (missed that in my review), yours doesn't. Suggest you guys figure out together which solution you want. Preferably with strncpy() replaced by pstrcpy(): Reviewed-by: Markus Armbruster [*] http://lists.nongnu.org/archive/html/qemu-devel/2015-05/msg05767.html