Skip to contentSkip to conversation

3.2: access permission filesystem 0.26

PATCH New Olaf Dietsche 1 participant 1 message Feb 3, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 3.2: access permission filesystem 0.26

This *untested* patch adds a new permission managing file system. Furthermore, it adds two modules, which make use of this file system.

One module allows granting capabilities based on user-/groupid. The second module allows to grant access to lower numbered ports based on user-/groupid, too.

Changes:
- Update to 3.x
- Fixed help text, suggestion from Randy Dunlap <[email protected]>
- Added build fix from Remy Bohmer <[email protected]>
- Added fix for 3.0 from Harro Haan <[email protected]>
- Fixed help text and config of usercaps

This patch is available at:
<http://www.olafdietsche.de/linux/accessfs/>

and attached inline below.

Regards, Olaf

Documentation/filesystems/accessfs.txt new file +41 -0
new file mode 100644
index 0000000..bf135b5
@@ -0,0 +1,41 @@
+Accessfs is a permission managing filesystem. It allows to control access to
+system resources, based on file permissions. The recommended mount point for
+this file-system is /proc/access, which will appear automatically in the
+/proc filesystem.
+
+Currently there are two modules using accessfs, userports and usercaps.
+
+With userports, you will be able to control access to IP ports based
+on user-/groupid.
+
+There's no need anymore to run internet daemons as root. You can
+individually configure which user/program can bind to protected ports
+(by default, below 1024).
+
+For example, you can say, user www is allowed to bind to port 80 or
+user mail is allowed to bind to port 25. Then, you can run apache as
+user www and sendmail as user mail. Now, you don't have to rely on
+apache or sendmail giving up superuser rights to enhance security.
+
+To use this option, you need to mount the access file system
+and do a chown on the appropriate ports:
+
+# mount -t accessfs none /proc/access
+# chown www /proc/access/net/ip/bind/80
+# chown mail /proc/access/net/ip/bind/25
+
+You can grant access to a group for individual ports as well. Just say:
+
+# chgrp lp /proc/access/net/ip/bind/515
+# chown g+x /proc/access/net/ip/bind/515
+
+With usercaps, you will be able to grant capabilities based on
+user-/groupid (root by default).
+
+For example you can create a group raw and change the capability
+net_raw to this group:
+
+# chgrp raw /proc/access/capabilities/net_raw
+# chmod ug+x /proc/access/capabilities/net_raw
+# chgrp raw /sbin/ping
+# chmod u-s /sbin/ping; chmod g+s /sbin/ping
fs/Kconfig +1 -0
index 5f4c45d..24f7348 100644
@@ -215,6 +215,7 @@ source "fs/pstore/Kconfig"
 source "fs/sysv/Kconfig"
 source "fs/ufs/Kconfig"
 source "fs/exofs/Kconfig"
+source "fs/accessfs/Kconfig"
 
 endif # MISC_FILESYSTEMS
 
fs/Makefile +1 -0
index d2c3353..fea1cfc 100644
@@ -121,5 +121,6 @@ obj-$(CONFIG_OCFS2_FS)		+= ocfs2/
 obj-$(CONFIG_BTRFS_FS)		+= btrfs/
 obj-$(CONFIG_GFS2_FS)           += gfs2/
 obj-y				+= exofs/ # Multiple modules
+obj-$(CONFIG_ACCESS_FS)		+= accessfs/
 obj-$(CONFIG_CEPH_FS)		+= ceph/
 obj-$(CONFIG_PSTORE)		+= pstore/
fs/accessfs/Kconfig new file +61 -0

61 lines not on this page · raw message

fs/accessfs/Makefile new file +11 -0
new file mode 100644
index 0000000..63a5647
@@ -0,0 +1,11 @@
+#
+# Makefile for the linux accessfs routines.
+#
+
+obj-$(CONFIG_ACCESS_FS) += accessfs.o
+obj-$(CONFIG_ACCESSFS_USER_CAPABILITIES) += usercaps.o
+obj-$(CONFIG_ACCESSFS_USER_PORTS) += userports.o
+
+accessfs-objs := inode.o
+usercaps-objs := capabilities.o
+userports-objs := ip.o
fs/accessfs/capabilities.c new file +109 -0

109 lines not on this page · raw message

fs/accessfs/inode.c new file +431 -0

431 lines not on this page · raw message

fs/accessfs/ip.c new file +101 -0

101 lines not on this page · raw message

include/linux/accessfs_fs.h new file +42 -0

42 lines not on this page · raw message

include/net/sock.h +43 -0

47 lines not on this page · raw message

net/Kconfig +12 -0
index a073148..bb5fb42 100644
@@ -75,6 +75,18 @@ config INET
 if INET
 source "net/ipv4/Kconfig"
 source "net/ipv6/Kconfig"
+
+config NET_HOOKS
+	bool "IP: Networking hooks (Experimental)"
+	depends on INET && EXPERIMENTAL
+	default n
+	help
+	  This option enables other kernel parts or modules to hook into the
+	  networking area and provide fine grained control over the access to
+	  IP ports.
+
+	  If you're unsure, say N.
+
 source "net/netlabel/Kconfig"
 
 endif # if INET
net/Makefile +1 -0
index acdde49..4e5dc79 100644
@@ -60,6 +60,7 @@ ifneq ($(CONFIG_DCB),)
 obj-y				+= dcb/
 endif
 obj-$(CONFIG_IEEE802154)	+= ieee802154/
+obj-$(CONFIG_NET)		+= hooks.o
 
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o
net/hooks.c new file +55 -0

55 lines not on this page · raw message

net/ipv4/af_inet.c +1 -1
index 1b5096a..9460a3c 100644
@@ -495,7 +495,7 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 
 	snum = ntohs(addr->sin_port);
 	err = -EACCES;
-	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
+	if (ip_prot_sock(sock, uaddr, addr_len))
 		goto out;
 
 	/*      We keep a pair of addresses. rcv_saddr is the one
net/ipv6/af_inet6.c +1 -1
index d27c797..154b1ec 100644
@@ -281,7 +281,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 		return -EINVAL;
 
 	snum = ntohs(addr->sin6_port);
-	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
+	if (ip6_prot_sock(sock, uaddr, addr_len))
 		return -EACCES;
 
 	lock_sock(sk);