diff options
author | Mike Kelly <mike@pair.com> | 2012-02-17 11:35:15 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2012-03-08 10:34:39 +0100 |
commit | 4dc10686e0d75ee24d002a68eb898ca43070d56a (patch) | |
tree | de9f1c56c95a90b25c862714765179e9fb7e4d3b | |
parent | b3af91b123af607611fed00a3cc801ebc639d9ff (diff) | |
download | sshfs-4dc10686e0d75ee24d002a68eb898ca43070d56a.tar sshfs-4dc10686e0d75ee24d002a68eb898ca43070d56a.tar.gz sshfs-4dc10686e0d75ee24d002a68eb898ca43070d56a.tar.bz2 sshfs-4dc10686e0d75ee24d002a68eb898ca43070d56a.zip |
make sure idmap files aren't writable by others
otherwise, other local users could change the mapping, and gain access
to things they shouldn't
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | sshfs.c | 16 |
2 files changed, 22 insertions, 0 deletions
@@ -1,3 +1,9 @@ +2012-03-08 Miklos Szeredi <miklos@szeredi.hu> + + * Make sure idmap files aren't writable by others otherwise, other + local users could change the mapping, and gain access to things + they shouldn't. Patch by Mike Kelly + 2012-02-08 Chris Wolfe <cwolfe@chromium.org> * Add -o slave. This option routes the sftp communication over stdin @@ -3561,6 +3561,7 @@ static void read_id_map(char *file, uint32_t *(*map_fn)(char *), FILE *fp; char line[LINE_MAX]; unsigned int lineno = 0; + uid_t local_uid = getuid(); fp = fopen(file, "r"); if (fp == NULL) { @@ -3568,6 +3569,21 @@ static void read_id_map(char *file, uint32_t *(*map_fn)(char *), file, strerror(errno)); exit(1); } + struct stat st; + if (fstat(fileno(fp), &st) == -1) { + fprintf(stderr, "failed to stat '%s': %s\n", file, + strerror(errno)); + exit(1); + } + if (st.st_uid != local_uid) { + fprintf(stderr, "'%s' is not owned by uid %lu\n", file, + (unsigned long)local_uid); + exit(1); + } + if (st.st_mode & S_IWGRP || st.st_mode & S_IWOTH) { + fprintf(stderr, "'%s' is writable by other users\n", file); + exit(1); + } while (fgets(line, LINE_MAX, fp) != NULL) { lineno++; |