All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 5/7] mkfs: properly fix TOCTOU open/stat race in config file handling
Date: Tue, 12 Jun 2018 14:31:21 -0500	[thread overview]
Message-ID: <1528831883-21879-6-git-send-email-sandeen@sandeen.net> (raw)
In-Reply-To: <1528831883-21879-1-git-send-email-sandeen@sandeen.net>

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 <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---
 mkfs/config.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mkfs/config.c b/mkfs/config.c
index f27e480..940a055 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;
 
@@ -593,7 +593,7 @@ int
 open_config_file(
 	const char			*cli_config_file,
 	struct mkfs_default_params	*dft,
-	char				**fpath)
+	char				**fpath)	/* path where config is found */
 {
 	int				dirfd, fd = -1, len, ret;
 	struct stat			st;
@@ -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;
 
-- 
1.8.3.1


  parent reply	other threads:[~2018-06-12 19:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12 19:31 [PATCH 0/7] mkfs config support cleanups Eric Sandeen
2018-06-12 19:31 ` [PATCH 1/7] mkfs: document the config file option Eric Sandeen
2018-06-12 22:13   ` Darrick J. Wong
2018-06-12 19:31 ` [PATCH 2/7] mkfs: move mkfs.xfs.8 to an .in file Eric Sandeen
2018-06-12 19:45   ` Eric Sandeen
2018-06-12 22:10     ` Darrick J. Wong
2018-06-12 23:15       ` Eric Sandeen
2018-06-12 19:31 ` [PATCH 3/7] mkfs: parameterize sysconfdir in mkfs.xfs.8 Eric Sandeen
2018-06-12 22:09   ` Darrick J. Wong
2018-06-12 19:31 ` [PATCH 4/7] mkfs: tidy up whitespace in mkfs/config.c Eric Sandeen
2018-06-12 22:09   ` Darrick J. Wong
2018-06-12 19:31 ` Eric Sandeen [this message]
2018-06-12 22:14   ` [PATCH 5/7] mkfs: properly fix TOCTOU open/stat race in config file handling Darrick J. Wong
2018-06-12 19:31 ` [PATCH 6/7] mkfs: consolidate and streamline config opening function Eric Sandeen
2018-06-12 22:21   ` Darrick J. Wong
2018-06-13  0:01     ` Darrick J. Wong
2018-06-12 19:31 ` [PATCH 7/7] mkfs: remove gotos in parse_defaults_file Eric Sandeen
2018-06-12 22:23   ` Darrick J. Wong
2018-06-12 22:27 ` [PATCH 0/7] mkfs config support cleanups Darrick J. Wong
2018-06-12 23:17   ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528831883-21879-6-git-send-email-sandeen@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.