Commit graph

50 commits

Author SHA1 Message Date
cinap_lenrek ee289c2415 lib9p: remove Srv.srvfd, make postsrv() and threadpostsrv() return the mountable file descriptor, update documentation
Now that we have these new functions,
we can also make them return an error
instead of calling sysfatal() like
postmountsrv().

Remove the confusing Srv.srvfd, as it
is only temporarily used and return
it from postsrv() instead.
2021-05-01 19:58:58 +02:00
cinap_lenrek 57c21ae441 lib9p: remove unneccesary headers 2021-05-01 17:03:03 +02:00
cinap_lenrek f6509078ed lib9p: expose Srv.forker handler and srvforker(), threadsrvforker() and threadsrv() functions
To use srvrease()/srvaquire() we need to have a way to spawn
new processes to handle the service loop. This functionality
was provided by the internal _forker() function which was
eigther rfork or libthread based implementation depending on
if postmountsrv() or threadpostmountsrv() where called.

For servers who want to use srv() directly, _forker would not
be initialized so srvrelease() could not be used.

To untangle this, we get rid of the global _forker handler
and put the handler in the Srv structure. Which will get
initialized (when nil) to eigther srvforker() or threadsrvforker()
depending on if the thread or non-thread entry points where used.

For symmetry, we provde new threadsrv() and threadpostsrv()
functions which handle the default initialization of Srv.forker.

This also allows a user to provide his own forker function,
maybe to conserve stack space.

To avoid dead code, we put each of these function in their
own object file. Note, this also allows a user to define its
own srvforker() symbol.
2021-05-01 16:37:00 +02:00
cinap_lenrek 5e59c57bb1 lib9p: open internal file-descriptor with OCEXEC flag in getremotesys() 2020-12-07 14:54:27 +01:00
cinap_lenrek 4d4b6a19de lib9p: open /mnt/factotum/rpc with OCEXEC flag in auth9p() 2020-12-07 14:51:53 +01:00
cinap_lenrek d570229e82 lib9p: improve reqqueuecreate()
- open /proc/n/ctl with OCEXEC flag
- format pid as ulong
- don't leak the fd
2020-12-07 14:49:12 +01:00
cinap_lenrek 39c3fd117a lib9p: reject reads on closed fids and writes on directories
mischief provided the following test that shows the issue:

ramfs -S crash

aux/9pcon /srv/crash <<EOF
Tversion 8192 9P2000
Tattach 0 -1 $user ''
Tcreate 0 dir 020000000777 0
Tattach 5 -1 $user ''
Twalk 5 6 dir
Tread 6 0 512
EOF

the problem is that lib9p wrongly allowed reads on closed fids,
due to the permission check only considering the lower 2 bits.
a closed fid has fid->omode == -1 and it would pass on read for:

(-1 & 3) == 3 == OEXEC

the following change explicitely checks for for the closed case
and also rejects writes on directories (they are rejected on
open/create, but a broken 9p client could still issue the request).
2020-04-27 19:55:42 +02:00
BurnZeZ 11025d6f4a lib9p: fix re-use of root Qid when using createfile(); remove unused dirqidgen 2020-03-29 17:39:30 +00:00
cinap_lenrek e9e55a21f6 lib9p: implement automatic remove-on-close cleanup in postsharesrv(), remove postfd() and sharefd() functions
with the latest changes to shr(3), we can use ORCLOSE on
the control file to get the mount in the share automatically
removed when the server exits or something goes wrong during
postsharesrv().

do not expose postfd() and sharefd() functions. they where
undocumented and leak the control file descriptors.
2020-03-08 22:00:23 +01:00
cinap_lenrek 5826140ce3 lib9p: restore previous behaviour of fd group sharing
it appears that too many fileservers rely on the fileserver
process sharing the filedescriptors with children of the
caller to postmntsrv() or threadpostmntsrv().

restoring previous behaviour for now.
2020-03-08 05:52:23 +01:00
cinap_lenrek 225c359bea lib9p: get rid of Srv.nopipe and Srv.leavefdsopen hacks
it is unclear how Srv.nopipe flag should work inside
postmountserv(). if a server wants to serve on stdio
descriptors, he can just call srv() after initializing
Srv.infd and Srv.outfd.

