lkml.org 
[lkml]   [1997]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subjectsockfs - a filesystem for reserved port permissions
Date
Here's sockfs, a little pseudo-filesystem that lets you set the
owner/group/permissions for reserved ports just by using
chown/chgrp/chmod and ls. I wrote it a few weeks ago as an
exercise to see how modular filesystems worked and because it
struck me as being the "right" way to do reserved port permission
checking. I see that there are some other suggested solutions now
so I thought I ought to polish this up and release it.

The only patch necessary to the kernel itself is a tiny one which
(1) creates an exported function pointer
int (*prot_sock_ok)(unsigned int family, unsigned int port)
(2) changes the test in af_inet.c to add:
+ if (prot_sock_ok)
+ return prot_sock_ok(AF_INET, snum);
if (snum < PROT_SOCK && !suser())
return(-EACCES);
The sockfs filesystem is modular, can be built away from the
kernel and lets you do
# mount -t sockfs sockfs /sockfs
after which /sockfs/1, /sockfs/2, ... show up as 700 root-owned
zero-length files just as pid files do under /proc. You can then
use standard tools chown/chgrp/chmod on them: when a process
attempts to bind a reserved port, the kernel (via the prot_sock_ok
function which the filesystem module sets) checks whether the
process has write permission to the relevant file in /sockfs.

Since the whole thing is only 8K when the .tar.gz is uuencoded,
I thought I might as well include it here. Full instructions are
in the included README. The patch and filesystem were written for
a 2.0.29 kernel but I'd be very surprised if it didn't work OK for
pretty much any 2.0.x. There's nothing fancy about it.
Please let me know what you think.

------------------------------ cut here ------------------------------
begin 644 sockfs-a1.tar.gz
M'XL(`(S$'C0``^P\:W?;QK'Y2OR*C9+:I,0W)<J6;->R1"NL)=)'C\9I;@X*
M@DL2)@B@>$AF$_WWSLPN@,6#DM/&]KV]QK%%8I^S\Y[=60:NN9P%K6\^Y<-V
MV_M[>^P;QO;V]_;QDW5V=^E3/FW&^MAHM]OI]:"VL]?N?L/V/BE4\HF"T/`9
M^V8UX4886GQS.^X'GP.@S_L$@OY!Y'&_:7Z:.3KM=E_0NXS^G>Y>=U_2O[?;
MZ7:AJ-?I[G_#VI\&G.SS_YS^K6V-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_IQV;3S''0_G_O7Z2_]_9Z^RC_.]V>E_E_W,\8O\O(;_<\/N8_3[P
M:QS,.-7/AJ/K=V1/]=>7^@])&%.H*/Q.SRSWZSUJWFWAYX'H+(-^TR=S/4"Y
M;`8>@#G9F^4:O!U?7.FOAE>7K-//UKP^.A^>_23J=A6GT<86&;\NN6U>N*U.
M/J"TYWCC&]RL:N>:/7N6F[P&'D^';@@],(V\KEX^$<Z`O]V2'?OP/@B413X(
M`\V5]77RUP@V_8*0!`"OPY<L_C<19-QE\1_?Y&.=9$-#_8$F=*[Q`*\B;I'3
M85Y%W`$7QWD5<8$;0V=Y$>+W;S$>?E37#3^Q4/*#3A]Y(R-WG2#]32?QLT61
MS.?:BE,"M\3O]DPL2@"XX;XU6\M$P-Q&0HQA]5=[($C0A*`?4^*<3`3`;0]*
M*G0A)A!Y%F4Y"!"*(`C8G4YHC;6\T<`X'F@;,TQOE;D&<8YB(;^QB=TIK=1T
M5Q[>P,0$0D.:^GJ2XYN<!*;W8#`SDI(3MIF(R93LA$QN`NFN%`.%W^R",.S_
MW/V\3_U(^T]Y/9]JC@?L?Z?=0?^_U]_K[W7!\&/^?[_[U?Y_EF=NFJSQKW;N
M8`5!(`C`\-VGF!<8@X+HTJDZ=,E(JN,>2DLH%;/W;S;;(.K2*8C_`V41<5P1
M8=S9G;K'`@'.B<YCVU[S@3"G3W3K_TSIUA=Z[EKUW[?*EP)>1).^:.YK@31O
M+*77NKJ7G]O!LE([/RL/[5&;;'_=V77JHK;]>3`:6O3)<CWN6MT\XJZQF:W2
M>;)(14/TSS?5>Z[Y%ZHCXJ.H]:IZ)BEA-</HKWO[2,4DC-U&I[T%E>R4N\('
D%&WN#R64=;WE<+]^%P$``````````````/"]&QI_K$@`>```
`
end
------------------------------ cut here ------------------------------
--Malcolm

--
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services

\
 
 \ /
  Last update: 2005-03-22 13:40    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site