Skip to contentSkip to conversation

scm: provide full privilege set via SCM_PRIVILEGE

PATCH New Casey Schaufler 1 participant 1 message Jan 18, 2011

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

PATCH 1/1 scm: provide full privilege set via SCM_PRIVILEGE

Subject: [PATCH] scm: provide full privilege set via SCM_PRIVILEGE

The SCM mechanism currently provides interfaces for delivering the uid/gid and the "security context" (LSM information) of the peer on a UDS socket. All of the security credential information is available, but there is no interface available to obtain it. Further, the existing interfaces require that the user chose between the uid/gid and the context as the existing interfaces are exclusive.

This patch introduces an additional interface that provides a complete set of security information from the peer credential. No additional work is required to provide the information internally, it is all being passed, just not exposed.

Also sent to LKML and LSM lists.

---

 include/asm-generic/socket.h |    1 +
 include/linux/net.h          |    1 +
 include/linux/socket.h       |    1 +
 include/net/scm.h            |   80 +++++++++++++++++++++++++++++++++++++++++-
 net/core/sock.c              |   11 ++++++
 5 files changed, 93 insertions(+), 1 deletions(-)
include/asm-generic/socket.h +1 -0
index 9a6115e..7aa8e84 100644
@@ -64,4 +64,5 @@
 #define SO_DOMAIN		39
 
 #define SO_RXQ_OVFL             40
+#define SO_PASSPRIV		41
 #endif /* __ASM_GENERIC_SOCKET_H */
include/linux/net.h +1 -0
index 16faa13..159a929 100644
@@ -71,6 +71,7 @@ struct net;
 #define SOCK_NOSPACE		2
 #define SOCK_PASSCRED		3
 #define SOCK_PASSSEC		4
+#define SOCK_PASSPRIV		5
 
 #ifndef ARCH_HAS_SOCKET_TYPES
 /**
include/linux/socket.h +1 -0
index 86b652f..e9cfd68 100644
@@ -147,6 +147,7 @@ static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr
 #define	SCM_RIGHTS	0x01		/* rw: access rights (array of int) */
 #define SCM_CREDENTIALS 0x02		/* rw: struct ucred		*/
 #define SCM_SECURITY	0x03		/* rw: security label		*/
+#define SCM_PRIVILEGES  0x04		/* rw: privilege set		*/
 
 struct ucred {
 	__u32	pid;
include/net/scm.h +79 -1

97 lines not on this page · raw message

net/core/sock.c +11 -0
index fb60801..f134126 100644
@@ -725,6 +725,13 @@ set_rcvbuf:
 		else
 			clear_bit(SOCK_PASSSEC, &sock->flags);
 		break;
+
+	case SO_PASSPRIV:
+		if (valbool)
+			set_bit(SOCK_PASSPRIV, &sock->flags);
+		else
+			clear_bit(SOCK_PASSPRIV, &sock->flags);
+		break;
 	case SO_MARK:
 		if (!capable(CAP_NET_ADMIN))
 			ret = -EPERM;
@@ -950,6 +957,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 		v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0;
 		break;
 
+	case SO_PASSPRIV:
+		v.val = test_bit(SOCK_PASSPRIV, &sock->flags) ? 1 : 0;
+		break;
+
 	case SO_PEERSEC:
 		return security_socket_getpeersec_stream(sock, optval, optlen, len);