Re: [PATCH] VSOCK: Send reset control packet when socket is partially bound

2018-12-19 Thread David Miller
From: Jorgen Hansen 
Date: Wed, 12 Dec 2018 01:38:59 -0800

>  static int vmci_transport_send_reset_bh(struct sockaddr_vm *dst,
> @@ -312,12 +328,29 @@ static int vmci_transport_send_reset_bh(struct 
> sockaddr_vm *dst,
>  static int vmci_transport_send_reset(struct sock *sk,
>struct vmci_transport_packet *pkt)
>  {
> + struct sockaddr_vm dst;
> + struct sockaddr_vm *dst_ptr;
> + struct vsock_sock *vsk;
> +

Please order local variables from longest to shortest line.

Thank you.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH] VSOCK: Send reset control packet when socket is partially bound

2018-12-13 Thread Jorgen Hansen
If a server side socket is bound to an address, but not in the listening
state yet, incoming connection requests should receive a reset control
packet in response. However, the function used to send the reset
silently drops the reset packet if the sending socket isn't bound
to a remote address (as is the case for a bound socket not yet in
the listening state). This change fixes this by using the src
of the incoming packet as destination for the reset packet in
this case.

Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Reviewed-by: Adit Ranadive 
Reviewed-by: Vishnu Dasa 
Signed-off-by: Jorgen Hansen 
---
 net/vmw_vsock/vmci_transport.c | 67 +++---
 1 file changed, 50 insertions(+), 17 deletions(-)

diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index 0ae3614..402d84e 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -264,6 +264,31 @@ vmci_transport_send_control_pkt_bh(struct sockaddr_vm *src,
 }
 
 static int
+vmci_transport_alloc_send_control_pkt(struct sockaddr_vm *src,
+ struct sockaddr_vm *dst,
+ enum vmci_transport_packet_type type,
+ u64 size,
+ u64 mode,
+ struct vmci_transport_waiting_info *wait,
+ u16 proto,
+ struct vmci_handle handle)
+{
+   struct vmci_transport_packet *pkt;
+   int err;
+
+   pkt = kmalloc(sizeof(*pkt), GFP_KERNEL);
+   if (!pkt)
+   return -ENOMEM;
+
+   err = __vmci_transport_send_control_pkt(pkt, src, dst, type, size,
+   mode, wait, proto, handle,
+   true);
+   kfree(pkt);
+
+   return err;
+}
+
+static int
 vmci_transport_send_control_pkt(struct sock *sk,
enum vmci_transport_packet_type type,
u64 size,
@@ -272,9 +297,7 @@ vmci_transport_send_control_pkt(struct sock *sk,
u16 proto,
struct vmci_handle handle)
 {
-   struct vmci_transport_packet *pkt;
struct vsock_sock *vsk;
-   int err;
 
vsk = vsock_sk(sk);
 
@@ -284,17 +307,10 @@ vmci_transport_send_control_pkt(struct sock *sk,
if (!vsock_addr_bound(>remote_addr))
return -EINVAL;
 
-   pkt = kmalloc(sizeof(*pkt), GFP_KERNEL);
-   if (!pkt)
-   return -ENOMEM;
-
-   err = __vmci_transport_send_control_pkt(pkt, >local_addr,
-   >remote_addr, type, size,
-   mode, wait, proto, handle,
-   true);
-   kfree(pkt);
-
-   return err;
+   return vmci_transport_alloc_send_control_pkt(>local_addr,
+>remote_addr,
+type, size, mode,
+wait, proto, handle);
 }
 
 static int vmci_transport_send_reset_bh(struct sockaddr_vm *dst,
@@ -312,12 +328,29 @@ static int vmci_transport_send_reset_bh(struct 
sockaddr_vm *dst,
 static int vmci_transport_send_reset(struct sock *sk,
 struct vmci_transport_packet *pkt)
 {
+   struct sockaddr_vm dst;
+   struct sockaddr_vm *dst_ptr;
+   struct vsock_sock *vsk;
+
if (pkt->type == VMCI_TRANSPORT_PACKET_TYPE_RST)
return 0;
-   return vmci_transport_send_control_pkt(sk,
-   VMCI_TRANSPORT_PACKET_TYPE_RST,
-   0, 0, NULL, VSOCK_PROTO_INVALID,
-   VMCI_INVALID_HANDLE);
+
+   vsk = vsock_sk(sk);
+
+   if (!vsock_addr_bound(>local_addr))
+   return -EINVAL;
+
+   if (vsock_addr_bound(>remote_addr)) {
+   dst_ptr = >remote_addr;
+   } else {
+   vsock_addr_init(, pkt->dg.src.context,
+   pkt->src_port);
+   dst_ptr = 
+   }
+   return vmci_transport_alloc_send_control_pkt(>local_addr, dst_ptr,
+VMCI_TRANSPORT_PACKET_TYPE_RST,
+0, 0, NULL, VSOCK_PROTO_INVALID,
+VMCI_INVALID_HANDLE);
 }
 
 static int vmci_transport_send_negotiate(struct sock *sk, size_t size)
-- 
2.6.2

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization