Spawn your shell like it's the 90s again
akat1.pl
akat1.pl
What can I do to change it? Is there a reliable, widespread and usable successor to the posix API that offers transactions, or "compare and swap"-type operations? Or are we forever caught in this catch 22 between OS writers and application programmers ?
I wouldn't mind an API that can be (unsafely) simulated on regular posix for compatibility, while being forward compatible with the next gen of file IO on systems that do support it, for example.
"Things UNIX can do atomically" https://rcrowley.org/2010/01/06/things-unix-can-do-atomicall...
O_NOFOLLOW
If pathname is a symbolic link, then the open fails. This is a FreeBSD extension, which was added to Linux in version
2.1.126. Symbolic links in earlier components of the pathname will still be followed. See also O_PATH below.
... The O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW flags are not specified in POSIX.1-2001, but are specified in POSIX.1-2008.https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
Obtain a "session ID" through stat and always use that to access the file:
id := stat("/a")
read(id)
write(id, ..) // doesn't protect race access to a file,
// but at least you're not using the
// pathname twice, which already solves a
// lot of problems
Use transactions: transid := ftransopen()
f := stat("/a")
read("/a")
write("/a", ..)
ftransend(transid) // fails if clashes with other fs changes
Have "last modification ID" counters that change for every modification to a file, and allow CAS-style operations: mod := stat_mod("/a")
open_mod("/a", mod)
read_mod("/a", mod)
mod2 := write_mod("/a", ..., mod) // fails if /a modified since mod
mod3 := chown_mod("/a", ..., mod2) // fails if modified since mod2
etc.All with their own pros and cons, of course, but definitely possible. I'm just curious if there's a specific implementation that's gaining momentum.
why did you use Go syntax?
EDIT: corrected year
Just make sure you fstat() the file descriptor and not stat() the file to avoid a second race condition where a malicious actor undoes their attack immediately after you open() the file to hide the evidence.
Although a quick lookup tells me that it appeared in 4.3BSD-Tahoe (June 1988) and SysVR4 (October 1988), so one would have expected all reasonable distributions to have gotten with the program by now.
Still, that syscall is 28 years old now. It's kind of embarrassing that nobody has gone though and checked for ancient and obvious privilege escalation issues like this. Or I guess they have, but on different OSes. This is one big downside to fragmentation, getting fixes distributed to all of the fragments.
Spoiler alert: it would be.
I was attempting to parody the line that you see around here every time a vulernable C program is shown, that rust is magic pixie dust that removes all security issues. (This is exactly the type of bug that memory safe languages are still vulnerable to.)
(One could argue setuid is the real problem though.)
Had AT&T charged UNIX at the same prices as the other OSes, instead of giving it for free to universities and I hardly believe C would matter.
Most of the features people associate with C are compiler specific language extensions that any compiler writer can bother to add to his favourite language and not part of ANSI C.
Inline Assembly, CPU intrisics, SIMD, calling conventions, out of order execution, hardware transaction memory, cache line control, GPU execution, attaching functions to interrupt handlers and so on.
Also the pile of UB patterns that C compilers have accumulated throughout the years, and the differences between compilers, makes it actually easier to reason about code at the Assembly level than looking at C code.
The only thing has going for it, us that thanks to the economics of free, we now have UNIX flavours everywhere.
So we can only get rid of C when UNIX is not an option, and that is almost impossible.
Only now almost 30 years later has C++ surpassed C in many use cases, but it still carries C with it.
C could have been made so much safer with a few tiny changes, like having optional bounds checking and not decaying arrays into pointers.
...No, not especially. It may not expose CPU-specific functionality in the spec, which is why it is somewhat portable, but it still is effectively good at the same things asm is good at. That's why C is sometimes dubbed "portable assembly"
>Also the pile of UB patterns that C compilers have accumulated throughout the years, and the differences between compilers, makes it actually easier to reason about code at the Assembly level than looking at C code.
Well, yeah. Asm is rigorously defined. It's perhaps the only language that has absolutely zero UB in practice (many languages CLAIM to have no UB, but if you're on multiple architectures, it's almost unavoidable, although few have as much as C): because it's totally unportable, it doesn't have to lean on UB the way C does for optimization.
>Only now almost 30 years later has C++ surpassed C in many use cases, but it still carries C with it.
Yeah, but C++ has... other problems.
>C could have been made so much safer with a few tiny changes, like having optional bounds checking and not decaying arrays into pointers.
Now that's something I wish happened.
If you want good code, you need to think, in every language.
And I would go further and say: the people who prefer to leave details to others are exactly the people who will write filesystem race conditions like this bug and not understand what they have done.
But this is a data race: the mail program performs a check on some data (in the filesystem) to establish some precondition, and then a concurrent thread of execution (another process) mutates that data before the mail program acts on its (now invalidated) belief.
LLVM wouldn't call it a data race, because to LLVM all system calls are essentially opaque. But if the filesystem only existed within your process, and were written in idiomatic Rust style, using structs, borrowing, mutability, and lifetimes, then the analogous bug (two threads racing and mutating the filesystem at once) would be prevented. The real villain here is shared mutable state; if UNIX had been written by skilled Rust progammers, it would with any luck have some abstraction that provides more isolation and less potential for interference than the filesystem.
I think this is kind of absurd and my guess is you haven't worked on a filesystem driver. At a certain point there is value in admitting that race conditions are a part of the universe and developing strategies to deal with them, rather than waste a bunch of overhead trying to isolate a program from the real world or from itself. The semantics you seem to want would be really crazy for a filesystem.
> on some data (in the filesystem)
Traditionally, "data race" only refers to memory, not other forms of resources. So I agree with you that this is like a data race, but would dispute that it's actually a data race.