linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* broken userland ABI in configfs binary attributes
@ 2019-08-26  2:48 Al Viro
  2019-08-26 16:29 ` [RFC] " Al Viro
  0 siblings, 1 reply; 22+ messages in thread
From: Al Viro @ 2019-08-26  2:48 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-fsdevel, Octavian Purdila, Pantelis Antoniou

	In commit 03607ace807b (configfs: implement binary attributes)
we have serious trouble:

+* Binary attributes, which are somewhat similar to sysfs binary attributes,
+but with a few slight changes to semantics.  The PAGE_SIZE limitation does not
+apply, but the whole binary item must fit in single kernel vmalloc'ed buffer.
+The write(2) calls from user space are buffered, and the attributes'
+write_bin_attribute method will be invoked on the final close, therefore it is
+imperative for user-space to check the return code of close(2) in order to
+verify that the operation finished successfully.

	This is completely broken.  ->release() is too late to return any errors -
they won't reach the caller of close(2).  ->flush() _is_ called early enough to
pass return value to userland, but it's called every time descriptor is removed
from descriptor table.  IOW, if userland e.g. python code from hell has written
some data to the attribute in question, then called a function that has ended
up calling something in some misbegotten library that spawned a child, had it
run and waited for it to exit, your ->flush() will be called twice.  Which is
fine for something like NFS sending the dirty data to server and checking that
there's nothing left, but not for this kind of "gather data, then commit the
entire thing at once" kind of interfaces.

	AFAICS, there's only one user in the tree right now (acpi/table/*/aml);
no idea what drives the userland side.

	We might be able to paper over that mess by doing what /dev/st does -
checking that file_count(file) == 1 in ->flush() instance and doing commit
there in such case.  It's not entirely reliable, though, and it's definitely
not something I'd like to see spreading.

	Folks, please don't do that kind of userland ABIs; that kind of
implicit commit on the final close is OK only if there's no error to
report (e.g. if all checks can be done at write() time).  Otherwise it's
an invitation for trouble.

	And *ANYTHING* that tries to return an error from ->release() is
very suspicious, no matter what.  Again, in ->release() it's too late
to return an error.

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-08-31 15:58 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26  2:48 broken userland ABI in configfs binary attributes Al Viro
2019-08-26 16:29 ` [RFC] " Al Viro
2019-08-26 18:20   ` Matthew Wilcox
2019-08-26 19:28     ` Al Viro
2019-08-27  8:51       ` Miklos Szeredi
2019-08-27 11:58         ` Al Viro
2019-08-27 12:21           ` Miklos Szeredi
2019-08-27 12:53             ` Al Viro
2019-08-31  8:32       ` Christoph Hellwig
2019-08-31 13:35         ` Al Viro
2019-08-31 14:44           ` Christoph Hellwig
2019-08-31 15:58             ` Al Viro
2019-08-26 18:34   ` "Kai Mäkisara (Kolumbus)"
2019-08-26 19:32     ` Al Viro
2019-08-27 15:01       ` Boaz Harrosh
2019-08-27 17:27         ` Al Viro
2019-08-27 17:59           ` Boaz Harrosh
2019-08-29 22:22           ` Al Viro
2019-08-29 23:32             ` Al Viro
2019-08-30  4:10             ` Dave Chinner
2019-08-30  4:44               ` Al Viro
2019-08-31  8:28                 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).