From cf305108a7f548c4d9162e630207ed53b72445d0 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Tue, 12 Jun 2018 22:26:31 -0500 Subject: [PATCH] mkfs: properly fix TOCTOU open/stat race in config file handling After open of the configfile, simply fstat() that fd to ensure that we are checking the file we just opened, not something that got renamed in between. Signed-off-by: Eric Sandeen Reviewed-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- mkfs/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkfs/config.c b/mkfs/config.c index bfd14c9f5..fcc7035c7 100644 --- a/mkfs/config.c +++ b/mkfs/config.c @@ -550,7 +550,7 @@ open_cli_config( if (fd < 0) goto out; - ret = fstatat(dirfd, cli_config_file, &st, AT_SYMLINK_NOFOLLOW); + ret = fstat(fd, &st); if (ret != 0) goto err_out_close; @@ -563,7 +563,7 @@ open_cli_config( memcpy(*fpath, cli_config_file, strlen(cli_config_file)); - ret = fstatat(AT_FDCWD, cli_config_file, &st, AT_SYMLINK_NOFOLLOW); + ret = fstat(fd, &st); if (ret != 0) goto err_out_close; @@ -628,7 +628,7 @@ open_config_file( goto err_out_close; } - ret = fstatat(dirfd, "default", &st, AT_SYMLINK_NOFOLLOW); + ret = fstat(fd, &st); if (ret != 0) goto err_out_close; -- 2.47.2