aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2018-05-04 10:28:19 -0400
committerJames Morris <james.morris@microsoft.com>2018-05-04 15:48:54 -0400
commitaae7cfcbb733cf16f3bc9cbb650673b94d5df75f (patch)
tree5e90734622f6f65d6eb7ed83099c05ad8cc2c80c
parentb3859ee18ed287170b66b19a78191f7312ec3470 (diff)
security: add hook for socketpair()
Right now the LSM labels for socketpairs are always uninitialized, since there is no security hook for the socketpair() syscall. This patch adds the required hooks so LSMs can properly label socketpairs. This allows SO_PEERSEC to return useful information on those sockets. Note that the behavior of socketpair() can be emulated by creating a listener socket, connecting to it, and then discarding the initial listener socket. With this workaround, SO_PEERSEC would return the caller's security context. However, with socketpair(), the uninitialized context is returned unconditionally. This is unexpected and makes socketpair() less useful in situations where the security context is crucial to the application. With the new socketpair-hook this disparity can be solved by making socketpair() return the expected security context. Acked-by: Serge Hallyn <serge@hallyn.com> Signed-off-by: Tom Gundersen <teg@jklm.no> Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: James Morris <james.morris@microsoft.com>
-rw-r--r--include/linux/lsm_hooks.h7
-rw-r--r--include/linux/security.h7
-rw-r--r--security/security.c6
3 files changed, 20 insertions, 0 deletions
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 9d0b286f3dba..8f1131c8dd54 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -757,6 +757,11 @@
757 * @type contains the requested communications type. 757 * @type contains the requested communications type.
758 * @protocol contains the requested protocol. 758 * @protocol contains the requested protocol.
759 * @kern set to 1 if a kernel socket. 759 * @kern set to 1 if a kernel socket.
760 * @socket_socketpair:
761 * Check permissions before creating a fresh pair of sockets.
762 * @socka contains the first socket structure.
763 * @sockb contains the second socket structure.
764 * Return 0 if permission is granted and the connection was established.
760 * @socket_bind: 765 * @socket_bind:
761 * Check permission before socket protocol layer bind operation is 766 * Check permission before socket protocol layer bind operation is
762 * performed and the socket @sock is bound to the address specified in the 767 * performed and the socket @sock is bound to the address specified in the
@@ -1656,6 +1661,7 @@ union security_list_options {
1656 int (*socket_create)(int family, int type, int protocol, int kern); 1661 int (*socket_create)(int family, int type, int protocol, int kern);
1657 int (*socket_post_create)(struct socket *sock, int family, int type, 1662 int (*socket_post_create)(struct socket *sock, int family, int type,
1658 int protocol, int kern); 1663 int protocol, int kern);
1664 int (*socket_socketpair)(struct socket *socka, struct socket *sockb);
1659 int (*socket_bind)(struct socket *sock, struct sockaddr *address, 1665 int (*socket_bind)(struct socket *sock, struct sockaddr *address,
1660 int addrlen); 1666 int addrlen);
1661 int (*socket_connect)(struct socket *sock, struct sockaddr *address, 1667 int (*socket_connect)(struct socket *sock, struct sockaddr *address,
@@ -1922,6 +1928,7 @@ struct security_hook_heads {
1922 struct hlist_head unix_may_send; 1928 struct hlist_head unix_may_send;
1923 struct hlist_head socket_create; 1929 struct hlist_head socket_create;
1924 struct hlist_head socket_post_create; 1930 struct hlist_head socket_post_create;
1931 struct hlist_head socket_socketpair;
1925 struct hlist_head socket_bind; 1932 struct hlist_head socket_bind;
1926 struct hlist_head socket_connect; 1933 struct hlist_head socket_connect;
1927 struct hlist_head socket_listen; 1934 struct hlist_head socket_listen;
diff --git a/include/linux/security.h b/include/linux/security.h
index ecb06e1357dd..63030c85ee19 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -1177,6 +1177,7 @@ int security_unix_may_send(struct socket *sock, struct socket *other);
1177int security_socket_create(int family, int type, int protocol, int kern); 1177int security_socket_create(int family, int type, int protocol, int kern);
1178int security_socket_post_create(struct socket *sock, int family, 1178int security_socket_post_create(struct socket *sock, int family,
1179 int type, int protocol, int kern); 1179 int type, int protocol, int kern);
1180int security_socket_socketpair(struct socket *socka, struct socket *sockb);
1180int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen); 1181int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen);
1181int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen); 1182int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen);
1182int security_socket_listen(struct socket *sock, int backlog); 1183int security_socket_listen(struct socket *sock, int backlog);
@@ -1248,6 +1249,12 @@ static inline int security_socket_post_create(struct socket *sock,
1248 return 0; 1249 return 0;
1249} 1250}
1250 1251
1252static inline int security_socket_socketpair(struct socket *socka,
1253 struct socket *sockb)
1254{
1255 return 0;
1256}
1257
1251static inline int security_socket_bind(struct socket *sock, 1258static inline int security_socket_bind(struct socket *sock,
1252 struct sockaddr *address, 1259 struct sockaddr *address,
1253 int addrlen) 1260 int addrlen)
diff --git a/security/security.c b/security/security.c
index 7bc2fde023a7..68f46d849abe 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1358,6 +1358,12 @@ int security_socket_post_create(struct socket *sock, int family,
1358 protocol, kern); 1358 protocol, kern);
1359} 1359}
1360 1360
1361int security_socket_socketpair(struct socket *socka, struct socket *sockb)
1362{
1363 return call_int_hook(socket_socketpair, 0, socka, sockb);
1364}
1365EXPORT_SYMBOL(security_socket_socketpair);
1366
1361int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) 1367int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
1362{ 1368{
1363 return call_int_hook(socket_bind, 0, sock, address, addrlen); 1369 return call_int_hook(socket_bind, 0, sock, address, addrlen);