lkml.org 
[lkml]   [1998]   [Oct]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: sockfs (was: setting access rights to priviledged ports)
Date
From
Alan Cox writes:
> > setuid port-allocator, but most such `solutions' require hacking the deamon's
> > code.
>
> Or learning about LD_PRELOAD
>
> > So I re-ask the question: what was the incentive for not putting sockfs in the
> > standard kernel ? Bad code ? Bloat ? Lack of usefulness ?

For a start, I never really made any effort nor actually asked for it
to be added. It was basically an afternoon hack that turned out rather
nicely.

> Because it can be done just fine in user space. 2.1.x cleans things up by
> having capabilities. So you need a capability to bind to low ports, you dont
> have to be root with all the root powers

With the capability approach, you lose the ability to separate out
different port numbers easily. I prefer
chown named /sockfs/53; chown smtpd /sockfs/25; chown slapd /sockfs/389

An extension of the "can put permissions checking in user-mode"
argument is that you don't need unprivileged programs to be able to
open ordinary files: you can have a daemon running as root which does
the permission checking itself and hands out file descriptors. It does
make things easier to administer when the kernel does it though. For
example, the equivalent of something like "find /sockfs ! -user root"
would require additional code in a privileged-port-handout daemon.

The kernel support for sockfs is basically a two line patch which
adds a function pointer callout which modules can intercept:

if (prot_sock_ok)
return prot_sock_ok(AF_INET, snum);

sockfs itself, even though it's only 465 lines of code, wouldn't have
to go in the kernel, nor be distributed with it. It just builds as a
file system module and sets prot_sock_ok to point to its own port
permission checker. It holds the permissions in a 6KB array and
presents them to the user in a familiar way: as the permissions on a
fake /sockfs/1234 file. The kernel patch is the following. Consider
this the first and last (mild) suggestion that it go in. I won't
bother sending it to Linus but if you (Alan) change your mind, feel
free to do so.

------------------------------ cut here ------------------------------
--- linux-2.0.29/include/net/sock.h.ORI Tue Sep 16 16:18:22 1997
+++ linux-2.0.29/include/net/sock.h Tue Sep 16 16:40:24 1997
@@ -393,10 +393,17 @@
#define SOCK_DESTROY_TIME (10*HZ)

/*
- * Sockets 0-1023 can't be bound to unless you are superuser
+ * Sockets 0-1023 can't be bound to unless you are superuser...
*/

#define PROT_SOCK 1024
+
+/*
+ * ...except prot_sock_ok can be defined to override that test.
+ */
+#ifdef CONFIG_INET
+extern int (*prot_sock_ok)(unsigned int family, unsigned int port);
+#endif

#define SHUTDOWN_MASK 3
#define RCV_SHUTDOWN 1
--- linux-2.0.29/net/ipv4/af_inet.c.ORI Tue Sep 16 15:49:00 1997
+++ linux-2.0.29/net/ipv4/af_inet.c Tue Sep 16 15:59:56 1997
@@ -124,6 +124,8 @@

int (*rarp_ioctl_hook)(unsigned int,void*) = NULL;

+int (*prot_sock_ok)(unsigned int, unsigned int) = NULL;
+
/*
* See if a socket number is in use.
*/
@@ -836,6 +838,8 @@

if (snum == 0)
snum = get_new_socknum(sk->prot, 0);
+ if (prot_sock_ok)
+ return prot_sock_ok(AF_INET, snum);
if (snum < PROT_SOCK && !suser())
return(-EACCES);
}
--- linux-2.0.29/net/netsyms.c.ORI Tue Sep 16 16:21:36 1997
+++ linux-2.0.29/net/netsyms.c Tue Sep 16 16:22:22 1997
@@ -28,6 +28,7 @@
#include <net/tcp.h>
#include <net/icmp.h>
#include <net/route.h>
+#include <net/sock.h>
#include <linux/net_alias.h>
#endif

@@ -176,6 +177,7 @@
X(tty_register_ldisc),
X(kill_fasync),
X(arp_query),
+ X(prot_sock_ok),
#endif /* CONFIG_INET */

#ifdef CONFIG_NETLINK
------------------------------ cut here ------------------------------
--Malcolm

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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:45    [W:1.079 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site