[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 3/8] virtiofsd: Fix xattr operations overwriting errno
From: |
Vivek Goyal |
Subject: |
[PATCH v6 3/8] virtiofsd: Fix xattr operations overwriting errno |
Date: |
Thu, 17 Jun 2021 14:12:08 -0400 |
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>
---
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 49c21fd855..ec91b3c133 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.25.4
- [PATCH v6 0/8] virtiofsd: Add support to enable/disable posix acls, Vivek Goyal, 2021/06/17
- [PATCH v6 3/8] virtiofsd: Fix xattr operations overwriting errno,
Vivek Goyal <=
- [PATCH v6 7/8] virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr, Vivek Goyal, 2021/06/17
- [PATCH v6 4/8] virtiofsd: Add support for extended setxattr, Vivek Goyal, 2021/06/17
- [PATCH v6 2/8] virtiofsd: Fix fuse setxattr() API change issue, Vivek Goyal, 2021/06/17
- [PATCH v6 6/8] virtiofsd: Add capability to change/restore umask, Vivek Goyal, 2021/06/17
- [PATCH v6 8/8] virtiofsd: Add an option to enable/disable posix acls, Vivek Goyal, 2021/06/17
- [PATCH v6 5/8] virtiofsd: Add umask to seccom allow list, Vivek Goyal, 2021/06/17
- [PATCH v6 1/8] linux-headers: Update linux headers to 5.13.0-rc6, Vivek Goyal, 2021/06/17
- Re: [PATCH v6 0/8] virtiofsd: Add support to enable/disable posix acls, no-reply, 2021/06/17