[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/19] virtiofsd: Fix xattr operations overwriting errno
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PULL 11/19] virtiofsd: Fix xattr operations overwriting errno |
Date: |
Mon, 5 Jul 2021 11:02:27 +0100 |
From: Vivek Goyal <vgoyal@redhat.com>
getxattr/setxattr/removexattr/listxattr operations handle regualar
and non-regular files differently. For the case of non-regular files
we do fchdir(/proc/self/fd) and the xattr operation and then revert
back to original working directory. After this we are saving errno
and that's buggy because fchdir() will overwrite the errno.
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = getxattr(procname, name, value, size);
FCHDIR_NOFAIL(lo->root.fd);
if (ret == -1)
saverr = errno
In above example, if getxattr() failed, we will still return 0 to caller
as errno must have been written by FCHDIR_NOFAIL(lo->root.fd) call.
Fix all such instances and capture "errno" early and save in "saverr"
variable.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Message-Id: <20210622150852.1507204-3-vgoyal@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
tools/virtiofsd/passthrough_ll.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 9858e961d9..ccbda98c5a 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2791,15 +2791,17 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino,
const char *in_name,
goto out_err;
}
ret = fgetxattr(fd, name, value, size);
+ saverr = ret == -1 ? errno : 0;
} else {
/* fchdir should not fail here */
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = getxattr(procname, name, value, size);
+ saverr = ret == -1 ? errno : 0;
FCHDIR_NOFAIL(lo->root.fd);
}
if (ret == -1) {
- goto out_err;
+ goto out;
}
if (size) {
saverr = 0;
@@ -2864,15 +2866,17 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t
ino, size_t size)
goto out_err;
}
ret = flistxattr(fd, value, size);
+ saverr = ret == -1 ? errno : 0;
} else {
/* fchdir should not fail here */
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = listxattr(procname, value, size);
+ saverr = ret == -1 ? errno : 0;
FCHDIR_NOFAIL(lo->root.fd);
}
if (ret == -1) {
- goto out_err;
+ goto out;
}
if (size) {
saverr = 0;
@@ -2998,15 +3002,15 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino,
const char *in_name,
goto out;
}
ret = fsetxattr(fd, name, value, size, flags);
+ saverr = ret == -1 ? errno : 0;
} else {
/* fchdir should not fail here */
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = setxattr(procname, name, value, size, flags);
+ saverr = ret == -1 ? errno : 0;
FCHDIR_NOFAIL(lo->root.fd);
}
- saverr = ret == -1 ? errno : 0;
-
out:
if (fd >= 0) {
close(fd);
@@ -3064,15 +3068,15 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_t
ino, const char *in_name)
goto out;
}
ret = fremovexattr(fd, name);
+ saverr = ret == -1 ? errno : 0;
} else {
/* fchdir should not fail here */
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = removexattr(procname, name);
+ saverr = ret == -1 ? errno : 0;
FCHDIR_NOFAIL(lo->root.fd);
}
- saverr = ret == -1 ? errno : 0;
-
out:
if (fd >= 0) {
close(fd);
--
2.31.1
- [PULL 01/19] tests: migration-test: Add dirty ring test, (continued)
- [PULL 01/19] tests: migration-test: Add dirty ring test, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 02/19] migration: fix the memory overwriting risk in add_to_iovec, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 03/19] migration: Move yank outside qemu_start_incoming_migration(), Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 04/19] migration: Allow reset of postcopy_recover_triggered when failed, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 06/19] migration: failover: continue to wait card unplug on error, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 05/19] migration: move wait-unplug loop to its own function, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 07/19] virtiofsd: use GDateTime for formatting timestamp for debug messages, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 08/19] docs: describe the security considerations with virtiofsd xattr mapping, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 09/19] virtiofsd: Don't allow file creation with FUSE_OPEN, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 10/19] virtiofsd: Fix fuse setxattr() API change issue, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 11/19] virtiofsd: Fix xattr operations overwriting errno,
Dr. David Alan Gilbert (git) <=
- [PULL 12/19] virtiofsd: Add support for extended setxattr, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 13/19] virtiofsd: Add umask to seccom allow list, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 14/19] virtiofsd: Add capability to change/restore umask, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 15/19] virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 16/19] virtiofsd: Add an option to enable/disable posix acls, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 17/19] tests/migration: parse the thread-id key of CpuInfoFast, Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 18/19] tests/migration: fix "downtime_limit" type when "migrate-set-parameters", Dr. David Alan Gilbert (git), 2021/07/05
- [PULL 19/19] migration/rdma: Use error_report to suppress errno message, Dr. David Alan Gilbert (git), 2021/07/05
- Re: [PULL v2 00/19] migration queue, Peter Maydell, 2021/07/05