From: Stefan Hajnoczi <stefanha@gmail.com>
To: "M. Mohan Kumar" <mohan@in.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [V9 PATCH 13/13] virtio-9p: Chroot environment for other functions
Date: Mon, 28 Mar 2011 22:06:42 +0100 [thread overview]
Message-ID: <20110328210642.GA11316@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <1300418881-20972-14-git-send-email-mohan@in.ibm.com>
On Fri, Mar 18, 2011 at 08:58:01AM +0530, M. Mohan Kumar wrote:
> +static int get_dirfd(FsContext *fs_ctx, const char *path)
> +{
> + int fd;
> + char *dpath = qemu_strdup(path);
> + char *last_component;
> +
> + /* path can not contain ".." */
> + last_component = strrchr(path, '/');
> + if (last_component && !strcmp(last_component, "/..")) {
> + error_report("9p path request contains \"..\": %s\n", path);
> + qemu_free(dpath);
> + errno = EFAULT;
> + return -1;
> + }
> + fd = passthrough_request(fs_ctx, NULL, dirname(dpath), 0, NULL, T_OPEN);
> + if (fd < 0) {
> + qemu_free(dpath);
> + errno = -fd;
> + fd = -1;
> + }
> + return fd;
> +}
dpath is leaked in the success case. I suggest writing the function like this:
static int get_dirfd(FsContext *fs_ctx, const char *path)
{
int fd;
char *dpath;
char *last_component;
/* path can not contain ".." */
last_component = strrchr(path, '/');
if (last_component && !strcmp(last_component, "/..")) {
error_report("9p path request contains \"..\": %s\n", path);
errno = EFAULT;
return -1;
}
dpath = qemu_strdup(path);
fd = passthrough_request(fs_ctx, NULL, dirname(dpath), 0, NULL, T_OPEN);
qemu_free(dpath);
if (fd < 0) {
errno = -fd;
fd = -1;
}
return fd;
}
> -static int local_utimensat(FsContext *s, const char *path,
> - const struct timespec *buf)
> +static int local_utimensat(FsContext *fs_ctx, const char *path,
> + const struct timespec *buf)
> {
> - return qemu_utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW);
> + if (fs_ctx->fs_sm == SM_PASSTHROUGH) {
> + int fd, retval;
> + fd = passthrough_request(fs_ctx, NULL, path,
> + O_RDONLY | O_NONBLOCK | O_NOFOLLOW, NULL, T_OPEN);
> + if (fd < 0) {
> + errno = -fd;
> + return -1;
> + }
> + retval = futimens(fd, buf);
> + close(fd);
> + return retval;
errno is clobbered here.
Stefan
next prev parent reply other threads:[~2011-03-28 21:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-18 3:27 [Qemu-devel] [V9 PATCH 00/13] virtio-9p: Use chroot to safely access files in passthrough security model M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 01/13] Implement qemu_read_full M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 02/13] virtio-9p: Enable CONFIG_THREAD if CONFIG_VIRTFS is enabled M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 03/13] virtio-9p: Provide chroot worker side interfaces M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 04/13] virtio-9p: Add qemu side interfaces for chroot environment M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 05/13] virtio-9p: Add support to open a file in " M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 06/13] virtio-9p: Create support " M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 07/13] virtio-9p: Support for creating special files M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 08/13] virtio-9p: Add support for removing file or directory M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 09/13] virtio-9p: Add support to rename M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 10/13] virtio-9p: Move file post creation changes to none security model M. Mohan Kumar
2011-03-18 3:27 ` [Qemu-devel] [V9 PATCH 11/13] virtio-9p: Add support for chmod M. Mohan Kumar
2011-03-18 3:28 ` [Qemu-devel] [V9 PATCH 12/13] virtio-9p: Add support for chown M. Mohan Kumar
2011-03-18 3:28 ` [Qemu-devel] [V9 PATCH 13/13] virtio-9p: Chroot environment for other functions M. Mohan Kumar
2011-03-28 21:06 ` Stefan Hajnoczi [this message]
2011-03-29 5:55 ` [Qemu-devel] " M. Mohan Kumar
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=20110328210642.GA11316@stefanha-thinkpad.localdomain \
--to=stefanha@gmail.com \
--cc=mohan@in.ibm.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).