]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix oversights from 4170ae4e
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Mon, 31 Oct 2022 17:01:04 +0000 (13:01 -0400)
committerGitHub <noreply@github.com>
Mon, 31 Oct 2022 17:01:04 +0000 (10:01 -0700)
4170ae4ea600fea6ac9daa8b145960c9de3915fc was intended to tackle TOCTOU
race conditions reported by CodeQL, but as an oversight, a file
descriptor was not closed and some comments were not updated.
Interestingly, CodeQL did not complain about the file descriptor leak,
so there is room for improvement in how we configure it to try to detect
this issue so that we get early warning about this.

In addition, an optimization opportunity was missed by mistake in
lib/libshare/os/linux/smb.c, which prevented us from truly closing the
TOCTOU race. This was also caught by Coverity.

Reported-by: Coverity (CID 1524424)
Reported-by: Coverity (CID 1526804)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14109

lib/libshare/os/linux/smb.c
tests/zfs-tests/tests/functional/tmpfile/tmpfile_stat_mode.c

index 8eb1894de5316ca64f76cfb158315ecc1ed4869e..0679e82104e29169ab99113fbd52beb1126c8de7 100644 (file)
@@ -103,7 +103,7 @@ smb_retrieve_shares(void)
                        goto out;
                }
 
-               if (stat(file_path, &eStat) == -1) {
+               if (fstat(fd, &eStat) == -1) {
                        close(fd);
                        rc = SA_SYSTEM_ERR;
                        goto out;
index 1a934a8b1852ae28a1696c170718483efdced55a..8f936d36de1f9620604da9dc443e3a6ad58d85f8 100644 (file)
 
 /*
  * DESCRIPTION:
- *     Verify stat(2) for O_TMPFILE file considers umask.
+ *     Verify fstat(2) for O_TMPFILE file considers umask.
  *
  * STRATEGY:
  *     1. open(2) with O_TMPFILE.
  *     2. linkat(2).
- *     3. fstat(2)/stat(2) and verify .st_mode value.
+ *     3. fstat(2) and verify .st_mode value.
  */
 
 static void
@@ -94,6 +94,7 @@ test_stat_mode(mode_t mask)
        mode = fst.st_mode & 0777;
        if (mode != masked)
                errx(8, "fstat(2) %o != %o\n", mode, masked);
+       close(fd);
 }
 
 int