The Srv.leavefdsopen hack can be removed now that acme
win has been fixed.
2020-03-07 20:19:14 +01:00
cinap_lenrek 022087cdcd lib9p: fix typo 2020-03-07 15:20:07 +01:00
cinap_lenrek 8f64e44854 lib9p: zero out per connection state in Srv template for listensrv()
in case listensrv() is called with a previously active Srv,
we have to make sure that per connection state is zeroed
out (locks and reference conuts).

also, dont assume anything about the Ref structure. there
might be implementations that have a spinlock in them.
2020-03-07 15:01:29 +01:00
cinap_lenrek dea2905783 lib9p: fix listensrv() filedescriptor leaks 2019-10-04 18:52:53 +02:00
cinap_lenrek 0aac600fb3 lib9p: fix zero msize abort() due to unknown version (thanks kivik)
kivik wrote:

I've found a nasty bug in lib9p handling of Tversion
messages, where an invalid version string in the request
leads to servers abort()ing the spaceship.

To reproduce:
	; ramfs -S ram
	; aux/9pcon /srv/ram
	Tversion ~0 DIE

The issue lies in sversion() where in case an invalid
version string is received we respond right away with
ofcall.version="unknown"; however, we fail to set the
ofcall.msize, which at this point is cleared to 0.  This
causes the convS2M call in respond() to fail and abort being
called.
2019-03-01 01:43:55 +01:00
cinap_lenrek f8478eb4c4 lib9p: allow rewinding in 9pfile directories 2017-04-30 01:49:21 +02:00
cinap_lenrek b728f50a79 lib9p: limit the number of srv processes kept arround 8 2016-10-23 17:16:22 +02:00
cinap_lenrek a0d4c5e208 make error handling in 9p service loops consistent
when we get eof, stop the loop immidiately and do not
rely on the read to eventually return an error.

when convM2S() fails to decode the message, error out
and stop the loop. there is no point in continuing.
2016-07-24 02:21:32 +02:00
BurnZeZ e1f7e472cf lib9p: remove duplicate variable assignment in createfile() 2016-03-19 17:58:35 -04:00
cinap_lenrek 2f99484b9d merge 2015-10-15 13:22:48 +02:00
cinap_lenrek a034e629f7 lib9p: do not override Srv.end in listensrv(), simplify srvclose() and recounting
listensrv() used to override Srv.end() with its own handler
to free the malloc'd Srv structure and close the fd. this
makes it impossible to register your own cleanup handler.
instead, we introduce the private Srv.free() handler that
is used by listensrv to register its cleanup code. Srv.free()
is called once all the srv procs have been exited and all
requests on that srv have been responded to while Srv.end()
is called once all the procs exited the srv loop regardless
of the requests still being in flight.
2015-10-15 13:21:30 +02:00
aiju 27d2955ccf lib9p: add reqqueuefree 2015-10-12 10:41:40 +02:00
cinap_lenrek 4b926f4e69 lib9p: make reqqueueflush() use new threadint(), which will also cover channel operations
using "interrupt" ctl message directly doesnt work when the
process is doing libthread channel operations (threadrendezvous)
as it will just repeat a interrupted rendezvous(). threadint()
handles this for us.
2015-08-10 03:52:40 +02:00
cinap_lenrek b506c6489b lib9p: return "write prohibited" error as documented in 9p(2) when srv->write is nil (thanks silasm) 2015-07-28 01:24:02 +02:00
cinap_lenrek 1473e5d437 lib9p: fix lib9p wstat qid.type/mode checks (fixes lock(1) for ramfs/hjfs) 2015-06-13 12:43:15 +02:00
cinap_lenrek a645a2f83d lib9p: handle erealloc9p(..., 0) 2015-04-23 18:25:19 +02:00
cinap_lenrek 3bb7ad61aa lib9p: prevent files from being created in deleted directories (thanks BurnZeZ) 2014-10-23 00:43:27 +02:00
cinap_lenrek 89e6315699 lib9p: fix .. walk crash in deleted directory (thanks BurnZeZ)
to reproduce:

 % ramfs; cd /tmp
 % mkdir foo; cd foo
 % pwd
 /tmp/foo
 % rm /tmp/foo
 % pwd
 /tmp/foo
 % ls
 % ls /tmp
 % ls ..
 ramfs 202751: suicide: sys: trap: fault read addr=0x0 pc=0x0000e46d
 ls: ..: '..' mount rpc error
