Received: from eggs.gnu.org ([2001:4830:134:3::10]:42688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOkxf-000383-4D for qemu-devel@nongnu.org; Tue, 02 Sep 2014 06:05:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOkxZ-0008QX-MJ for qemu-devel@nongnu.org; Tue, 02 Sep 2014 06:05:15 -0400 Received: from soto.provo.novell.com ([137.65.250.214]:37842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOkxZ-0008QD-Ew for qemu-devel@nongnu.org; Tue, 02 Sep 2014 06:05:09 -0400 Message-Id: <540606CD020000660005BBBD@soto.provo.novell.com> Date: Tue, 02 Sep 2014 04:05:01 -0600 From: "Chun Yan Liu" References: <1409643643-31589-1-git-send-email-cyliu@suse.com> <1409643643-31589-2-git-send-email-cyliu@suse.com> <20140902085434.GA21282@redhat.com> <5405F9A3020000660005BB22@soto.provo.novell.com> <20140902091655.GB21282@redhat.com> In-Reply-To: <20140902091655.GB21282@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: Re: [Qemu-devel] [PATCH 1/2] add 'umask' option to -chardev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: libvir-list@redhat.com, qemu-devel@nongnu.org >>> On 9/2/2014 at 05:16 PM, in message <20140902091655.GB21282@redhat.com>= , "Daniel P. Berrange" wrote:=20 > On Tue, Sep 02, 2014 at 03:08:51AM -0600, Chun Yan Liu wrote:=20 > > =20 > > =20 > > >>> On 9/2/2014 at 04:54 PM, in message <20140902085434.GA21282@redhat.= com>,=20 > > "Daniel P. Berrange" wrote: =20 > > > On Tue, Sep 02, 2014 at 03:40:42PM +0800, Chunyan Liu wrote: =20 > > > > To use virtio-serial device, unix socket created for chardev with = =20 > > > > default umask(022) has insufficient permissions. =20 > > > > =20 > > > > e.g. start kvm guest with: =20 > > > > -device virtio-serial \ =20 > > > > -chardev socket,path=3D/tmp/foo,server,nowait,id=3Dfoo \ =20 > > > > -device virtserialport,chardev=3Dfoo,name=3Dorg.fedoraproject.port.= 0 =20 > > > > =20 > > > > Check permissions for the socket file that has been created in the = host =20 > > > > to enable communication through virtual serial ports in the guest: = =20 > > > > #ls -l /tmp/somefile.sock =20 > > > > srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock =20 > > > > =20 > > > > Other users in the qemu group (like real user, test engines, etc) = cannot =20 > > > > write to this socket. =20 > > > > =20 > > > > Problem reported here: =20 > > > > https://sourceware.org/bugzilla/show_bug.cgi?id=3D13078#c11 =20 > > > > https://bugzilla.novell.com/show_bug.cgi?id=3D888166 =20 > > > > =20 > > > > This patch tries to add a 'umask' option to 'chardev', so that = user =20 > > > > can have chance to indicate a umask overwritting the default one = (default =20 > =20 > > > > is 022), then create unix sockets with expected permissions. =20 > > > > =20 > > > > Signed-off-by: Chunyan Liu =20 > > > > --- =20 > > > > This is patch for qemu. =20 > > > > =20 > > > > qemu-char.c | 3 +++ =20 > > > > qemu-options.hx | 9 +++++++-- =20 > > > > util/qemu-sockets.c | 12 +++++++++++- =20 > > > > 3 files changed, 21 insertions(+), 3 deletions(-) =20 > > > =20 > > > > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c =20 > > > > index 5d38395..facf2c6 100644 =20 > > > > --- a/util/qemu-sockets.c =20 > > > > +++ b/util/qemu-sockets.c =20 > > > > @@ -680,7 +680,8 @@ int unix_listen_opts(QemuOpts *opts, Error = **errp) =20 > > > > { =20 > > > > struct sockaddr_un un; =20 > > > > const char *path =3D qemu_opt_get(opts, "path"); =20 > > > > - int sock, fd; =20 > > > > + int newmask =3D qemu_opt_get_number(opts, "umask", 0); =20 > > > > + int sock, fd, oldmask; =20 > > > > =20 > > > > sock =3D qemu_socket(PF_UNIX, SOCK_STREAM, 0); =20 > > > > if (sock < 0) { =20 > > > > @@ -708,10 +709,19 @@ int unix_listen_opts(QemuOpts *opts, Error = **errp) =20 > > > > } =20 > > > > =20 > > > > unlink(un.sun_path); =20 > > > > + if (newmask) { =20 > > > > + oldmask =3D umask(newmask); =20 > > > > + } =20 > > > > if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { =20 > > > > + if (newmask) { =20 > > > > + umask(oldmask); =20 > > > > + } =20 > > > > error_set_errno(errp, errno, QERR_SOCKET_BIND_FAILED); = =20 > > > > goto err; =20 > > > > } =20 > > > > + if (newmask) { =20 > > > > + umask(oldmask); =20 > > > > + } =20 > > > =20 > > > Setting umask() is not thread-safe as it affects the entire = process. =20 > While =20 > > > this is OK for chardevs which are cold-plugged at startup, once QEMU = is =20 > > > running it is not OK to alter umask during hotplug of devices. =20 > > > =20 > > > Wouldn't it be simpler for libvirt to simply set the umask to 002 = when it =20 > > > first launches QEMU, avoiding the need for trying todo this per = device. =20 > > =20 > > I think that's OK. Only one thing: I'm not sure if permissions of any = other=20 > > file created in qemu will be changed due to this change, and if that = is=20 > > unexpected or not.=20 > =20 > Whether or not it causes problems today is only half the story. I'm = more=20 > concerned about the long term problems. The use of threads is increasing= =20 > in QEMU over time, so manipulating umask() is a time-bomb waiting to = strike=20 > at some point in the future when people have forgotten that this = proposed=20 > feature exists. IMHO umask() should simply never be used when multiple=20= > threads are running, to avoid this long term risk entirely.=20 I agree. Now suppose when it explicitly sets the mode S_IWGRP while = creating new file, group user writing permission is really expected, I think = setting umask to 002 to the whole qemu process should be OK. > =20 > Regards,=20 > Daniel=20 > -- =20 > |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / =20 > :|=20 > |: http://libvirt.org -o- http://virt-manager.or= g =20 > :|=20 > |: http://autobuild.org -o- http://search.cpan.org/~danberr= / =20 > :|=20 > |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c =20 > :|=20 > =20 > =20 > =20