25e9385
diff -up ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c.CVE-2011-3145 ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c
25e9385
--- ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c.CVE-2011-3145	2011-08-31 12:08:26.479493949 +0200
25e9385
+++ ecryptfs-utils-90/src/utils/mount.ecryptfs_private.c	2011-08-31 12:10:09.014666213 +0200
25e9385
@@ -274,12 +274,14 @@ int update_mtab(char *dev, char *mnt, ch
25e9385
 	int fd;
25e9385
 	FILE *old_mtab, *new_mtab;
25e9385
 	struct mntent *old_ent, new_ent;
25e9385
+	mode_t old_umask;
25e9385
 
25e9385
 	/* Make an attempt to play nice with other mount helpers
25e9385
 	 * by creating an /etc/mtab~ lock file. Of course this
25e9385
 	 * only works if those other helpers actually check for
25e9385
 	 * this.
25e9385
 	 */
25e9385
+	old_umask = umask(033);
25e9385
 	fd = open("/etc/mtab~", O_RDONLY | O_CREAT | O_EXCL, 0644);
25e9385
 	if (fd < 0) {
25e9385
 		perror("open");
25e9385
@@ -332,6 +334,8 @@ int update_mtab(char *dev, char *mnt, ch
25e9385
 
25e9385
 	unlink("/etc/mtab~");
25e9385
 
25e9385
+	umask(old_umask);
25e9385
+
25e9385
 	return 0;
25e9385
 
25e9385
 fail:
25e9385
@@ -341,6 +345,7 @@ fail_late:
25e9385
 fail_early:
25e9385
 	endmntent(old_mtab);
25e9385
 	unlink("/etc/mtab~");
25e9385
+	umask(old_umask);
25e9385
 	return 1;
25e9385
 }
25e9385
 
25e9385
@@ -476,7 +481,7 @@ int zero(FILE *fh) {
25e9385
  *  c) updating /etc/mtab
25e9385
  */
25e9385
 int main(int argc, char *argv[]) {
25e9385
-	int uid, mounting;
25e9385
+	int uid, gid, mounting;
25e9385
 	int force = 0;
25e9385
 	struct passwd *pwd;
25e9385
 	char *alias, *src, *dest, *opt, *opts2;
25e9385
@@ -491,6 +496,7 @@ int main(int argc, char *argv[]) {
25e9385
 	}
25e9385
 	
25e9385
 	uid = getuid();
25e9385
+	gid = getgid();
25e9385
 	/* Non-privileged effective uid is sufficient for all but the code
25e9385
  	 * that mounts, unmounts, and updates /etc/mtab.
25e9385
 	 * Run at a lower privilege until we need it.
25e9385
@@ -618,7 +624,14 @@ int main(int argc, char *argv[]) {
25e9385
 		 * the real uid to be that of the user.
25e9385
 		 * And we need the effective uid to be root in order to mount.
25e9385
 		 */
25e9385
-		setreuid(-1, 0);
25e9385
+		if (setreuid(-1, 0) < 0) {
25e9385
+			perror("setreuid");
25e9385
+			goto fail;
25e9385
+		}
25e9385
+		if (setregid(-1, 0) < 0) {
25e9385
+			perror("setregid");
25e9385
+			goto fail;
25e9385
+		}
25e9385
  		/* Perform mount */
25e9385
 		if (mount(src, ".", FSTYPE, 0, opt) == 0) {
25e9385
 			if (update_mtab(src, dest, opt) != 0) {
25e9385
@@ -630,6 +643,9 @@ int main(int argc, char *argv[]) {
25e9385
 			if (setreuid(uid, uid) < 0) {
25e9385
 				perror("setreuid");
25e9385
 			}
25e9385
+			if (setregid(gid, gid) < 0) {
25e9385
+				perror("setregid");
25e9385
+			}
25e9385
 			goto fail;
25e9385
 		}
25e9385
 	} else {
25e9385
@@ -665,6 +681,7 @@ int main(int argc, char *argv[]) {
25e9385
 		 * Do not use the umount.ecryptfs helper (-i).
25e9385
  		 */
25e9385
 		setresuid(0,0,0);
25e9385
+		setresgid(0,0,0);
25e9385
 
25e9385
 		/* Since we're doing a lazy unmount anyway, just unmount the current
25e9385
 		 * directory. This avoids a lot of complexity in dealing with race