aboutsummaryrefslogtreecommitdiff
path: root/hw/vfio
diff options
context:
space:
mode:
authorCédric Le Goater <clg@redhat.com>2023-12-21 09:09:57 +0100
committerCédric Le Goater <clg@redhat.com>2024-01-05 21:25:20 +0100
commit6ba254801f6bc7f3ef68a6414f1b107237c7eb26 (patch)
treeab20ad2be22c0471210e1de42b65c852eba5b9b2 /hw/vfio
parent9353b6da430f90e47f352dbf6dc31120c8914da6 (diff)
downloadqemu-6ba254801f6bc7f3ef68a6414f1b107237c7eb26.zip
qemu-6ba254801f6bc7f3ef68a6414f1b107237c7eb26.tar.gz
qemu-6ba254801f6bc7f3ef68a6414f1b107237c7eb26.tar.bz2
vfio/iommufd: Remove the use of stat() to check file existence
Using stat() before opening a file or a directory can lead to a time-of-check to time-of-use (TOCTOU) filesystem race, which is reported by coverity as a Security best practices violations. The sequence could be replaced by open and fdopendir but it doesn't add much in this case. Simply use opendir to avoid the race. Fixes: CID 1531551 Signed-off-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Zhenzhong Duan <Zhenzhong.duan@intel.com>
Diffstat (limited to 'hw/vfio')
-rw-r--r--hw/vfio/iommufd.c6
1 files changed, 0 insertions, 6 deletions
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index d4c586e..9bfddc1 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -121,17 +121,11 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
DIR *dir = NULL;
struct dirent *dent;
gchar *contents;
- struct stat st;
gsize length;
int major, minor;
dev_t vfio_devt;
path = g_strdup_printf("%s/vfio-dev", sysfs_path);
- if (stat(path, &st) < 0) {
- error_setg_errno(errp, errno, "no such host device");
- goto out_free_path;
- }
-
dir = opendir(path);
if (!dir) {
error_setg_errno(errp, errno, "couldn't open directory %s", path);