vfio/iommufd: Remove the use of stat() to check file existence
commit6ba254801f6bc7f3ef68a6414f1b107237c7eb26
authorCédric Le Goater <clg@redhat.com>
Thu, 21 Dec 2023 08:09:57 +0000 (21 09:09 +0100)
committerCédric Le Goater <clg@redhat.com>
Fri, 5 Jan 2024 20:25:20 +0000 (5 21:25 +0100)
treeab20ad2be22c0471210e1de42b65c852eba5b9b2
parent9353b6da430f90e47f352dbf6dc31120c8914da6
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>
hw/vfio/iommufd.c