summaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
authorMickaël Salaün <mic@digikod.net>2015-12-22 22:15:10 +0100
committerRichard Weinberger <richard@nod.at>2016-01-10 21:49:50 +0100
commit3e46b25376321db119bc8507ce8c8841c580e736 (patch)
tree808f88738a6caae1bc28e10238f815471c0eca54 /arch/um
parent571d2f0c341fa15dbbb4fb73c80bd740ef37a9f0 (diff)
downloadop-kernel-dev-3e46b25376321db119bc8507ce8c8841c580e736.zip
op-kernel-dev-3e46b25376321db119bc8507ce8c8841c580e736.tar.gz
um: Use race-free temporary file creation
Open the memory mapped file with the O_TMPFILE flag when available. Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Acked-by: Tristan Schmelcher <tschmelcher@google.com> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'arch/um')
-rw-r--r--arch/um/os-Linux/mem.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index 840d573..8b17676 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -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;
OpenPOWER on IntegriCloud