Skip to contentSkip to conversation

um: Protect memory mapped file

PATCH Applied Mickaël Salaün 2 participants 4 messages Dec 22, 2015 – Jan 10, 2016 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

v5 cover um: Protect memory mapped file

This series protect the memory mapped file. This apply on v4.4-rc6.

Changes since v4:
* fix spelling [1/2]

Changes since v3:
* add Tristan Schmelcher's ack

Changes since v2; addressed Tristan Schmelcher's comment:
* remove the whole fchmod call [1/2]

Changes since v1; addressed Richard Weinberger's comments:
* add attacker model to the patch description [1/2]
* remove errno reset [2/2]

Regards,
Mickaël

Mickaël Salaün (2):
um: Do not set unsecure permission for temporary file
um: Use race-free temporary file creation

 arch/um/os-Linux/mem.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
Signature · 7 lines
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#1 lore raw

PATCH v5 1/2 um: Do not set unsecure permission for temporary file

Remove the insecure 0777 mode for temporary file to prohibit other users to change the executable mapped code.

An attacker could gain access to the mapped file descriptor from the temporary file (before it is unlinked) in a read-only mode but it should not be accessible in write mode to avoid arbitrary code execution.

To not change the hostfs behavior, the temporary file creation permission now depends on the current umask(2) and the implementation of mkstemp(3).

---
 arch/um/os-Linux/mem.c | 6 ------
 1 file changed, 6 deletions(-)
arch/um/os-Linux/mem.c +0 -6
index 897e9ad0c108..840d573f7e38 100644
@@ -142,12 +142,6 @@ static int __init create_tmp_file(unsigned long long len)
 	if (fd < 0)
 		exit(1);
 
-	err = fchmod(fd, 0777);
-	if (err < 0) {
-		perror("fchmod");
-		exit(1);
-	}
-
 	/*
 	 * Seek to len - 1 because writing a character there will
 	 * increase the file size by one byte, to the desired length.
Signature · 7 lines
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#2 lore raw

PATCH v5 2/2 um: Use race-free temporary file creation

In reply to Mickaël Salaün

Open the memory mapped file with the O_TMPFILE flag when available.

---
 arch/um/os-Linux/mem.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/um/os-Linux/mem.c +11 -0
index 840d573f7e38..8b1767668515 100644
@@ -106,6 +106,17 @@ static int __init make_tempfile(const char *template)
 		}
 	}
 
+#ifdef O_TMPFILE
+	fd = open(tempdir, O_CLOEXEC | O_RDWR | O_EXCL | O_TMPFILE, 0700);
+	/*
+	 * If the running system does not support O_TMPFILE flag then retry
+	 * without it.
+	 */
+	if (fd != -1 || (errno != EINVAL && errno != EISDIR &&
+			errno != EOPNOTSUPP))
+		return fd;
+#endif
+
 	tempname = malloc(strlen(tempdir) + strlen(template) + 1);
 	if (tempname == NULL)
 		return -1;
Signature · 7 lines
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
maintainer Applied
#3 lore raw
In reply to Mickaël Salaün

Am 22.12.2015 um 22:15 schrieb Mickaël Salaün:

Quoted 15 lines

This series protect the memory mapped file. This apply on v4.4-rc6.

Changes since v4:
* fix spelling [1/2]

Changes since v3:
* add Tristan Schmelcher's ack

Changes since v2; addressed Tristan Schmelcher's comment:
* remove the whole fchmod call [1/2]

Changes since v1; addressed Richard Weinberger's comments:
* add attacker model to the patch description [1/2]
* remove errno reset [2/2]

Quoted 6 lines

Regards,
Mickaël

Mickaël Salaün (2):
um: Do not set unsecure permission for temporary file
um: Use race-free temporary file creation

Applied!

Thanks,
//richard