diff options
| author | Andrew Morton <akpm@osdl.org> | 2004-01-18 18:38:13 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.osdl.org> | 2004-01-18 18:38:13 -0800 |
| commit | da6e57a2e6bd7939f610d957afacaf6a131e75ed (patch) | |
| tree | f4ba93d7a37116b24d4e52dada4f65653e4a8581 /include | |
| parent | fa9b605f51e1cb530f197f6bb608e72d9d778512 (diff) | |
[PATCH] selinux: Add SO_PEERSEC socket option and getpeersec LSM hook.
From: James Morris <jmorris@redhat.com>
This patch adds a new option for Unix sockets, SO_PEERSEC, and an
associated LSM hook, getpeersec. The SELinux handler is also included.
The purpose of this is to allow applications to obtain each others security
credentials, analagously to the existing SO_PEERCRED option.
Examples of use are Security Enhanced D-BUS and Security Enhanced X.
This patch was previously approved in principle by David, and has been
updated with feedback from Chris Wright and extended to cover all
architectures.
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-alpha/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-arm/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-arm26/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-cris/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-h8300/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-i386/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-ia64/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-m68k/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-mips/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-parisc/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-ppc/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-ppc64/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-s390/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-sh/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-sparc/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-sparc64/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-v850/socket.h | 2 | ||||
| -rw-r--r-- | include/asm-x86_64/socket.h | 2 | ||||
| -rw-r--r-- | include/linux/security.h | 50 | ||||
| -rw-r--r-- | include/net/sock.h | 1 |
20 files changed, 87 insertions, 0 deletions
diff --git a/include/asm-alpha/socket.h b/include/asm-alpha/socket.h index e821ac372464..88912c4c8931 100644 --- a/include/asm-alpha/socket.h +++ b/include/asm-alpha/socket.h @@ -48,6 +48,8 @@ #define SO_TIMESTAMP 29 #define SCM_TIMESTAMP SO_TIMESTAMP +#define SO_PEERSEC 30 + /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 19 #define SO_SECURITY_ENCRYPTION_TRANSPORT 20 diff --git a/include/asm-arm/socket.h b/include/asm-arm/socket.h index 5c1428e41b06..b05e717397a1 100644 --- a/include/asm-arm/socket.h +++ b/include/asm-arm/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-arm26/socket.h b/include/asm-arm26/socket.h index 5c1428e41b06..b05e717397a1 100644 --- a/include/asm-arm26/socket.h +++ b/include/asm-arm26/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-cris/socket.h b/include/asm-cris/socket.h index 89edfb11650f..b4421808b676 100644 --- a/include/asm-cris/socket.h +++ b/include/asm-cris/socket.h @@ -47,6 +47,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + #if defined(__KERNEL__) /* Socket types. */ #define SOCK_STREAM 1 /* stream (connection) socket */ diff --git a/include/asm-h8300/socket.h b/include/asm-h8300/socket.h index a328c84b9f23..070d46d2344e 100644 --- a/include/asm-h8300/socket.h +++ b/include/asm-h8300/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-i386/socket.h b/include/asm-i386/socket.h index 525f83218cd8..711f906193fd 100644 --- a/include/asm-i386/socket.h +++ b/include/asm-i386/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nasty libc5 fixup - bletch */ #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) /* Socket types. */ diff --git a/include/asm-ia64/socket.h b/include/asm-ia64/socket.h index 01e3b50760d3..5935d3e7d5aa 100644 --- a/include/asm-ia64/socket.h +++ b/include/asm-ia64/socket.h @@ -52,6 +52,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-m68k/socket.h b/include/asm-m68k/socket.h index 1959b608d477..68a33bfbae03 100644 --- a/include/asm-m68k/socket.h +++ b/include/asm-m68k/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-mips/socket.h b/include/asm-mips/socket.h index df9fcb53d71e..871344330047 100644 --- a/include/asm-mips/socket.h +++ b/include/asm-mips/socket.h @@ -66,6 +66,8 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */ #define SO_TIMESTAMP 29 #define SCM_TIMESTAMP SO_TIMESTAMP +#define SO_PEERSEC 30 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-parisc/socket.h b/include/asm-parisc/socket.h index 7833ff68f2e4..fd3f0f29eb3c 100644 --- a/include/asm-parisc/socket.h +++ b/include/asm-parisc/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 0x401c +#define SO_PEERSEC 0x401d + #if defined(__KERNEL__) #define SOCK_STREAM 1 /* stream (connection) socket */ #define SOCK_DGRAM 2 /* datagram (conn.less) socket */ diff --git a/include/asm-ppc/socket.h b/include/asm-ppc/socket.h index d513b3238efd..bad94c36f1b8 100644 --- a/include/asm-ppc/socket.h +++ b/include/asm-ppc/socket.h @@ -51,6 +51,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-ppc64/socket.h b/include/asm-ppc64/socket.h index 9f23b2f3b59b..1021a5268346 100644 --- a/include/asm-ppc64/socket.h +++ b/include/asm-ppc64/socket.h @@ -52,6 +52,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-s390/socket.h b/include/asm-s390/socket.h index d7b7f5bb6a39..1855ec7a112b 100644 --- a/include/asm-s390/socket.h +++ b/include/asm-s390/socket.h @@ -53,6 +53,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-sh/socket.h b/include/asm-sh/socket.h index 918e2f225959..2b9469472f76 100644 --- a/include/asm-sh/socket.h +++ b/include/asm-sh/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-sparc/socket.h b/include/asm-sparc/socket.h index 254d446bdcf9..cfa529d9bb96 100644 --- a/include/asm-sparc/socket.h +++ b/include/asm-sparc/socket.h @@ -45,6 +45,8 @@ #define SO_TIMESTAMP 0x001d #define SCM_TIMESTAMP SO_TIMESTAMP +#define SO_PEERSEC 0x100e + /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x5001 #define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002 diff --git a/include/asm-sparc64/socket.h b/include/asm-sparc64/socket.h index d041e3352970..ba2230ba1d7d 100644 --- a/include/asm-sparc64/socket.h +++ b/include/asm-sparc64/socket.h @@ -45,6 +45,8 @@ #define SO_TIMESTAMP 0x001d #define SCM_TIMESTAMP SO_TIMESTAMP +#define SO_PEERSEC 0x001e + /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x5001 #define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002 diff --git a/include/asm-v850/socket.h b/include/asm-v850/socket.h index d1dddefa9eaa..7d7f80efa8b3 100644 --- a/include/asm-v850/socket.h +++ b/include/asm-v850/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nast libc5 fixup - bletch */ #if defined(__KERNEL__) /* Socket types. */ diff --git a/include/asm-x86_64/socket.h b/include/asm-x86_64/socket.h index 525f83218cd8..373e7abadfb5 100644 --- a/include/asm-x86_64/socket.h +++ b/include/asm-x86_64/socket.h @@ -45,6 +45,8 @@ #define SO_ACCEPTCONN 30 +#define SO_PEERSEC 31 + /* Nasty libc5 fixup - bletch */ #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) /* Socket types. */ diff --git a/include/linux/security.h b/include/linux/security.h index 9794223e8e17..06b2c60a48f8 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -757,6 +757,22 @@ struct swap_info_struct; * incoming sk_buff @skb has been associated with a particular socket, @sk. * @sk contains the sock (not socket) associated with the incoming sk_buff. * @skb contains the incoming network data. + * @socket_getpeersec: + * This hook allows the security module to provide peer socket security + * state to userspace via getsockopt SO_GETPEERSEC. + * @sock is the local socket. + * @optval userspace memory where the security state is to be copied. + * @optlen userspace int where the module should copy the actual length + * of the security state. + * @len as input is the maximum length to copy to userspace provided + * by the caller. + * Return 0 if all is well, otherwise, typical getsockopt return + * values. + * @sk_alloc_security: + * Allocate and attach a security structure to the sk->sk_security field, + * which is used to copy security attributes between local stream sockets. + * @sk_free_security: + * Deallocate security structure. * * Security hooks affecting all System V IPC operations. * @@ -1183,6 +1199,9 @@ struct security_operations { int (*socket_setsockopt) (struct socket * sock, int level, int optname); int (*socket_shutdown) (struct socket * sock, int how); int (*socket_sock_rcv_skb) (struct sock * sk, struct sk_buff * skb); + int (*socket_getpeersec) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len); + int (*sk_alloc_security) (struct sock *sk, int family, int priority); + void (*sk_free_security) (struct sock *sk); #endif /* CONFIG_SECURITY_NETWORK */ }; @@ -2564,6 +2583,22 @@ static inline int security_sock_rcv_skb (struct sock * sk, { return security_ops->socket_sock_rcv_skb (sk, skb); } + +static inline int security_socket_getpeersec(struct socket *sock, char __user *optval, + int __user *optlen, unsigned len) +{ + return security_ops->socket_getpeersec(sock, optval, optlen, len); +} + +static inline int security_sk_alloc(struct sock *sk, int family, int priority) +{ + return security_ops->sk_alloc_security(sk, family, priority); +} + +static inline void security_sk_free(struct sock *sk) +{ + return security_ops->sk_free_security(sk); +} #else /* CONFIG_SECURITY_NETWORK */ static inline int security_unix_stream_connect(struct socket * sock, struct socket * other, @@ -2664,6 +2699,21 @@ static inline int security_sock_rcv_skb (struct sock * sk, { return 0; } + +static inline int security_socket_getpeersec(struct socket *sock, char __user *optval, + int __user *optlen, unsigned len) +{ + return -ENOPROTOOPT; +} + +static inline int security_sk_alloc(struct sock *sk, int family, int priority) +{ + return 0; +} + +static inline void security_sk_free(struct sock *sk) +{ +} #endif /* CONFIG_SECURITY_NETWORK */ #endif /* ! __LINUX_SECURITY_H */ diff --git a/include/net/sock.h b/include/net/sock.h index 7b38c08f0f64..16e129f90426 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -246,6 +246,7 @@ struct sock { struct socket *sk_socket; void *sk_user_data; struct module *sk_owner; + void *sk_security; void (*sk_state_change)(struct sock *sk); void (*sk_data_ready)(struct sock *sk, int bytes); void (*sk_write_space)(struct sock *sk); |
