extattr(2)

"Dr Slivnik Tomaž MA (Cantab) MMath (Cantab) PhD (Cantab) FTICA" slivnik at tomaz.name
Mon Aug 26 18:00:06 UTC 2013


I posted this on FreeBSD forums (http://forums.freebsd.org/showthread.php?t=41552) and was advised by the moderator that this mailing list may be the right forum.
-------------------------------------------------

There seems to me to be a race condition in the design of the extattr(2) interface. I can't imagine I am the first person to notice this, but I have not been able to find any discussion of it, so I mention it.

To read an attribute, I have to first call len = extattr_get_file (path, attrnamespace, attrname, NULL, 0) to obtain its length, then call extattr_get_file (path, attrnamespace, attrname, buf, len) to read it. If the attribute changes between the two calls to a longer value, I will read data which is in an inconsistent state, and not be aware of it.

One way to work around it would be to always call extattr_get_file (path, attrnamespace, attrname, buf, len+1) and repeat if length-extension is detected, but it seems like a clunky way of doing it.

The issue could easily be resolved in one of many ways, by some locking or snapshotting mechanism, e.g. by adding a call like this to the interface:

Code:
int extattr_snapshot_and_getlen_file (const char *path, int attrnamespace, const char *attrname);
A subsequent read of the attribute would release the snapshot. Existing code would not be affected.


More information about the freebsd-fs mailing list