* [PATCH] VSOCK: bind to random port for VMADDR_PORT_ANY
@ 2018-12-11 2:06 Lepton Wu
2018-12-11 6:38 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Lepton Wu @ 2018-12-11 2:06 UTC (permalink / raw)
To: stable; +Cc: stefanha, Lepton Wu
The old code always starts from fixed port for VMADDR_PORT_ANY. Sometimes
when VMM crashed, there is still orphaned vsock which is waiting for
close timer, then it could cause connection time out for new started VM
if they are trying to connect to same port with same guest cid since the
new packets could hit that orphaned vsock. We could also fix this by doing
more in vhost_vsock_reset_orphans, but any way, it should be better to start
from a random local port instead of a fixed one.
Signed-off-by: Lepton Wu <ytht.net@gmail.com>
---
net/vmw_vsock/af_vsock.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index ab27a2872935..73817e846a1f 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -107,6 +107,7 @@
#include <linux/mutex.h>
#include <linux/net.h>
#include <linux/poll.h>
+#include <linux/random.h>
#include <linux/skbuff.h>
#include <linux/smp.h>
#include <linux/socket.h>
@@ -504,9 +505,12 @@ static void vsock_pending_work(struct work_struct *work)
static int __vsock_bind_stream(struct vsock_sock *vsk,
struct sockaddr_vm *addr)
{
- static u32 port = LAST_RESERVED_PORT + 1;
+ static u32 port = 0;
struct sockaddr_vm new_addr;
+ if (!port)
+ port = prandom_u32();
+
vsock_addr_init(&new_addr, addr->svm_cid, addr->svm_port);
if (addr->svm_port == VMADDR_PORT_ANY) {
--
2.20.0.rc2.403.gdbc3b29805-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] VSOCK: bind to random port for VMADDR_PORT_ANY
2018-12-11 2:06 [PATCH] VSOCK: bind to random port for VMADDR_PORT_ANY Lepton Wu
@ 2018-12-11 6:38 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2018-12-11 6:38 UTC (permalink / raw)
To: Lepton Wu; +Cc: stable, stefanha
On Mon, Dec 10, 2018 at 06:06:31PM -0800, Lepton Wu wrote:
> The old code always starts from fixed port for VMADDR_PORT_ANY. Sometimes
> when VMM crashed, there is still orphaned vsock which is waiting for
> close timer, then it could cause connection time out for new started VM
> if they are trying to connect to same port with same guest cid since the
> new packets could hit that orphaned vsock. We could also fix this by doing
> more in vhost_vsock_reset_orphans, but any way, it should be better to start
> from a random local port instead of a fixed one.
>
> Signed-off-by: Lepton Wu <ytht.net@gmail.com>
> ---
> net/vmw_vsock/af_vsock.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-11 6:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-11 2:06 [PATCH] VSOCK: bind to random port for VMADDR_PORT_ANY Lepton Wu
2018-12-11 6:38 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).