Strict Posix Nonconformance
tedunangst.com
tedunangst.com
(and of course though there is a slight race you can unlink the file you get through mkstemp while keeping it open, that seems to be the strategy used by python's tempfile.TemporaryFile)
There is still a possibility that an attacker opens the file before you unlink it and starts writing to it, which O_TMPFILE gets rid of as it never has a name so can never be opened.
1. Create temporary file in the same directory as the target path.
2. Write and fsync the temporary file
3. Rename the temporary file to the target filename
Oh, and on Linux you can open even deleted files by using /proc/<N>/fd/<M>. It may look like a symlink, but it's not.
There needs to be a single dictator with a single standard. The problem so far is that the dictator and standard need to be hit with the clue stick man times before rather than pushing corporate features and agendas. POSIX, HTML5, Java are all design-by-committee crapfests.
Golang is about right on this. Once core standard and reference implementation which is opinionated and built by people who know their shit.
Am I wrong about this?
And it's not like they wanted a descriptive standard, it's that they knew a prescriptive one would not fly and would just be completely ignored due to the conflicting interests of the half-dozen actors.
A standard everybody ignores is utterly pointless.
It's a type-casted ugly hackfest that serves only to demonstrate the mis-design of the language itself.
~ » uname
Darwin
~ » man shm_open
SHM_OPEN(2) BSD System Calls ManualBased on the description in this post, it seems to me that shm_open() has been a successful addition to the standard. It's basically a semantic annotation: "I intend to use this file descriptor to share memory between processes". The OpenBSD people looked at projects that use this API and discovered that they're overwhelmingly using it to share memory between processes owned by one user (e.g. WebKit), so they solidified that practice into a hard limit as part of their implementation.
Isn't this perfectly in the spirit of why we have all these Unix variants in the first place? Some of them will be at the bleeding edge of implementing new APIs, whereas others like OpenBSD take the cautious and security-minded approach. Thanks to the work of the OpenBSD crew and the (granted, apparently largely implicit) semantics of shm_open(), WebKit is now a bit safer to use in a multi-user scenario on OpenBSD than elsewhere. Maybe others will adopt this interpretation of shm_open() and everyone wins.
Linux has bizarre named Unix domain sockets of two flavours one with names in the filesystem and one with names in another namespace...
It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments.
It is unspecified whether the name and shared memory object state remain valid after a system reboot.
That gives the implementation wider latitude in how it implements the function, for example shm_open() objects may be entirely in-memory.
http://sources.debian.net/src/eglibc/2.17-3/sysdeps/posix/sh...
http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix...
http://pubs.opengroup.org/onlinepubs/9699919799/functions/op...
[1] http://git.musl-libc.org/cgit/musl/tree/src/mman/shm_open.c
At the same time, in another sphere, POSIX was shaping up as factor in the emerging Open Systems wars. It drove compatibility between big vendors like IBM and HP and Sun (over other idiosyncratic offerings, like Apollo).
Perhaps POSIX as a user response to corporate power had value, but there was also collateral damage. As I understand the story, Canadian colleges standardized on POSIX, and so a great little Canadian OS (QNX) was left out in the cold. They had to become like others to survive.
Conformity served to reduce innovation and developer choice.
Now fast forward to 2013, and leaving aside shared memory details, what is POSIX driving today? Don't forget that ultimately a non-POSIX OS killed them all. And don't forget that users have their own means of bubbling up new features and architectures in the Open Source projects. Their control is far beyond what users got out of POSIX in the Open Systems age.
[note: if your reply is going to be some variant of "all programmers are shit"-- not interested, heard it before.]
It sounds like the OpenBSD implementation would throw an error if the file was owned by someone else when you tried to shm_open() it, which mitigates this race attack. mkstemp mitigates this attack by atomically determining the name and opening the file without the opportunity for a nefarious process to touch the file system in between.