2014-10-23 23:59:16 +02:00
cinap_lenrek a1b2b9b126 lib9p: fix nil dereference crash in remove for directory permission check
file->parent can be nil when the file has been previously removed.
removefile() deals with this, so skip the permission check in
that case and let removefile() error out.
2014-09-19 05:22:26 +02:00
cinap_lenrek 51cb8f50d8 remove executable bit from /sys/src/lib9p/ramfs.c 2014-07-03 00:17:28 +02:00
cinap_lenrek 3a5b2189ed revert ramfs example
the code was correct. erealloc9p() terminates the process
on error, but the code was handling realloc() error explicitely
and responded the request with Enomem error.
2014-06-11 18:01:20 +02:00
ftrvxmtrx 6dd3cf4c40 lib9p: ramfs example: s/realloc/erealloc9p/ 2014-06-11 17:22:32 +02:00
cinap_lenrek 505bc9b491 lib9p/hjfs: use x != ~0 instead (type)~x conditionals to work arround arm compiler issue 2013-10-02 01:36:05 +02:00
cinap_lenrek e36d9f5c4e make filesystem handling of read9pmsg() consistent 2013-06-16 06:26:31 +02:00
cinap_lenrek 6b4c5380d8 lib9p: defer freeing srv for listensrv()
use the Srv.end callback for freeing the srv and closing the
file descriptor of a connection. this makes sure we wont free
the srv while there are still outstanding requests that would
access the srv when doing the respond() call.
2013-01-30 10:34:57 +01:00
cinap_lenrek dbbbff8915 lib9p: defer closing down srv until the last request has been responded, Tversion message size
in multithreaded programs, we have to wait until all outstanding
requests have been responded before closing down the srv.

dont make write errors sysfatal(), only print them. in case if
listensrv() is used we dont want to exit the process in respond()
called by some worker thread.

make sure Tversion is only handled when there are no outstanding
requests and make sure message size is sane.
2013-01-30 06:26:03 +01:00
cinap_lenrek 9c844d90e1 lib9p: add Srv.start 2012-03-30 20:06:33 +02:00
aiju 8434f98cdd added interrupt proc ctl message 2011-08-20 12:30:06 +02:00
aiju 0a0435dbc1 lib9p reqqueue: more cleaning 2011-08-19 19:33:36 +02:00
aiju 9574793fc7 lib9p reqqueue: remove setjmp shit 2011-08-19 16:24:44 +02:00
cinap_lenrek 0c1284f602 lib9p: add srvacquire/srvrelease 2011-08-19 05:18:19 +02:00
cinap_lenrek b0f1c5ed6c usb ptp camera driver 2011-08-16 01:47:59 +02:00
aiju c65100ffa0 lib9p: added toilet queues 2011-08-16 22:00:34 +02:00
aiju 6aed9711b4 devshr: changed #σc to contain directories
nusb: detaching
2011-07-30 14:30:27 +02:00
aiju 5181f2e576 lib9p: fix 2011-07-27 16:38:32 +02:00
aiju 7d0ce95567 lib9p: added threadpostsharesrv 2011-07-27 16:36:32 +02:00
aiju abe6ead0ff lib9p: added functions for devshr 2011-07-27 10:46:34 +02:00
cinap_lenrek d1dcdf2df3 lib9p: respond with error instead of aborting for unknown 9p messages 2011-07-09 13:11:59 +02:00
Taru Karttunen a9060cc06b Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
Taru Karttunen e5888a1ffd Import sources from 2011-03-30 iso image 2011-03-30 15:46:40 +03:00