diff options
author | Reilly Grant <grantr@vmware.com> | 2013-03-14 07:55:41 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-03-15 08:26:26 -0400 |
commit | 2a89f9247ae43a2cf36fbc07b21b5792fc7b9efe (patch) | |
tree | 869acbbc9e9cf4ae92e7153b387dfccd0a76659e /net | |
parent | 8a7fbfab4be39b8690543f3d29b26860d2f6c576 (diff) |
VSOCK: Support VM sockets connected to the hypervisor.
The resource ID used for VM socket control packets (0) is already
used for the VMCI_GET_CONTEXT_ID hypercall so a new ID (15) must be
used when the guest sends these datagrams to the hypervisor.
The hypervisor context ID must also be removed from the internal
blacklist.
Signed-off-by: Reilly Grant <grantr@vmware.com>
Acked-by: Andy King <acking@vmware.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/vmw_vsock/vmci_transport.c | 16 | ||||
-rw-r--r-- | net/vmw_vsock/vmci_transport.h | 3 |
2 files changed, 16 insertions, 3 deletions
diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c index a70ace83a153..faf81b8c1a3a 100644 --- a/net/vmw_vsock/vmci_transport.c +++ b/net/vmw_vsock/vmci_transport.c | |||
@@ -123,6 +123,14 @@ static s32 vmci_transport_error_to_vsock_error(s32 vmci_error) | |||
123 | return err > 0 ? -err : err; | 123 | return err > 0 ? -err : err; |
124 | } | 124 | } |
125 | 125 | ||
126 | static u32 vmci_transport_peer_rid(u32 peer_cid) | ||
127 | { | ||
128 | if (VMADDR_CID_HYPERVISOR == peer_cid) | ||
129 | return VMCI_TRANSPORT_HYPERVISOR_PACKET_RID; | ||
130 | |||
131 | return VMCI_TRANSPORT_PACKET_RID; | ||
132 | } | ||
133 | |||
126 | static inline void | 134 | static inline void |
127 | vmci_transport_packet_init(struct vmci_transport_packet *pkt, | 135 | vmci_transport_packet_init(struct vmci_transport_packet *pkt, |
128 | struct sockaddr_vm *src, | 136 | struct sockaddr_vm *src, |
@@ -140,7 +148,7 @@ vmci_transport_packet_init(struct vmci_transport_packet *pkt, | |||
140 | pkt->dg.src = vmci_make_handle(VMADDR_CID_ANY, | 148 | pkt->dg.src = vmci_make_handle(VMADDR_CID_ANY, |
141 | VMCI_TRANSPORT_PACKET_RID); | 149 | VMCI_TRANSPORT_PACKET_RID); |
142 | pkt->dg.dst = vmci_make_handle(dst->svm_cid, | 150 | pkt->dg.dst = vmci_make_handle(dst->svm_cid, |
143 | VMCI_TRANSPORT_PACKET_RID); | 151 | vmci_transport_peer_rid(dst->svm_cid)); |
144 | pkt->dg.payload_size = sizeof(*pkt) - sizeof(pkt->dg); | 152 | pkt->dg.payload_size = sizeof(*pkt) - sizeof(pkt->dg); |
145 | pkt->version = VMCI_TRANSPORT_PACKET_VERSION; | 153 | pkt->version = VMCI_TRANSPORT_PACKET_VERSION; |
146 | pkt->type = type; | 154 | pkt->type = type; |
@@ -511,6 +519,9 @@ static bool vmci_transport_is_trusted(struct vsock_sock *vsock, u32 peer_cid) | |||
511 | 519 | ||
512 | static bool vmci_transport_allow_dgram(struct vsock_sock *vsock, u32 peer_cid) | 520 | static bool vmci_transport_allow_dgram(struct vsock_sock *vsock, u32 peer_cid) |
513 | { | 521 | { |
522 | if (VMADDR_CID_HYPERVISOR == peer_cid) | ||
523 | return true; | ||
524 | |||
514 | if (vsock->cached_peer != peer_cid) { | 525 | if (vsock->cached_peer != peer_cid) { |
515 | vsock->cached_peer = peer_cid; | 526 | vsock->cached_peer = peer_cid; |
516 | if (!vmci_transport_is_trusted(vsock, peer_cid) && | 527 | if (!vmci_transport_is_trusted(vsock, peer_cid) && |
@@ -631,7 +642,6 @@ static int vmci_transport_recv_dgram_cb(void *data, struct vmci_datagram *dg) | |||
631 | static bool vmci_transport_stream_allow(u32 cid, u32 port) | 642 | static bool vmci_transport_stream_allow(u32 cid, u32 port) |
632 | { | 643 | { |
633 | static const u32 non_socket_contexts[] = { | 644 | static const u32 non_socket_contexts[] = { |
634 | VMADDR_CID_HYPERVISOR, | ||
635 | VMADDR_CID_RESERVED, | 645 | VMADDR_CID_RESERVED, |
636 | }; | 646 | }; |
637 | int i; | 647 | int i; |
@@ -670,7 +680,7 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg) | |||
670 | */ | 680 | */ |
671 | 681 | ||
672 | if (!vmci_transport_stream_allow(dg->src.context, -1) | 682 | if (!vmci_transport_stream_allow(dg->src.context, -1) |
673 | || VMCI_TRANSPORT_PACKET_RID != dg->src.resource) | 683 | || vmci_transport_peer_rid(dg->src.context) != dg->src.resource) |
674 | return VMCI_ERROR_NO_ACCESS; | 684 | return VMCI_ERROR_NO_ACCESS; |
675 | 685 | ||
676 | if (VMCI_DG_SIZE(dg) < sizeof(*pkt)) | 686 | if (VMCI_DG_SIZE(dg) < sizeof(*pkt)) |
diff --git a/net/vmw_vsock/vmci_transport.h b/net/vmw_vsock/vmci_transport.h index 1bf991803ec0..fd88ea8924e4 100644 --- a/net/vmw_vsock/vmci_transport.h +++ b/net/vmw_vsock/vmci_transport.h | |||
@@ -28,6 +28,9 @@ | |||
28 | /* The resource ID on which control packets are sent. */ | 28 | /* The resource ID on which control packets are sent. */ |
29 | #define VMCI_TRANSPORT_PACKET_RID 1 | 29 | #define VMCI_TRANSPORT_PACKET_RID 1 |
30 | 30 | ||
31 | /* The resource ID on which control packets are sent to the hypervisor. */ | ||
32 | #define VMCI_TRANSPORT_HYPERVISOR_PACKET_RID 15 | ||
33 | |||
31 | #define VSOCK_PROTO_INVALID 0 | 34 | #define VSOCK_PROTO_INVALID 0 |
32 | #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0) | 35 | #define VSOCK_PROTO_PKT_ON_NOTIFY (1 << 0) |
33 | #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY) | 36 | #define VSOCK_PROTO_ALL_SUPPORTED (VSOCK_PROTO_PKT_ON_NOTIFY) |