How should I protect against hard link attacks?
Posted
by Thomas
on Stack Overflow
See other posts from Stack Overflow
or by Thomas
Published on 2010-03-31T06:01:17Z
Indexed on
2010/03/31
6:03 UTC
Read the original article
Hit count: 297
- I want to append data to a file in /tmp.
- If the file doesn't exist I want to create it
- I don't care if someone else owns the file. The data is not secret.
- I do not want someone to be able to race-condition this into writing somewhere else, or to another file.
What is the best way to do this?
Here's my thought:
fd = open("/tmp/some-benchmark-data.txt", O_APPEND | O_CREAT | O_NOFOLLOW | O_WRONLY, 0644);
fstat(fd, &st);
if (st.st_nlink != 1) {
HARD LINK ATTACK!
}
What's the right way? Besides not using a world-writable directory.
© Stack Overflow or respective owner