Skip to contentSkip to conversation

Redundant syscalls?

DISCUSSION Andi Kleen 1 participant 1 message Feb 15, 2002 1 message not in the archive

lore
Share & tools
lore

Andi Kleen

author
#1 lore raw
In reply to a message not in the archive
Quoted 4 lines · Lorenzo Allegrucci

I was wondering why do we need fsetxattr(2), fgetxattr(2) etc when we already have setxattr(2), getxattr(2) etc working on file names instead of file descriptors.
truncate(2)/ftruncate(2) is another more traditional example.

The f* variant can be race free. For example you want to stat something first to make sure it is what you expect it to be and not a symlink to your /etc/passwd. When you use first stat() and then do random operation on filename with name there is a small window where someone could replace the name with something else. This could be security relevant. fd = open(name, ...); fstat(fd, ..); check fsomething(fd, ...); close(fd); guarantees that you're always working on the same object without any race windows.

-Andi