From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Virtio-fs] [PATCH v2 1/2] virtiofsd: Save error code early at the failure callsite
Date: Mon, 8 Feb 2021 17:05:05 +0000 [thread overview]
Message-ID: <20210208170505.GD3033@work-vm> (raw)
In-Reply-To: <20201112182418.25395-2-vgoyal@redhat.com>
* Vivek Goyal (vgoyal@redhat.com) wrote:
> Change error code handling slightly in lo_setattr(). Right now we seem
> to jump to out_err and assume that "errno" is valid and use that to
> send reply.
>
> But if caller has to do some other operations before jumping to out_err,
> then it does the dance of first saving errno to saverr and the restore
> errno before jumping to out_err. This makes it more confusing.
>
> I am about to make more changes where caller will have to do some
> work after error before jumping to out_err. I found it easier to
> change the convention a bit. That is caller saves error in "saverr"
> before jumping to out_err. And out_err uses "saverr" to send error
> back and does not rely on "errno" having actual error.
>
> Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Yes, that looks OK, so
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
but please can you send a rebased version, Stefan's recent
security fix changes it around the openat.
Dave
> ---
> tools/virtiofsd/passthrough_ll.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index ec1008bceb..6407b1a2e1 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -686,6 +686,7 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
> res = fchmodat(lo->proc_self_fd, procname, attr->st_mode, 0);
> }
> if (res == -1) {
> + saverr = errno;
> goto out_err;
> }
> }
> @@ -695,6 +696,7 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
>
> res = fchownat(ifd, "", uid, gid, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
> if (res == -1) {
> + saverr = errno;
> goto out_err;
> }
> }
> @@ -707,15 +709,15 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
> sprintf(procname, "%i", ifd);
> truncfd = openat(lo->proc_self_fd, procname, O_RDWR);
> if (truncfd < 0) {
> + saverr = errno;
> goto out_err;
> }
> }
>
> res = ftruncate(truncfd, attr->st_size);
> + saverr = res == -1 ? errno : 0;
> if (!fi) {
> - saverr = errno;
> close(truncfd);
> - errno = saverr;
> }
> if (res == -1) {
> goto out_err;
> @@ -748,6 +750,7 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
> res = utimensat(lo->proc_self_fd, procname, tv, 0);
> }
> if (res == -1) {
> + saverr = errno;
> goto out_err;
> }
> }
> @@ -756,7 +759,6 @@ static void lo_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
> return lo_getattr(req, ino, fi);
>
> out_err:
> - saverr = errno;
> lo_inode_put(lo, &inode);
> fuse_reply_err(req, saverr);
> }
> --
> 2.25.4
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2021-02-08 17:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 18:24 [Virtio-fs] [PATCH v2 0/2] viritofsd: Add support for FUSE_HANDLE_KILLPRIV_V2 Vivek Goyal
2020-11-12 18:24 ` Vivek Goyal
2020-11-12 18:24 ` [Virtio-fs] [PATCH v2 1/2] virtiofsd: Save error code early at the failure callsite Vivek Goyal
2020-11-12 18:24 ` Vivek Goyal
2021-02-08 17:05 ` Dr. David Alan Gilbert [this message]
2020-11-12 18:24 ` [Virtio-fs] [PATCH v2 2/2] viriofsd: Add support for FUSE_HANDLE_KILLPRIV_V2 Vivek Goyal
2020-11-12 18:24 ` Vivek Goyal
2020-11-19 15:42 ` [Virtio-fs] " Stefan Hajnoczi
2021-02-08 17:35 ` Dr. David Alan Gilbert
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=20210208170505.GD3033@work-vm \
--to=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vgoyal@redhat.com \
--cc=virtio-fs@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.