Re: sockfs - a filesystem for reserved port permissions

Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Thu, 18 Sep 1997 16:02:27 +0100 (BST)


Dean Gaudet writes:
> Unfortunately I don't think this will work with 2.0.30 and later because
> the anonymous socket allocation code also needs to know these permissions.
> That's the code which calculates the "random" port for a socket that's
> bound to port 0.

Surely anonymous sockets shouldn't get bound to port numbers less
than 1024 (i.e. PROT_SOCK)? The kernel patch I made was a bit wrong
though. Instead of

if (prot_sock_ok)
return prot_sock_ok(AF_INET, snum);
if (snum < PROT_SOCK && !suser())
return(-EACCES);

it should be

if (snum < PROT_SOCK) {
if (prot_sock_ok) {
int err = prot_sock_ok(AF_INET, snum);
if (err)
return err;
} else if (!suser())
return(-EACCES);
}
}

I've checked 2.0.30 and it changed the lines preceding the
above from
if (snum == 0)
snum = get_new_socknum(sk->prot, 0);
to
if (snum == 0)
snum = sk->prot->good_socknum();

That will probably stop the patch from applying automatically but
appending the above "if (snum < PROT_SOCK) { ... }" block manually
should be fine.

Note that if anyone wants to try out the sockfs filesystem without
applying the kernel patch, you can build sockfs with -DSTANDALONE
and it'll provide a dummy prot_sock_ok pointer so that it links OK.
You can then mount and try out the filesystem: it's just the kernel
won't take any notice of its permission contents when doing a bind().

--Malcolm

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